//#pragma GCC optimize(3)

#include<bits/stdc++.h>
#define MST(a,b) memset(a,b,sizeof(a))
#define pb push_back
#define eb emplace_back
#define rep(i,a,b) for(int i = a ; i < b ; ++i)
#define per(i,a,b) for(int i = a ; i > b ; --i)
#define ALL(v) v.begin(),v.end()
#define ft first
#define sd second
using namespace std;
namespace fast_IO{
    const int maxbuff = 1<<17;
    char ibuff[maxbuff],obuff[maxbuff];
    inline char Getchar(){
        static char *p1=ibuff,*p2=ibuff;
        if(p1 == p2) {
            p1 = ibuff;
            p2 = ibuff+fread(ibuff,1,maxbuff,stdin);
            if(p1 == p2) return -1;
        }
        return *p1++;
    }

    int optr = 0;
    inline void Putchar(char c) {
        if(optr == maxbuff) {fwrite(obuff,1,optr,stdout);optr = 0;}
        obuff[optr++] = c;
    }

    inline void Flush() {
        fwrite(obuff,1,optr,stdout);
    }

    template<class T>
    inline int read(T &x) {
        x = 0;
        char c = Getchar();
        if(c == EOF) return -1;
        for( ; (c < '0' || c > '9') && c != EOF ; c = Getchar());
        if(c == EOF) return -1;
        for( ; c >= '0' && c <= '9' ; c = Getchar()) x = x*10+c-'0';
        return 0;
    }

    template<class T>
    inline void write(const T &x,int tag = 0) {
        if(!x) {
            if(!tag) Putchar(x+'0');
            return ;
        }
        write(x/10,1);
        Putchar(x%10+'0');
    }

    template<class T>
    inline void writeln(const T &x) {
        write(x);Putchar('\n');
    }

    template<class T>
    inline void writesp(const T &x) {
        write(x);Putchar(' ');
    }
}
template<class T> void show(T *x,int len,int s = 0) {for(int i = s ; i < s+len-1 ; ++i) cerr << x[i] << ' ';cerr << x[s+len-1] << endl;}
void debug() {cerr << endl;}
template <typename T, typename... Args> void debug(T x,Args... args) {cerr << x << ' ';debug(args...);}
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> pii;
#include <ext/pb_ds/priority_queue.hpp>
using namespace __gnu_pbds;
typedef __gnu_pbds::priority_queue<pii,greater<>,pairing_heap_tag> heap;
typedef heap::point_iterator iter;

template<class T>
inline void cmin(T &A,const T &B) {A = (A<B?A:B);}
template<class T>
inline void cmax(T &A,const T &B) {A = (A>B?A:B);}

#define int LL
const int N = 11;
int n,len,val,l,r;
int f[N][10][2],s[N];
int ans;

int getlen(int x) {
    int t = 0;
    while(x) {
        ++t;
        x /= 10;
    }
    return t;
}

void calc(int s,int t) {
    int p = 1,tot = 0;
    for(int i = 0 ; i < len-2 ; ++i) {
        ans += p;
        tot += p;
        p *= 10;
    }
    ans += (s==t);
    tot += (s==t);
    //cout << tot << ' ';
}

int dp(int len,int c,int tag) {
    if(f[len][c][tag] != -1) return f[len][c][tag];
    int &ans = f[len][c][tag];
    ans = 0;
    for(int i = 0 ; i < 10 ; ++i) {
        if(!tag) ans += dp(len-1,i,0);
        if(tag == 1 && c == s[len]) ans += dp(len-1,i,1);
        if(tag == 0 && c < s[len]) ans += dp(len-1,i,1);
    }
    return ans;
}

void work(int x) {
    int s,t,ppp = x;
    s = x%10;
    if(s == 0) return ;
    while(x >= 10) x/=10;
    t = x;
    //cout << ppp << ' ';
    calc(s,t);
    if(s > l) {return ;}
    MST(f,-1);
    for(int i = 0 ; i < 10 ; ++i) f[1][i][0] = f[1][i][1] = 0;
    f[1][s][s == l] = 1;
    ans += dp(len,t,0);
    ans += dp(len,t,1);
    //cout << f[len][t][0] + f[len][t][1] << endl;
}

void bf() {
    for(int i = 1 ; i <= n ; ++i)
        for(int j = 1 ; j <= n ; ++j) {
            int a = i,b = j;
            int q,w,e,r;
            q = a%10,w = b%10;
            if(q == 0 || w == 0) continue ;
            while(a >= 10) a/= 10;
            e = a;
            while(b >= 10) b/= 10;
            r = b;
            if(q == r && w == e) ++ans;
        }
    cout << ans << endl;
}

void gets(int n) {
    for(int i = len ; i ; --i) {
        s[i] = n % 10;
        n /= 10;
    }
}

void solve() {
    cin >> n;
    r = n%10;
    {
        int b = n;
        while(b>=10) b/=10;
        l = b;
    }
    len = getlen(n);
    gets(n);
    if(n < 5000) {
        bf();
        return ;
    }
    for(int i = 1 ; i <= n ; ++i)
        work(i);
    cout << ans << endl;
}

signed main() {
#ifdef LOCAL
    //freopen("input","r",stdin);
    //freopen("output","w",stdout);
#endif
    srand((int)time(0));
    ios::sync_with_stdio(0);
    int T = 1;
    //cin >> T;
    while(T--) solve();
}

Measured memory_bytes: 256