#include <bits/stdc++.h>
using namespace std;
int step, n;
long long ans = 0;
bool check(int a) {
  string tmp = to_string(a);
  unordered_set<char> count;
  for (auto i : tmp) count.insert(i);
  if (count.size() <= 2)
    return true;
  else
    return false;
}
void dfs(int a) {
  if (a > 0 && a <= n) {
    ans++;
  }
  if (a > pow(10, 8)) return;
  for (int i = 0; i <= 9; i++) {
    int b = a * 10 + i;
    if (b > 0 && check(b)) dfs(b);
  }
}
void solve() {
  cin >> n;
  dfs(0);
  cout << ans << endl;
}
int main() {
  step = 1;
  while (step--) {
    solve();
  }
  return 0;
}
