#include <bits/stdc++.h>
using namespace std;
long long suf(long long a) { return (a * (a + 1)) / 2; }
const long long OO = 1e6 + 10, MOD = 1e6 + 3;
vector<vector<int> > adj, can;
int dx[]{1, -1, 0, 0, 1, -1, 1, -1};
int dy[]{0, 0, 1, -1, 1, -1, -1, 1};
vector<long long> N;
void go(int idx, int Fe, int Se, string s) {
  if (Se != -1 || Fe != -1) {
    long long NN;
    stringstream st;
    st << s;
    st >> NN;
    N.push_back(NN);
  }
  if (idx == 10) return;
  for (int i = 0; i <= 9; i++) {
    if (i != 0 || s.size() != 0 && i == 0) {
      if (Fe == i || Fe == -1)
        go(idx + 1, (Fe == -1 ? i : Fe), Se,
           s + char('0' + (Fe == -1 ? i : Fe)));
      else if (Se == i || Se == -1)
        go(idx + 1, Fe, (Se == -1 ? i : Se),
           s + char('0' + (Se == -1 ? i : Se)));
    }
  }
}
int main() {
  std::ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  string s;
  long long n, m, a, b, c, d, e, k, f, l, r;
  go(0, -1, -1, "");
  sort(((N).begin()), ((N).end()));
  while (cin >> n) {
    long long ans = 0;
    for (int i = 0; i < N.size(); i++) {
      if (N[i] <= n)
        ans++;
      else
        break;
    }
    cout << ans << endl;
  }
  return 0;
}
