#include <bits/stdc++.h>
using namespace std;
template <typename T>
T fastPower(T base, T power) {
  if (!power) return 1;
  T ans = fastPower(base, power / 2);
  return power & 1 ? ans * ans * base : ans * ans;
}
bool can(long long x) {
  map<int, int> freq;
  while (x) {
    ++freq[x % 10];
    if (freq.size() > 2) return false;
    x /= 10;
  }
  return true;
}
long long DFS(long long num, int n) {
  long long ans = 0;
  if (num > 0 and num <= n) ++ans;
  if (num > 1e9) return ans;
  for (int i = 0; i < 10; ++i) {
    long long x = num * 10 + i;
    if (x <= n and can(x) and x > 0) {
      ans += DFS(x, n);
    }
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio();
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  cout << DFS(0, n);
  return 0;
}
