#include <bits/stdc++.h>
using namespace std;
const int MaxN = 1;
int n, sol, counter;
bool mark[20];
void check(long long x) {
  if (x > n) return;
  if (x != 0) sol++;
  for (int i = 0; i <= 9; i++) {
    if (mark[i]) {
      if (i != 0 || (i == 0 && x != 0)) check(x * 10 + i);
    } else {
      if (counter < 2) {
        counter++;
        mark[i] = true;
        if (i != 0 || (i == 0 && x != 0)) check(x * 10 + i);
        mark[i] = false;
        counter--;
      }
    }
  }
}
int main() {
  scanf("%d", &n);
  sol = 0;
  counter = 0;
  for (int i = 0; i <= 9; i++) mark[i] = false;
  long long x = 0;
  check(x);
  printf("%d\n", sol);
  return 0;
}
