#include #include #include int main() { std::string n; std::cin >> n; while (n.length() < 18) { n = "0" + n; } if (n.length() == 19) { n = std::string(18, '9'); } std::string S = n.substr(0, 9); std::string T = n.substr(9, 9); long long S_num = std::stoll(S); long long T_num = std::stoll(T); long long num; if (T_num >= S_num) { num = S_num; } else { num = S_num - 1; } long long ans = std::min(num, 9LL); long long x = 1; while (true) { bool br = false; for (long long i = x; i < 10 * x; ++i) { std::string i_str = std::to_string(i); std::string z = i_str + std::string(i_str.rbegin(), i_str.rend()); if (std::stoll(z) <= num) { ans += 1; } else { br = true; } for (int j = 0; j < 10; ++j) { std::string z_with_j = i_str + std::to_string(j) + std::string(i_str.rbegin(), i_str.rend()); if (std::stoll(z_with_j) <= num) { ans += 1; } else { br = true; } } } x *= 10; if (br) { break; } } std::cout << ans << std::endl; return 0; }