Example

Input

20


Output

4
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
typedef long long ll;
string s;
int N,x[14];
ll X;
ll inf=1e14;
ll dp[2][9*14+1][25606][3];
vector<ll> ash;
int nxt[25606][10];
int main(){
	cin>>s;
	N=s.size();
	rep(i,N) x[i]=s[i]-'0';
	rep(i,N) X=X*10+x[i];
	rep(a,43) rep(b,29) rep(c,15) rep(d,15){
		ll v=1;
		rep(i,a) v=min(inf+1,v*2);
		rep(i,b) v=min(inf+1,v*3);
		rep(i,c) v=min(inf+1,v*5);
		rep(i,d) v=min(inf+1,v*7);
		if(v<=inf) ash.pb(v);
	}
	sort(all(ash));
	int M=ash.size();
	rep(i,M) rep(j,10){
		ll x=ash[i]*(j+1);
		if(x<=inf) nxt[i][j]=lower_bound(all(ash),x)-ash.begin();
		else nxt[i][j]=-1;
	}
	dp[0][0][0][1]=1;
	rep(i,N){
		rep(j,9*i+1) rep(k,M) rep(l,3) dp[1-i%2][j][k][l]=0;
		rep(j,9*i+1) rep(k,M) rep(l,3){
			if(dp[i%2][j][k][l]==0) continue;
			rep(d,10){
				int nk=nxt[k][d];
				if(nk<0) continue;
				int nl=l;
				if(nl==1){
					if(d<x[i]) nl=0;
					if(d>x[i]) nl=2;
				}
				dp[1-i%2][j+d][nk][nl]+=dp[i%2][j][k][l];
			}
		}
	}
	ll ans=0;
	int J=accumulate(x,x+N,0);
	ll val=1;
	rep(i,N) val*=(x[i]+1);
	int K=lower_bound(all(ash),val)-ash.begin();
	rep(j,9*N+1) rep(k,M) rep(l,3){
		if(j<J||(j==J&&k<K)||(j==J&&k==K&&l==0)) ans+=dp[N%2][j][k][l];
	}
	cout<<ans<<endl;
}