program Handstand2

  implicit none

  integer N
  integer a, b
  real logA,logB
  integer intLogA, intLogB
  integer a1, a2, b1, b2
  integer :: count = 0

  read *, N
  do a = 1, N
    do b = 1, N
      logA = log10(real(a))
      logB = log10(real(b))
      intLogA = 10 ** int(logA)
      intLogB = 10 ** int(logB)
      logA = real(intLogA)
      logB = real(intLogB)
      a1 = a / logA
      a2 = mod(a,10)
      b1 = b / logB
      b2 = mod(b,10)
      if (a1 == b2 .and. a2 == b1) then
        ! print *,a,b
        count = count + 1
      end if
    end do
  end do

  print '(i0)', count

end program
