#include <bits/stdc++.h>
using namespace std;
const int INF_MAX = 0x7FFFFFFF;
const int INF_MIN = -(1 << 30);
const double eps = 1e-10;
const double pi = acos(-1.0);
template <class T>
inline T gcd(T a, T b) {
  if (a < 0) return gcd(-a, b);
  if (b < 0) return gcd(a, -b);
  return (b == 0) ? a : gcd(b, a % b);
}
template <class T>
inline T lcm(T a, T b) {
  if (a < 0) return lcm(-a, b);
  if (b < 0) return lcm(a, -b);
  return a * (b / gcd(a, b));
}
template <class T>
inline void CLR(priority_queue<T, vector<T>, greater<T> > &Q) {
  while (!Q.empty()) Q.pop();
}
inline int random(int l, int r) { return rand() % (r - l + 1) + l; }
int dir_4[4][2] = {{0, 1}, {-1, 0}, {0, -1}, {1, 0}};
int dir_8[8][2] = {{0, 1},  {-1, 1}, {-1, 0}, {-1, -1},
                   {0, -1}, {1, -1}, {1, 0},  {1, 1}};
long long cnt = 0;
void calc(long long up, long long a, long long b, long long k, bool ja,
          bool jb) {
  for (long long i = 0; i < 2; i++) {
    if (i == 0) {
      long long k1 = 10 * k;
      k1 += a;
      if (k1 > up) continue;
      if (jb) {
        cnt++;
      }
      calc(up, a, b, k1, true, jb);
    } else {
      long long k2 = k * 10;
      k2 += b;
      if (k2 > up) continue;
      if (ja) {
        cnt++;
      }
      calc(up, a, b, k2, ja, true);
    }
  }
}
int main() {
  long long up;
  scanf("%I64d", &up);
  for (int i = 1; i <= 9; i++) {
    for (int j = i + 1; j <= 9; j++) {
      calc(up, i, j, 0, false, false);
    }
  }
  for (int i = 1; i <= 9; i++) {
    if (i <= up) cnt++;
    calc(up, i, 0, i, true, true);
  }
  cout << cnt << endl;
  return 0;
}
