#include <bits/stdc++.h>
using namespace std;
vector<long long int> v;
set<int> s;
long long int n, x, y, cnt = 0;
void join(long long int val);
int main() {
  cin >> n;
  if (n <= 10)
    cout << n << endl;
  else {
    cnt = 0;
    for (int i = 9; i > 0; i--) {
      for (int j = 9; j >= 0; j--) {
        x = i;
        y = j;
        if (j != 0) {
          if (i <= n) {
            join(i);
          }
          if (j <= n) {
            join(j);
          }
        } else {
          join(i);
        }
      }
    }
    cnt = s.size() + 9;
    cout << cnt << endl;
  }
  return (0);
}
void join(long long int val) {
  long long int a = val * 10 + x;
  long long int b = val * 10 + y;
  if (a <= n) {
    join(a);
    s.insert(a);
  }
  if (b <= n) {
    join(b);
    s.insert(b);
  }
}
