#include <bits/stdc++.h>
using namespace std;
long long n, ans = 0;
int CORONA(long long x) {
  long long k = x, d, p[10] = {0}, pp = 0;
  while (k > 0) {
    d = k % 10;
    if (!p[d]) {
      p[d] = 1;
      pp++;
    }
    k /= 10;
  }
  if (pp <= 2)
    return 1;
  else
    return 0;
}
void BApPa_LaGyA(long long x) {
  if (x > 0 && x <= n) ans++;
  if (x > pow(10, 9)) return;
  for (long long i = 0; i <= 9; i++) {
    if (x * 10 + i > 0) {
      if (CORONA(x * 10 + i)) {
        BApPa_LaGyA(x * 10 + i);
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  cin >> n;
  BApPa_LaGyA(0);
  cout << ans << endl;
}
