#include <bits/stdc++.h>
using namespace std;
long long ans = 0;
bool check(long long x) {
  set<long long> s;
  while (x != 0) {
    s.insert(x % 10);
    x /= 10;
  }
  if (s.size() <= 2)
    return 1;
  else
    return 0;
}
void f(long long x, long long n) {
  if (x > 0 && x <= n) {
    ans++;
  }
  if (x > n) return;
  for (long long i = 0; i <= 9; i++) {
    if (x * 10 + i > 0)
      if (check(x * 10 + i)) f(x * 10 + i, n);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  long long n;
  cin >> n;
  f(0, n);
  cout << ans;
  return 0;
}
