#include<bits/stdc++.h>
using namespace std;
#define int long long
const int mod=1e9+7;
int n,ans;
int dp[10009][12][12];
bool isp[1009];
void init(){
for(int i=100;i<=999;i++){
bool flag=1;
for(int j=2;j<=sqrt(i);j++){
if(i%j==0){
flag=0;
}
}
isp[i]=flag;
}
for(int i=1;i<=9;i++){
for(int j=0;j<=9;j++) dp[2][i][j]=1;
}
}
signed main()
{
init();
cin>>n;
for(int i=3;i<=n;i++)
for(int now=0;now<=9;now++)
for(int pre=0;pre<=9;pre++)
for(int last=1;last<=9;last++)
if(isp[last*100+pre*10+now])
dp[i][now][pre]=(dp[i][now][pre]+dp[i-1][pre][last])%mod;
for(int i=0;i<=9;i++)
for(int j=0;j<=9;j++)
ans=(ans+dp[n][i][j])%mod;
printf("%d\n",ans);
return 0;
}