object Main extends App {
  val src: Iterator[List[Int]] = io.Source.stdin.getLines.map(_.split("").map(_.toInt).toList)

  def bottomMost(li: List[Int]): Char = {
    if (li.length == 1) li.head.toString.last
    else bottomMost(bottomList(li))
  }

  def bottomList(li: List[Int]): List[Int] = li match {
    case h1 :: h2 :: tail => (h1+h2) :: bottomList(h2 :: tail)
    case _ => Nil
  }

  for (li <- src) println(bottomMost(li))
}