#include #include #include #include #include using namespace std; typedef long long ll; int b[10] = { 9,8,7,6,5,4,3,2,1,0 }; int digit(ll a); vectorv[15]; int main() { ll N; scanf("%lld",&N); int i, j, k; if (N < 1000000001ll) { printf("0\n"); } else { int d = digit(N); if (d == 19) { d = 18; N = 999999999999999999ll; } for (i = 0; i <= 9; i++) { v[1].push_back(to_string(i)); } v[2].push_back("00"); for (i = 11; i <= 99; i++) { if (i / 10 == i % 10) { v[2].push_back(to_string(i)); } } for (i = 3; i <= 11; i++) { for (k = 0; k <= 9; k++) { for (j = 0; j < v[i - 2].size(); j++) { string s = to_string(k); s += v[i - 2][j]; s += to_string(k); v[i].push_back(s); } } } ll ans = 0ll; for (k = 1; k <= d - 9; k++) { for (i = 0; i < v[k].size(); i++) { string s = v[k][i]; for (j = 0; j < b[k]; j++) { s += to_string(0); } s += v[k][i]; if (s[0] == '0') { continue; } if (stoll(s) <= N) { ans += 1ll; } } } printf("%lld\n", ans); } return 0; } int digit(ll a) { int ret = 0; while (1) { if (a == 0ll) { break; } ret++; a /= 10ll; } return ret; }