#include "bits/stdc++.h" using namespace std; #define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i)) #define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i)) #define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i)) static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL; typedef vector vi; typedef pair pii; typedef vector > vpii; typedef long long ll; template static void amin(T &x, U y) { if (y < x) x = y; } template static void amax(T &x, U y) { if (x < y) x = y; } int main() { vector palins; reu(d, 1, 10) palins.push_back(d); for (int P = 1; P < (int)1e4; P *= 10) { reu(i, P, P * 10) { int revi = 0; for (int x = i, y = P; x > 0; x /= 10, y /= 10) revi += x % 10 * y; palins.push_back(i * P * 10 + revi); rep(d, 10) { palins.push_back(i * P * 100 + d * P * 10 + revi); } } } long long N; while (~scanf("%lld", &N)) { int ans = 0; for (ll x : palins) { ll y = ((ll)1e9 + 1) * x; if (y <= N) { ++ ans; } } printf("%d\n", ans); } return 0; }