#include <bits/stdc++.h>
using namespace std;
const int MX = 25;
int n;
set<int> s;
void solve(int d1, int d2, long long x, int k, int len) {
  if (x > n) return;
  if (k == len) {
    if (x <= n) {
      s.insert(x);
    }
    return;
  }
  solve(d1, d2, 10 * x + d1, k + 1, len);
  solve(d1, d2, 10 * x + d2, k + 1, len);
}
int main(int argc, char *argv[]) {
  cin >> n;
  if (n < 100) {
    cout << n << endl;
    return 0;
  }
  for (int len = (3), _b = (10); len < (_b); ++len) {
    for (int i = (1), _b = (10); i < (_b); ++i)
      for (int j = (0), _b = (10); j < (_b); ++j) {
        if (j == i) continue;
        int x = (i * 10 + j);
        solve(i, j, x, 0, len - 2);
      }
    for (int i = (1), _b = (10); i < (_b); ++i) {
      int x = i * 10 + i;
      for (int j = (0), _b = (10); j < (_b); ++j)
        if (j != i) solve(i, j, x, 0, len - 2);
    }
  }
  if (n == 1000000000) s.insert(n);
  cout << s.size() + 99 << endl;
  return 0;
}
