program Handstand2

  implicit none

  integer N
  integer a, b
  real logA,logB
  ! integer intLogA, intLogB
  integer a1, a2, b1, b2
  integer :: count = 0
  integer Pa1(200000), Pa2(200000), Pb1(200000), Pb2(200000)

  read *, N
  do a = 1, N
    logA = real(10 ** int(log10(real(a))))
    a1 = a / logA
    a2 = mod(a,10)
    Pa1(a) = a1
    Pa2(a) = a2
  end do
  do b = 1, N
    ! logA = log10(real(a))
    ! logB = log10(real(b))
    ! intLogA = 10 ** int(log10(real(a)))
    ! intLogB = 10 ** int(logB)
    logB = real(10 ** int(log10(real(b))))
    b1 = b / logB
    b2 = mod(b,10)

    Pb1(b) = b1
    Pb2(b) = b2
  end do

  ! print *, Pa1
  ! print *, Pa2
  ! print *, Pb1
  ! print *, Pb2

  do a = 1, N
    do b = 1, N
      if (Pa1(a) == Pb2(b) .and. Pa2(a) == Pb1(b)) then
        ! print *,a,b
        count = count + 1
      end if
    end do
  end do

  print '(i0)', count

end program
