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