#include <bits/stdc++.h>
using namespace std;
int ans = 0;
int n;
int check(int p) {
  if (p <= 9) return 0;
  bool a[20];
  for (int i = 0; i <= 9; i++) {
    a[i] = 0;
  }
  int sa = 0;
  while (p) {
    if (a[p % 10] == 0) {
      sa++;
      a[p % 10] = 1;
    }
    p /= 10;
  }
  if (sa <= 2)
    return 0;
  else
    return 1;
}
void dfs(int car) {
  if (car >= 1 && car <= n) {
    ans++;
  } else if (car != 0) {
    return;
  }
  if (car > 1000 * 1000 * 100) return;
  for (int i = 0; i <= 9; i++) {
    if (car * 10 + i > 0) {
      if (check(car * 10 + i) == 0) {
        dfs(car * 10 + i);
      }
    }
  }
}
int main() {
  cin >> n;
  dfs(0);
  cout << ans;
}
