while true do
sougaku = gets.to_i
if sougaku == 0 then
break
end

hon1 = gets.to_i
sougaku = sougaku - hon1

hon2 = gets.to_i
sougaku = sougaku - hon2

hon3 = gets.to_i
sougaku = sougaku - hon3

hon4 = gets.to_i
sougaku = sougaku - hon4

hon5 = gets.to_i
sougaku = sougaku - hon5

hon6 = gets.to_i
sougaku = sougaku - hon6

hon7 = gets.to_i
sougaku = sougaku - hon7

hon8 = gets.to_i
sougaku = sougaku - hon8

hon9 = gets.to_i
sougaku = sougaku - hon9

puts(sougaku)
end