#include <bits/stdc++.h>
using namespace std;
void fastio() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
template <typename T>
T POW(T B, T P) {
  if (P == 0) return 1;
  if (P & 1)
    return B * POW(B, P - 1);
  else
    return (POW(B, P / 2)) * (POW(B, P / 2));
}
long long powmod(long long a, long long b) {
  long long ans = 1;
  while (b) {
    if (b & 1) ans = ans * a % 100000007;
    a = a * a % 100000007;
    b >>= 1;
  }
  return ans;
}
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
int main() {
  int n;
  cin >> n;
  set<long long> s;
  for (int mask = 0; mask < POW(2, 9); mask++) {
    for (int x = 0; x <= 9; x++) {
      for (int y = 0; y <= 9; y++) {
        long long result = 0;
        for (int j = 0; j < 9; j++) {
          if (mask & (1 << j))
            result = result * 10LL + x;
          else
            result = result * 10LL + y;
          if (result > 0 && result <= n) s.insert(result);
        }
      }
    }
  }
  if (n == 1000000000)
    cout << s.size() + 1 << '\n';
  else
    cout << s.size() << '\n';
}
