#include #include #include #include using lint = long long; std::vector palis(int d) { std::vector ret; if (d == 0) { ret.push_back(""); } else if (d == 1) { for (int x = '0'; x <= '9'; ++x) { ret.push_back(std::string(1, x)); } } else { auto res = palis(d - 2); for (auto& s : res) { s.insert(s.begin(), '$'); s.push_back('$'); for (int x = '0'; x <= '9'; ++x) { s.front() = s.back() = x; ret.push_back(s); } } } return ret; } void solve() { std::vector ps; for (int d = 1; d <= 9; ++d) { auto res = palis(d); for (const auto& s : res) { if (s.front() == '0') continue; ps.push_back(std::stoi(s)); } } lint n; std::cin >> n; n /= 1000000001; std::cout << std::count_if(ps.begin(), ps.end(), [&](auto p) { return p <= n; }) << "\n"; } int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); solve(); return 0; }