#include <bits/stdc++.h>
using namespace std;
const int INF = 1061109567;
long long N;
int len(long long a) {
  int res = 0;
  while (a) res++, a /= 10;
  return res;
}
set<long long> q;
void gen(int l, int x, int y, int k, long long num) {
  if (k != len(num)) return;
  if (l == k) {
    if (num <= N) {
      q.insert(num);
    }
    return;
  }
  if (k || x > 0) gen(l, x, y, k + 1, num * 10 + x);
  if (k || y > 0) gen(l, x, y, k + 1, num * 10 + y);
}
int main() {
  cin >> N;
  if (N <= 10) {
    cout << N << "\n";
    return 0;
  }
  for (int i = 1; i <= 10; ++i) q.insert(i);
  for (int l = 2; l <= 10; ++l)
    for (int x = 0; x < 10; ++x)
      for (int y = 0; y < 10; ++y) {
        gen(l, x, y, 0, 0);
      }
  cout << (int)((q).size());
  return 0;
}
