#include using namespace std; #define rep(i,a,b) for(int i=a;i=b;i--) typedef long long ll; ll N; //----------------------------------------------------------------- int main() { cin >> N; ll mo = 1000000001; int dig = 0; ll t = N; while (0 < t) dig++, t /= 10; ll ans = 0; rrep(i, 8, 1) { ll c = 0; int d = i + 2 * (9 - i); if (d < dig) { // 全部OK int j = 9 - i; if (j == 1) { c = 9; } else if(j % 2 == 0){ int k = j / 2 - 1; c = 9; rep(kk, 0, k) c *= 10; ans += c; } else { int k = j / 2; c = 9; rep(kk, 0, k) c *= 10; ans += c; } } else if (d == dig) { // 一部OK int j = 9 - i; string n = to_string(N); int ma = 0; rep(i, 0, j) ma = ma * 10 + n[i] - '0'; int mi = 0; rep(i, 0, j) mi = mi * 10 + 1; rep(x, mi, ma) { string s = to_string(x); bool ok = true; rep(i, 0, s.length() / 2 + 1) { int j = s.length() - 1 - i; if (s[i] != s[j]) ok = false; } if (ok) c++; } ll th = ma; rep(i, 0, d - j * 2) th *= 10; int y = ma; while (0 < y) { th = th * 10 + y % 10; y /= 10; } if (th <= N) c++; //cout << th << endl; /*cout << j << endl; cout << ma << endl; cout << mi << endl;*/ } ans += c; //printf("%d -> %lld\n", d, c); } cout << ans << endl; }