aw,ab=map(int,input().split()) bw,bn=map(int,input().split()) c,d=map(int,input().split()) if ab<=c: aw-=(c-ab) bw+=(c-ab) if d<=bw: aw+=d else: aw+=bw print(aw)