#碁石の移動 Aw , Ab = map(int , input().split()) Bw , Bb = map(int , input().split()) C , D = map(int , input().split()) s = min(Ab , C) print(Aw - (C - s) + min(Bw + (C - s) , D))