#include<fstream>
#include<algorithm>
using namespace std;
ifstream f("bancomat.in");
ofstream g("bancomat.out");
int n,s,x,i,u,s1;
int main()
{
f>>s;
f>>n;
for(i=1;i<=n;i++)
{
f>>x;
u=x%10;
s1=x/10;
if(u==3)
{
if(s>=s1) s=s-s1;
}
else s=s+s1;
}
g<<s;
f.close();
g.close();
return 0;
}