#include <bits/stdc++.h>
using namespace ::std;
int A[12];
int cont = 99;
int verifica(int n, int *x, int *y) {
  memset(A, 0, sizeof A);
  int l = 0, c = 1, pos;
  bool f = true;
  int aux = n;
  while (n != 0) {
    A[l] = n % 10;
    n /= 10;
    l++;
  }
  *x = A[l - 1];
  for (int i = l - 2; i >= 0 & f; i--) {
    if (c == 1) {
      if (A[i] != *x) {
        c++;
        *y = A[i];
      }
    }
    if (c == 2) {
      if (A[i] != *x && A[i] != *y) {
        f = false;
        c = 1;
        pos = i;
      }
    }
  }
  if (!f) {
    return aux + pow(10, pos) - 1;
  } else {
    cont++;
    return aux;
  }
}
int main(void) {
  int n, x, y;
  cin >> n;
  if (n < 100)
    cout << n << endl;
  else {
    int pos;
    for (int i = 100; i <= n; i++) i = verifica(i, &x, &y);
    cout << cont << endl;
  }
  return 0;
}
