#include <iostream>
#include <stdlib.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <assert.h>
#include <memory.h>
#include <time.h>
#include <bitset>
#include<iomanip>
#include<float.h>
 
#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = (l); i < (r); i++)
#define repb(i, r, l) for (int i = (r); i > (l); i--)
#define sz(a) (int)a.size()
#define fi first
#define se second
#define pii pair<int,int>
#define pli pair<ll,int>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define mp(a, b) make_pair(a, b)
#define mt(a,b,c) make_tuple(a,b,c)
#define rank qwertyuio
#define next dfghjk
#define plus fsghsf
#define minus ytryr
#define pb push_back
#define debug(x) cerr<<#x<<": "<<(x)<<endl
using namespace std;
 
inline bool setmin(int &x, int y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(int &x, int y) { return (y > x) ? x = y, 1 : 0; }
inline bool setmin(ll &x, ll y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(ll &x, ll y) { return (y > x) ? x = y, 1 : 0; }
 
const int N = 100000;
const int inf = (int)1e9 + 1;
const ll big = (ll)1e18 + 1;
const int P = 239;
const int P1 = 31;
const int P2 = 57;
const int mod = (int)1e9 + 7;
const int mod1 = (int)1e9 + 9;
const int mod2 = 998244353;
const int mod3 = (int)1e6+3;
const ld eps = 1e-12;
const double pi = atan2(0, -1);
const int ABC = 26;
 void lineFromPoints(pdd P, pdd Q, double &a, 
                        double &b, double &c) 
{ 
    a = Q.second - P.second; 
    b = P.first - Q.first; 
    c = a*(P.first)+ b*(P.second); 
} 
  
// Function which converts the input line to its 
// perpendicular bisector. It also inputs the points 
// whose mid-point lies on the bisector 
void perpendicularBisectorFromLine(pdd P, pdd Q, 
                 double &a, double &b, double &c) 
{ 
    pdd mid_point = make_pair((P.first + Q.first)/2, 
                            (P.second + Q.second)/2); 
  
    // c = -bx + ay 
    c = -b*(mid_point.first) + a*(mid_point.second); 
  
    double temp = a; 
    a = -b; 
    b = temp; 
} 
  
// Returns the intersection point of two lines 
pdd lineLineIntersection(double a1, double b1, double c1, 
                         double a2, double b2, double c2) 
{ 
    double determinant = a1*b2 - a2*b1; 
    if (determinant == 0) 
    { 
        // The lines are parallel. This is simplified 
        // by returning a pair of FLT_MAX 
        return make_pair(FLT_MAX, FLT_MAX); 
    } 
  
    else
    { 
        double x = (b2*c1 - b1*c2)/determinant; 
        double y = (a1*c2 - a2*c1)/determinant; 
        return make_pair(x, y); 
    } 
} 
  
pdd findCircumCenter(pdd P, pdd Q, pdd R,pdd S) 
{ 
    // Line PQ is represented as ax + by = c 
    double a, b, c; 
    lineFromPoints(P, Q, a, b, c); 
  
    // Line QR is represented as ex + fy = g 
    double e, f, g; 
    lineFromPoints(R, S, e, f, g); 
  
    // Converting lines PQ and QR to perpendicular 
    // vbisectors. After this, L = ax + by = c 
    // M = ex + fy = g 
    perpendicularBisectorFromLine(P, Q, a, b, c); 
    perpendicularBisectorFromLine(R, S, e, f, g); 
  
    // The point of intersection of L and M gives 
    // the circumcenter 
    pdd circumcenter = 
           lineLineIntersection(a, b, c, e, f, g); 
  
    
    return circumcenter;
} 

double dis(double x1,double x2,double y1,double y2){
    return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}
ll ans[200007];
int main()
{   ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int n;
    cin>>n;
    int i;
    ll first;
    ll last;
    ll sum=0;
    ll digit;
    ans[1]=1;
    rep(i,2,n+1){
        int j=i;
        first=j%10;
        digit=0;
        ll plus=0;
        ll mul=1;
        while(j>0){
            mul*=10;
            digit++;
            last=j%10;
            j/=10;
        }
        mul/=100;
        if(digit==1){
            plus=1;
        }
        else if(first==0){
            plus=0;
        }
        else if(first==last){
            int ii;
            
            for(ii=3;ii<=digit-1;ii++){
                plus+=1;
                plus*=10;
                
               
            }
            plus+=2;
            if(digit>=3){
                plus+=i/10-mul*last+1;
                //cout<<plus<<" "<<i<<" "<<mul<<" "<<last<<endl;
            }
            plus=2*plus-1;
        }
        else{
            int ii;
            if(last>first){
                for(ii=2;ii<=digit;ii++){
                    plus+=1;
                    plus*=10;
                }
            }
            else{
                for(ii=2;ii<=digit-1;ii++){
                    plus+=1;
                    plus*=10;
                }
            }
            plus/=10;
            plus=2*plus;
            //cout<<plus<<endl;
        }
        ans[i]=ans[i-1]+plus;
    }
    
    
    cout<<ans[n];
    return 0;
             
    
}

Measured memory_bytes: 1792