#coding:utf-8
import sys,os
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    XLMIIS = lambda x: [LMIIS() for _ in range(x)]
    YN = lambda c : print('Yes') if c else print('No')
    MOD = 10**9+7

    sN = input()
    N = int(sN)
    firts_digit = int(sN[0])
    last_digit = int(sN[-1])
    num_candidates = max(min(firts_digit,last_digit),firts_digit -1 )
    max_inter_digits = len(sN) - 2
    

    ans = 0
    #for i in range(10**(len(sN)-1),N+1):
    max_inter_digits = len(sN) - 2
    intermediate = 0
    for _ in range(max_inter_digits):
        intermediate = intermediate*10+1
    # print(intermediate)
    if len(sN) == 1:
        print(N)
        return
    elif len(sN) == 2:
        ans = 9
        for i in range(1,10):
            tmp = i
            if i * 11 <= N:
                ans += 1
        for i in range(11,N+1):
            if i % 10 == 0:
                continue
            if i % 11 == 0:
                ans += 1
            if (i % 10) * 10 + i//10 <= N:
                ans += 1
            # print(i,ans)
        print(ans)
        return 

    first_N = int(sN[0])
    last_N = N % 10
    for i in range(1,N+1):

        # print(i,ans,intermediate)
        if i%10 == 0:
            continue
        si = str(i)
        #print(intermediate)
        if si[0] != si[-1]:
            ans += intermediate
        else:
            ans += intermediate + 1
            # ans += 
        # print(i,ans,intermediate)
        first_B = i % 10
        last_B = int(si[0])
        # first_N = int(sN[0])
        # last_N = i % 10



        
        if first_B <  first_N:
            ans += pow(10,max(len(sN)-2,0))
        elif first_B == first_N:
            # print(i) if i == 1 or i == 11 else None
            sm = sN[1:-1]
            m = (N % pow(10,len(sN)-1)) // 10 + 1 #if len(sN) > 2 else (N % pow(10,len(sN)-1))
            # print('i=',i,'m=',m)
            if last_B <= last_N:
                ans += m
            else:
                ans += max(m-1,0)
            # print(i,m) if i == 1 or i == 11 else None

            
            
    print(ans)
    '''


        N = 2500
        2012
        2
        22
        2?2
        2xy2 - 2492
            x: 0...4
            y: 0...9
            sm = 2492 = sN[:-2]+si[0]
            m = int(m)
            if m > N:
                sm = str(m-10)
            intermediate += (sm[1]+1)*....*(sm[-2]+1)
            

        N = 90000
        i = 65432
        26
        2?6
        2??6
        2???6 29996
            first_i = int(si[-1])
            first_N = int(N[0])
            if first_i <  first_N:
                intermediate = intermediate *10 +1
                ans += intermediate
            elif first_i == first_N:
                sm = sN[:-2]+si[0]
                tmp = 1
                for c in sm[1:-2]:
                    tmp*= c+1
                ans += tmp
            
                
                



        N = 30512
        i = 503
        i[-1] == N[0]
        35
        3?5
        3??5
        3???5 
        sm =  30505 = sN[0:-1] + str(i[0])
        intermediate += (s[1]+1)*...*(s[-2]+1)
        if m < N:
            m -=10
        '''

    

if __name__ == '__main__':
    main()

Measured memory_bytes: 42732