#include <bits/stdc++.h>
using namespace std;
set<long long> s;
long long n;
int main(int argc, char const *argv[]) {
  ios::sync_with_stdio(false);
  scanf("%I64d", &n);
  for (long long i = 1; i < 10; i++)
    for (long long z = 0; z < 1023; z++) {
      long long x = i, y = z;
      for (long long j = 0; j < 10; j++, y = y / 2) {
        if (y & 1)
          x = (long long)(x * 10 + i);
        else
          x = x * 10;
        if (x <= n) s.insert(x);
      }
    }
  for (long long i = 1; i < 10; i++)
    for (long long j = i + 1; j < 10; j++)
      for (long long z = 1; z < 1023; z++) {
        long long x = 0LL, y = z;
        for (long long xx = 0; xx < 10; xx++, y = y / 2) {
          if (y & 1)
            x = (long long)(x * 10 + i);
          else
            x = (long long)(x * 10 + j);
          if (x <= n) s.insert(x);
        }
      }
  cout << (long long)s.size();
  return 0;
}
