#include <bits/stdc++.h>
using namespace std;
int SI(string st) {
  int ans;
  stringstream s;
  s << st;
  s >> ans;
  return ans;
}
string IS(int n) {
  string str;
  stringstream s;
  s << n;
  s >> str;
  return str;
}
set<long int> a;
set<long int>::iterator it;
bool islucky(long int n) {
  int h[10] = {0};
  int c = 0;
  while (n > 0) {
    if (h[n % 10] == 0) c++;
    h[n % 10]++;
    n /= 10;
  }
  return c <= 2;
}
void f(long int n) {
  if (n > 1000000000 || n < 0) return;
  int s;
  if (n == 0)
    s = 1;
  else
    s = 0;
  for (int i = s; i <= 9; i++) {
    if (islucky(n * 10 + i) && (n * 10 + i) > 0 && (n * 10 + i) <= 1000000000) {
      a.insert(n * 10 + i);
      f(n * 10 + i);
    }
  }
}
int main() {
  long int n, ans = 0;
  cin >> n;
  f(0);
  for (it = a.begin(); it != a.end(); it++) {
    if (*it <= n)
      ans++;
    else
      break;
  }
  cout << ans << "\n";
  return 0;
}
