#include <bits/stdc++.h>
using namespace std;
int main() {
  int q, w, e, r, t = 0, c, v;
  cin >> q;
  if (q == 1000000000) t = 1;
  for (w = 1; w < 512; w++) {
    c = 1;
    v = w;
    e = r = 0;
    while (v) {
      if (v % 2)
        e += c;
      else
        r += c;
      c *= 10;
      v /= 2;
    }
    for (c = 1; c < 10; c++)
      if (!r) {
        if (e * c <= q) t++;
      } else
        for (v = 0; v < 10; v++)
          if ((e * c + r * v <= q) && (c != v)) t++;
  }
  cout << t;
  return 0;
}
