#include <bits/stdc++.h>
using namespace std;
int n, ans = 0;
void dfs(int s) {
  if (s > 0 && s <= n) ans++;
  if (s >= 100000000) return;
  for (int i = 0; i <= 9; i++) {
    int t = s * 10 + i;
    int cnt[10] = {0};
    while (t) {
      cnt[t % 10]++;
      t /= 10;
    }
    int temp = 0;
    for (int j = 0; j <= 9; j++) temp += (cnt[j] > 0);
    if (temp <= 2) dfs(s * 10 + i);
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= min(n, 9); i++) dfs(i);
  printf("%d\n", ans + (n == 1000000000));
  return 0;
}
