#include <bits/stdc++.h>
using namespace std;
int n;
set<int> p;
void gen() {
  for (int i = 1; i <= n; ++i) p.insert(i);
  for (int i = 2; i <= 9; ++i) {
    for (int j = 0; j < 10; ++j)
      for (int k = j + 1; k < 10; ++k) {
        int mask = 1 << i;
        for (int u = 0; u < mask; ++u) {
          int now = 0;
          for (int v = 0; v < i; ++v) {
            if (u >> v & 1)
              now = now * 10 + j;
            else
              now = now * 10 + k;
          }
          if (now) p.insert(now);
        }
      }
  }
  scanf("%d", &n);
  if (n == 1000000000) {
    printf("%d\n", p.size() + 1);
    return;
  }
  if (n >= *p.rbegin()) {
    printf("%d\n", p.size());
    return;
  }
  for (int i = 0;; ++i) {
    if (*p.begin() > n) {
      printf("%d\n", i);
      break;
    }
    p.erase(p.begin());
  }
}
int main() {
  gen();
  return 0;
}
