#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<stdio.h>
#include<vector>
using namespace std;
#define int long long
#define double long double
#define rep(s,i,n) for(int i=s;i<n;i++)
#define c(n) cout<<n<<endl;
#define ic(n) int n;cin>>n;
#define sc(s) string s;cin>>s;
#define mod 1000000007
#define inf 1000000000000000007
#define f first
#define s second
#define mini(c,a,b) *min_element(c+a,c+b)
#define maxi(c,a,b) *max_element(c+a,c+b)
#define P pair<int,int>
//printf("%.12Lf\n",);
int keta(int x){
	rep(0,i,30){
		if(x<10){
			return i+1;
		}
		x=x/10;
	}
}
int gcd(int x,int y){
	int aa=x,bb=y;
	rep(0,i,1000){
		aa=aa%bb;
		if(aa==0){
			return bb;
		}	
		bb=bb%aa;
		if(bb==0){
			return aa;
		}
	}
}	
int lcm(int x,int y){
	int aa=x,bb=y;
	rep(0,i,1000){
		aa=aa%bb;
		if(aa==0){
			return x/bb*y;
		}	
		bb=bb%aa;
		if(bb==0){
			return x/aa*y;
		}
	}
}
bool p(int x){
	if(x==1)return false;
	rep(2,i,sqrt(x)+1){
		if(x%i==0&&x!=i){
			return false;
		}
	}	
	return true;
}
int max(int a,int b){
	if(a>=b)return a;
	else return b;
}
int min(int a,int b){
	if(a>=b)return b;
	else return a;
}	
int n2[41];		
int nis[41]; 
int nia[41];
int mody[41];
int nn;
int com(int n,int y){
	int ni=1;
	for(int i=0;i<41;i++){
		n2[i]=ni;
		ni*=2;
	}
	int bunsi=1,bunbo=1;
	rep(0,i,y)bunsi=(bunsi*(n-i))%mod;
	rep(0,i,y)bunbo=(bunbo*(i+1))%mod;
	mody[0]=bunbo;
	rep(1,i,41){
		bunbo=(bunbo*bunbo)%mod;
		mody[i]=bunbo;
	}
	rep(0,i,41)nis[i]=0;
	nn=mod-2;
	for(int i=40;i>=0;i-=1){
		if(nn>n2[i]){
			nis[i]++;
			nn-=n2[i];
		}
	}
	nis[0]++;
	rep(0,i,41){
		if(nis[i]==1){
			bunsi=(bunsi*mody[i])%mod;
		}
	}
	return bunsi;
}
int yakuwa(int n){
	int sum=0;
	rep(1,i,sqrt(n+1)){
		if(n%i==0)sum+=i+n/i;
		if(i*i==n)sum-=i;
	}
	return sum;
}	
bool integer(double n){
	if(n==long(n))return true;
	else return false;	
}
int pow(int b,int a){	
	int aa=1;
	rep(0,i,a)aa*=b;	
	return aa;
}
int sankaku(int a){
	return a*(a+1)/2;
} 
bool search(int x){
	int n;
	int a[n];
	int l=0,r=n;
	while(r-l>=1){
		int i=(l+r)/2;
		if(a[i]==x)return true;
		else if(a[i]<x)l=i+1;
		else r=i;
	}
	return false;
}
int lun[314514];
signed main(){
	ic(n)
	int sum=1;
	rep(1,i,10){
		lun[sum]=i;
		sum++;
	}
	rep(1,i,10){
		rep(max(0,i-1),j,min(10,i+2)){
			lun[sum]=i*10+j;
			sum++;
		}
	}
	rep(1,i,10){
		rep(max(0,i-1),j,min(10,i+2)){
			rep(max(0,j-1),k,min(10,j+2)){
				lun[sum]=i*100+j*10+k;
				sum++;
			}
		}
	}
	rep(1,i,10){
		rep(max(0,i-1),j,min(10,i+2)){
			rep(max(0,j-1),k,min(10,j+2)){
				rep(max(0,k-1),l,min(10,k+2)){
					lun[sum]=i*1000+j*100+k*10+l;
					sum++;
				}	
			}
		}
	}	
	rep(1,i,10){
		rep(max(0,i-1),j,min(10,i+2)){
			rep(max(0,j-1),k,min(10,j+2)){
				rep(max(0,k-1),l,min(10,k+2)){
					rep(max(0,l-1),m,min(10,l+2)){
						lun[sum]=i*10000+j*1000+k*100+l*10+m;
						sum++;
					}	
				}	
			}
		}
	}
	rep(1,i,10){
		rep(max(0,i-1),j,min(10,i+2)){
			rep(max(0,j-1),k,min(10,j+2)){
				rep(max(0,k-1),l,min(10,k+2)){
					rep(max(0,l-1),m,min(10,l+2)){
						rep(max(0,m-1),o,min(10,m+2)){
							lun[sum]=i*100000+j*10000+k*1000+l*100+m*10+o;
							sum++;
						}	
					}	
				}	
			}
		}
	}
	rep(1,i,10){
		rep(max(0,i-1),j,min(10,i+2)){
			rep(max(0,j-1),k,min(10,j+2)){
				rep(max(0,k-1),l,min(10,k+2)){
					rep(max(0,l-1),m,min(10,l+2)){
						rep(max(0,m-1),o,min(10,m+2)){
							rep(max(0,o-1),p,min(10,o+2)){
								lun[sum]=i*1000000+j*100000+k*10000+l*1000+m*100+o*10+p;
								sum++;
							}	
						}	
					}	
				}	
			}
		}
	}
	rep(1,i,10){
		rep(max(0,i-1),j,min(10,i+2)){
			rep(max(0,j-1),k,min(10,j+2)){
				rep(max(0,k-1),l,min(10,k+2)){
					rep(max(0,l-1),m,min(10,l+2)){
						rep(max(0,m-1),o,min(10,m+2)){
							rep(max(0,o-1),p,min(10,o+2)){
								rep(max(0,p-1),q,min(10,p+2)){
									lun[sum]=i*10000000+j*1000000+k*100000+l*10000+m*1000+o*100+p*10+q;
									sum++;
								}	
							}	
						}	
					}	
				}	
			}
		}
	}
	rep(1,i,10){
		rep(max(0,i-1),j,min(10,i+2)){
			rep(max(0,j-1),k,min(10,j+2)){
				rep(max(0,k-1),l,min(10,k+2)){
					rep(max(0,l-1),m,min(10,l+2)){
						rep(max(0,m-1),o,min(10,m+2)){
							rep(max(0,o-1),p,min(10,o+2)){
								rep(max(0,p-1),q,min(10,p+2)){
									rep(max(0,q-1),r,min(10,q+2)){
										lun[sum]=i*100000000+j*10000000+k*1000000+l*100000+m*10000+o*1000+p*100+q*10+r;
										sum++;
									}	
								}	
							}	
						}	
					}	
				}	
			}
		}
	}
	rep(1,i,10){
		rep(max(0,i-1),j,min(10,i+2)){
			rep(max(0,j-1),k,min(10,j+2)){
				rep(max(0,k-1),l,min(10,k+2)){
					rep(max(0,l-1),m,min(10,l+2)){
						rep(max(0,m-1),o,min(10,m+2)){
							rep(max(0,o-1),p,min(10,o+2)){
								rep(max(0,p-1),q,min(10,p+2)){
									rep(max(0,q-1),r,min(10,q+2)){
										rep(max(0,r-1),s,min(10,r+2)){
											lun[sum]=i*1000000000+j*100000000+k*10000000+l*1000000+m*100000+o*10000+p*1000+q*100+r*10+s;
											sum++;
										}
									}		
								}	
							}	
						}	
					}	
				}	
			}
		}
	}
	c(lun[n])
}

Measured memory_bytes: 1792