#include <bits/stdc++.h>
using namespace std;
long int len(long int a) {
  int p = 0;
  while (a != 0) {
    p++;
    a = a / 10;
  }
  return p;
}
int main() {
  long long int n;
  cin >> n;
  long long int p = len(n);
  long long int mx = 0;
  for (long long int i = 1; i <= p; i++) {
    for (long long int j = 1; j < ((1 << i) - 1); j++) {
      for (long long int k = 0; k < 9; k++) {
        if ((k == 0) && ((j & (1 << (i - 1))) == 0)) continue;
        for (long long int l = k + 1; l <= 9; l++) {
          long long int sum = 0;
          for (long long int m = i - 1; m >= 0; m--) {
            if ((j & (1 << m)) == 0)
              sum = sum * 10 + k;
            else
              sum = sum * 10 + l;
          }
          if (sum <= n) mx++;
        }
      }
    }
    for (long long int k = 1; k <= 9; k++) {
      long long int sum = 0;
      for (long long int l = 1; l <= i; l++) sum = sum * 10 + k;
      if (sum <= n) mx++;
    }
  }
  cout << mx << "\n";
  return 0;
}
