#include <bits/stdc++.h>
using namespace std;
int toint(string s) {
  int n;
  istringstream is(s);
  is >> n;
  return n;
}
string tostring(int n) {
  stringstream is;
  is << n;
  return is.str();
}
long long int modulo(int a, int b, int c) {
  long long x = 1, y = a;
  while (b > 0) {
    if (b % 2 == 1) {
      x = (x * y) % c;
    }
    y = (y * y) % c;
    b /= 2;
  }
  return x % c;
}
long long mulmod(long long a, long long b, long long c) {
  long long x = 0, y = a % c;
  while (b > 0) {
    if (b % 2 == 1) {
      x = (x + y) % c;
    }
    y = (y * 2) % c;
    b /= 2;
  }
  return x % c;
}
int query(const vector<int> &tree, int a, int b) {
  if (a == 0) {
    int sum = 0;
    for (; b >= 0; b = (b & (b + 1)) - 1) sum += tree[b];
    return sum;
  } else {
    return query(tree, 0, b) - query(tree, 0, a - 1);
  }
}
void increase(vector<int> &tree, int k, int inc) {
  for (; k < (int)tree.size(); k |= k + 1) tree[k] += inc;
}
map<long long int, int> dp;
int n;
void func(int x, int y, int ptr, long long int num) {
  if (num > n) return;
  if (num >= 1 && num <= n) dp[num] = 1;
  if (!(num == 0 && x == 0)) func(x, y, ptr + 1, num * 10 + x);
  if (!(num == 0 && y == 0)) func(x, y, ptr + 1, num * 10 + y);
}
int main() {
  int x, y;
  cin >> n;
  for (x = 0; x <= 9; x++) {
    for (y = x + 1; y <= 9; y++) {
      func(x, y, 0, 0);
    }
  }
  printf("%d\n", dp.size());
  return 0;
}
