i;a[1<<17];main(t){for(;~scanf("%d",a+i)?++i:--i>1?t=t-(a[i]>=t)?:a[i]:0;);i=!printf("%d",t);}