#include <bits/stdc++.h>
using namespace std;
string tostr(long long x) {
  stringstream ss;
  ss << x;
  return ss.str();
}
long long toint(const string &s) {
  stringstream ss;
  ss << s;
  long long x;
  ss >> x;
  return x;
}
vector<int> pri;
void sieve() {
  vector<bool> prime(1000 + 1, true);
  prime[0] = prime[1] = false;
  for (int i = 2; i <= 1000; ++i)
    if (prime[i])
      if (i * 1ll * i <= 1000)
        for (int j = i * i; j <= 1000; j += i) prime[j] = false;
  for (int i = 2; i <= 1000; i++)
    if (prime[i]) pri.push_back(i);
}
string s;
int len, ar[10][10] = {0};
set<long long> v;
void rec(string num, int i, int j) {
  if (toint(num) > 1LL * 1000000000) return;
  rec(num + tostr(i), i, j);
  rec(num + tostr(j), i, j);
  v.insert(toint(num));
}
void pre() {
  for (int i = 1; i <= 9; i++)
    for (int j = 0; j <= 9; j++) rec(tostr(i), i, j);
}
int main() {
  pre();
  int n;
  cin >> n;
  int i = 0;
  set<long long>::iterator it;
  for (it = v.begin(); it != v.end(); it++)
    if (*it > n)
      break;
    else
      i++;
  cout << i << endl;
  return 0;
}
