#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n, ans;
void dfs(int A, int B, ll now) {
if (now > n) {
return;
}
ans++;
if (A != B) {
dfs(A, B, now * 10 + A);
dfs(A, B, now * 10 + B);
}
else {
for (int i = 0; i <= 9; i++) {
dfs(B, i, now * 10 + i);
}
}
}
int main () {
cin >> n;
if (n <= 9) {
cout << n << endl;
exit(0);
}
ans = 9;
for (int i = 1; i <= 9; i++) {
for (int j = 0; j <= 9; j++) {
dfs(i, j, i * 10 + j);
}
}
cout << ans << endl;
}