int MAIN()
{
int n; cin>>n;
if(n<10) return n;
queue<LL> stq;
for(LL i=10;i<=99&&i<=n;i++) stq.push(i);
int ret = 0;
while(!stq.empty()) {
LL can = stq.front(); stq.pop();
LL cansave = can;
if(can>n) continue;
ret++;
LL a=can%10,b=-1;
while(can>0&&(a==can%10)) can/=10;
if(can>0) b=can%10;
if(b==-1) {
for(int k=0;k<=9;k++) stq.push(cansave*10+(LL)k);
}else {
stq.push(cansave*10+a);
stq.push(cansave*10+b);
}
}
cout<<ret+9;
return 0;
}
int main()
{
//srand((unsigned)time(NULL));
#ifdef LOCAL_TEST
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
ios :: sync_with_stdio(false);
//cout << fixed << setprecision(16);
return MAIN();
}