## https://yukicoder.me/problems/no/149 def main(): Aw, Ab = map(int, input().split()) Bw, Bb = map(int, input().split()) C, D = map(int, input().split()) d = max(0, C - Ab) answer = Aw - d + (min(Bw + d, D)) print(answer) if __name__ == "__main__": main()