#include <bits/stdc++.h>
using namespace std;
long long n, tot, ans, ya, yb;
void srh(int a, int b, long long now) {
  if (ya && yb && now <= n) ans++;
  if (now * 10 + a <= n) {
    ya++;
    srh(a, b, now * 10 + a);
    ya--;
  }
  if (now * 10 + b <= n) {
    yb++;
    srh(a, b, now * 10 + b);
    yb--;
  }
}
void s(int a, long long now) {
  if (now <= n) ans++;
  if (now * 10 + a <= n) s(a, now * 10 + a);
}
int main() {
  scanf("%lld", &n);
  for (int i = 0; i <= 9; i++)
    for (int j = i + 1; j <= 9; j++) {
      if (i) {
        ya = 1;
        yb = 0;
        srh(i, j, i);
        ya = 0;
        yb = 0;
      }
      if (j) {
        ya = 0;
        yb = 1;
        srh(i, j, j);
        ya = 0;
        yb = 0;
      }
    }
  for (int i = 1; i <= 9; i++) s(i, i);
  printf("%lld\n", ans);
  return 0;
}
