#include<bits/stdc++.h>
using namespace std;
typedef long long LL;

#define CIN_ONLY if(1)
struct cww{cww(){
    CIN_ONLY{
        ios::sync_with_stdio(false);cin.tie(0);
    }
}}star;
#define fin "\n"
#define FOR(i,bg,ed) for(int i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
#define pb push_back
#define DEBUG if(0)
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline void chmin(T &l,T r){l=min(l,r);}
template <typename T>inline void chmax(T &l,T r){l=max(l,r);}
template <typename T>
istream& operator>>(istream &is,vector<T> &v){
    for(auto &it:v)is>>it;
    return is;
}
template <typename ITR>
bool next_value(int base,ITR bg,ITR ed){
    int c=1;
    for(; bg != ed && c==1; ++bg){
        (*bg)+=c;
        if((c = ((*bg) == base)))(*bg)=0;
    }
    return !c;
}

const LL B=1e9;
int main(){
    LL N;
    cin>>N;
    int res=0;
    FOR(i,1,10)if(i*B+i<=N)res++;
    REP(len,4){
        vector<LL> x(len,0);
        do{
            FOR(i,1,10)REP(j,11){
                LL y=0;
                y=i;
                REP(k,len){y*=10;y+=x[k];}
                if(j<10){y*=10;y+=j;}
                REP(k,len){y*=10;y+=x[len-k-1];}
                y*=10;y+=i;
                y=y*B+y;
                if(y<=N)res++;
                //                cout<<y<<endl;
            }
        }while(next_value(10,ALL(x)));
    }
    cout<<res<<endl;
    return 0;
}