#include <bits/stdc++.h>
using namespace std;
int x, y, lim;
set<int> numbs;
set<int>::iterator it;
void btracking(int n = 0, int a = 0) {
  if (a == lim) {
    if (n) numbs.insert(n);
    return;
  }
  btracking(10 * n + x, a + 1);
  btracking(10 * n + y, a + 1);
}
int main() {
  int N;
  int h = 0;
  for (x = 0; x < 10; x++)
    for (y = 0; y < 10; y++)
      for (lim = 1; lim <= 9; lim++) btracking();
  scanf(" %d", &N);
  for (it = numbs.begin(); it != numbs.end() && *it <= N; it++) h++;
  if (N == 1000000000) h++;
  printf("%d\n", h);
  return 0;
}
