#include <bits/stdc++.h>
using namespace std;
const int INF = (int)1e+9 + 9;
const long double EPS = 1e-9;
const long double PI = 3.1415926535897932384626433832795;
const int N = 100500;
int n, ans;
bool good(int num) {
  int a = -1, b = -1;
  while (num > 0) {
    int x = num % 10;
    if (a == -1 || a == x)
      a = x;
    else if (b == -1)
      b = x;
    else if (a != x && b != x)
      return false;
    num /= 10;
  }
  return true;
}
void f(int num) {
  if (num > 0 && num <= n) ans++;
  if (num >= (int)1e+8) return;
  for (int i = 0; i <= 9; ++i)
    if (num * 10 + i > 0)
      if (good(num * 10 + i)) f(num * 10 + i);
}
int main() {
  cin >> n;
  f(0);
  if (n == (int)1e+9) ans++;
  cout << ans;
  return 0;
}
