#include <fstream>
#include <cstring>
using namespace std;
char num[100];
int ct[10], len;
long long calc (int bt)
{
double ans = 1.0;
for (int i=2; i<=bt; i++)
ans *= i;
for (int i=0; i<10; i++)
for (int j=2; j<=ct[i]; j++)
ans /= j;
return (long long)ans;
}
long long go (const int wh)
{
if (wh == len)
return 0;
int bn=num[wh]-'0';
long long ans = 0;
for (int i=bn-1; i>=0; i--)
if (ct[i])
{
ct[i]--;
ans += calc(len-wh-1);
ct[i]++;
}
ct[bn]--;
return ans + go(wh+1);
}
int main ()
{
ifstream fin("perm.in");
ofstream fout("perm.out");
fin >> num;
len = strlen(num);
for (int i=0; i<len; i++)
ct[num[i]-'0']++;
fout << go(0) << endl;
fin.close();
fout.close();
return 0;
}