#include <bits/stdc++.h>
using namespace std;
bool use[15];
int n, m, ans;
void dfs(long long num, int now, int cnt) {
  if (num <= n)
    ans++;
  else
    return;
  if (now == m) return;
  if (cnt < 2)
    for (int i = 0; i < 10; i++)
      if (!use[i]) {
        use[i] = true;
        dfs(num * 10 + i, now + 1, cnt + 1);
        use[i] = false;
      } else
        dfs(num * 10 + i, now + 1, cnt);
  else
    for (int i = 0; i < 10; i++)
      if (use[i]) dfs(num * 10 + i, now + 1, cnt);
}
int main() {
  cin >> n;
  int n2 = n;
  while (n2) {
    n2 /= 10;
    m++;
  }
  for (int i = 1; i <= 9; i++) {
    use[i] = true;
    dfs((long long)i, 1, 1);
    use[i] = false;
  }
  cout << ans << endl;
  return 0;
}
