#include<iostream>
using namespace std;

int main(){
int books=1;
int book=0;
int i=0;
while(books!=0){
cin>>books;
if(books==0){
break;
}
while(i<=8){
cin>>book;
books-=book;
i++;
}
if(i==9){
cout<<books<<'\n';
i=0;
}

}


return 0;
}