I=input w,b=map(int,I().split()) W,B=map(int,I().split()) c,d=map(int,I().split()) e=c-min(b,c) w-=e W+=e print(w+min(W,d))