#include using namespace std; typedef long long ll; typedef vector vint; typedef pair pint; typedef vector vpint; #define rep(i,n) for(int i=0;i<(n);i++) #define reps(i,f,n) for(int i=(f);i<(n);i++) #define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++) #define all(v) (v).begin(),(v).end() #define eall(v) unique(all(v), v.end()) #define pb push_back #define mp make_pair #define fi first #define se second #define chmax(a, b) a = (((a)<(b)) ? (b) : (a)) #define chmin(a, b) a = (((a)>(b)) ? (b) : (a)) const int MOD = 1e9 + 7; const int INF = 1e9; const ll INFF = 1e18; set tmp; void dfs(string s, int cnt, int size){ // cout << s << endl; if(cnt == size){ // cout << s << endl; // tmp.pb(s); tmp.insert(s); return; } if(size % 2 == 1 && cnt == size / 2){ if(size >= 2){ rep(i, 10){ string d = to_string(i); dfs(s + d, cnt + 1, size); } }else{ reps(i, 1, 10){ string d = to_string(i); dfs(s + d, cnt + 1, size); } } } if(cnt < size / 2){ if(cnt != 0){ rep(i, 10){ string d = to_string(i); dfs(s + d, cnt + 1, size); } }else{ reps(i, 1, 10){ string d = to_string(i); dfs(s + d, cnt + 1, size); } } } if(cnt >= size / 2){ // printf("size %d \n",size - cnt - 1 ); auto d = s[size - cnt - 1]; // cout << "last " << s + d << endl; dfs(s + d, cnt + 1, size); } return; } ll solve(ll n){ ll ret = 0; string s = to_string(n); /* rep(i, s.size() / 2 + 1){ if(i % 2 == 0) ret += pow(9, i / 2); else ret += pow(9, i); } printf("tret %lld\n", ret); */ /* ll tmp = 1; bool flag = false; rep(i, s.size() / 2 + 1){ ll d = min(s[i] - '0', s[s.size() - i - 1] - '0'); printf("i %d d %lld\n", i, d); if(d != 0) flag = true; tmp *= d; if(s.size() % 2 == 0 && i == s.size() / 2 - 1) break; } if(flag) ret += tmp; return ret; */ // dfs("", 0, s.size()); reps(cnt, 1, s.size() + 1){ reps(i, 1, 10){ auto d = to_string(i); dfs(d, 1, cnt); } } set ans; for(auto u : tmp) ans.insert(stoll(u)); for(auto u : ans){ // cout << "u " << u << endl; if(1 <= u && u<= n){ // printf("%lld\n", u); ret++; } } return ret; } int main(void){ ll n; cin >> n; n /= (INF + 1); // printf("%lld\n", n); printf("%lld\n", solve(n)); return 0; } /* 1000000001 9000000009 11000000011 */