import scala.io.StdIn._

object Main {
  def main(args: Array[String]): Unit = {
    while (true) {
      val sum = readInt
      if (sum == 0) return
      val result = sum - readIntList(9).sum
      println(result)
    }
  }
  def readIntList(n:Int) : List[Int] = {
    var list: Array[Int] = Array.empty
    for (i <- 0 until n) {
      list :+= readInt
    }
    list.toList
  }
}

