#include <bits/stdc++.h>
static const int INF = std::numeric_limits<int>::max();
int main() {
  int n;
  std::cin >> n;
  std::vector<int> res;
  if (n == 1000000000) {
    res.push_back(n);
    --n;
  }
  int rk = 0;
  int tn = n;
  while (tn) {
    ++rk;
    tn /= 10;
  }
  for (int i = 1; i <= rk; ++i) {
    for (int j = 0; j <= 9; ++j) {
      for (int k = j; k <= 9; ++k) {
        if (j == k) {
          if (j != 0) {
            int d = 0;
            for (int l = 0; l < i; ++l) {
              d *= 10;
              d += j;
            }
            if (d <= n) {
              res.push_back(d);
            }
          }
        } else {
          for (int mask = 0; mask < (1 << i); ++mask) {
            int d = 0;
            for (int l = 0; l < i; ++l) {
              d *= 10;
              if (mask & (1 << l)) {
                if (l == 0 && j == 0) {
                  d = -1;
                  break;
                }
                d += j;
              } else {
                if (l == 0 && k == 0) {
                  d = -1;
                  break;
                }
                d += k;
              }
            }
            if (d != -1 && d <= n) {
              res.push_back(d);
            }
          }
        }
      }
    }
  }
  std::sort(res.begin(), res.end());
  std::cout << std::unique(res.begin(), res.end()) - res.begin() << std::endl;
}
