#include <bits/stdc++.h>
int dx[] = {0, 0, 1, -1, 1, -1, 1, -1};
int dy[] = {1, -1, 0, 0, -1, 1, 1, -1};
const double PI = acos(-1), EPS = 1e-7;
const int OO = 0x3f3f3f3f, N = 1e7 + 5, mod = 1e9 + 7;
using namespace std;
long long gcd(long long x, long long y) { return (!y) ? x : gcd(y, x % y); }
long long lcm(long long x, long long y) { return ((x / gcd(x, y)) * y); }
void file() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
int n;
bool ok(int x) {
  map<int, int> mp;
  while (x) {
    mp[x % 10]++;
    x /= 10;
  }
  return ((int)mp.size() <= 2);
}
int cnt;
void DFS(int x) {
  if (x > 0 && x <= n) cnt++;
  if (x > 1e8) return;
  if (x > n) return;
  for (int i = 0; i <= 9; i++) {
    if (x * 10 + i > 0 && ok(x * 10 + i)) DFS(x * 10 + i);
  }
}
int main() {
  file();
  cin >> n;
  DFS(0);
  cout << cnt;
}
