#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
template<class T>using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;

int main() {
  ll N; cin >> N;
  if (N < 1000000001) {
    cout << "0\n";
    return 0;
  }
  int ans = 0;
  int n = N / 1000000001LL;
  // n以下の数字のうち回文である個数を求めれば良い
  priority_queue_rev<pair<int, pair<ll, string>>> q;
  rep(i, 10)
    q.emplace(1, make_pair(i, to_string(i)));
  q.emplace(1, make_pair(0, ""));
  while (!q.empty()) {
    auto [idx, e] = q.top(); q.pop();
    auto [p, s] = e;
    if (p > n) break;
    if (s[0] != '0' && p != 0) {
      ++ans;
    }
    if (idx > 4)
      continue;
    rep(i, 10) {
      string s2 = to_string(i) + s + to_string(i);
      q.emplace(idx+1, make_pair(stoll(s2), s2));
    }
  }
  cout << ans << endl;
  return 0;
}