#include <bits/stdc++.h>
using namespace std;
long long n, ans;
map<long long, bool> mp;
void DFS(long long x, long long a, long long b) {
  if (mp.count(x) == 0 && x != 0) {
    ans++;
  }
  mp[x] = 1;
  if (x * 10 + a <= n && x * 10 + a != 0) {
    DFS(x * 10 + a, a, b);
  }
  if (x * 10 + b <= n && x * 10 + b != 0) {
    DFS(10 * x + b, a, b);
  }
}
int main() {
  cin >> n;
  for (int i = 0; i <= 9; i++) {
    for (int j = 0; j <= 9; j++) {
      if (i != j) {
        DFS(0, i, j);
      }
    }
  }
  cout << ans;
  return 0;
}
