#include <bits/stdc++.h>
using namespace std;
int a[9000], b[9000];
map<int, int> vis;
int n, nn = 0, ans = 0;
void dfs(long long now, int i, int j) {
  int a, b;
  if (now > n) return;
  if (now != 0 && vis[now] == 0) ans++;
  vis[now] = 1;
  if (now != 0 || i != 0) dfs(now * 10 + i, i, j);
  dfs(now * 10 + j, i, j);
}
int main() {
  scanf("%d", &n);
  if (n <= 101) {
    printf("%d\n", n);
    return 0;
  }
  for (int i = 0; i <= 9; i++)
    for (int j = i + 1; j <= 9; j++) {
      dfs(0, i, j);
    }
  printf("%d\n", ans);
}
