#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=1e5+10;
const int inf=0x3f3f3f3f;
ll n,a[N],f[100][100];
ll vis[10];
ll read(){
ll s=0,w=1;
char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-') w=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){s=s*10+ch-'0';ch=getchar();}
return s*w;
}
ll dfs(int pos,int sum,bool zero,bool top){
if(!pos){
for(int i=1;i<=9;i++) if(vis[i]) return 0;
return 1;
}
if(!top&&!zero&&f[pos][sum]>=0) return f[pos][sum];
int low;
if(top) low=a[pos];
else low=9;
ll res=0;
for(int i=0;i<=low;i++){
if(!vis[i]&&i!=0) continue;
if(i!=0) vis[i]--;
res+=dfs(pos-1,sum+((i==0)),zero&&(i==0),top&&(i==low));
if(i!=0)vis[i]++;
}
if(!top&&!zero) f[pos][sum]=res;
return res;
}
int main(){
memset(f,-1,sizeof(f));
n=read();
int cnt=0;
while(n){
a[++cnt]=n%10;
vis[a[cnt]]++;
n/=10;
}
vis[0]=inf;
printf("%lld",dfs(cnt,0,0,1)-1);
return 0;
}