main = interact $ unlines . map (show . bottommost . map (read . return)) . lines
bottommost ns = head $ iterateUntil ((==1) . length) (compress (\x y -> mod (x+y) 10)) ns
 where
  iterateUntil p f x = if p x == True then x else iterateUntil p f (f x)
  compress _ [x] = []
  compress op (x1:x2:xs) = op x1 x2 : compress op (x2:xs)