# yukicoder No.149 碁石の移動 A_w, A_b = map(int, input().split()) B_w, B_b = map(int, input().split()) C, D = map(int, input().split()) ''' 最初の移動ではできるだけAの白石をBに持っていかずに 次の移動では、できるだけBの白石をAに持っていく、 という手法を取るとよい ''' A2B_w = max(0, C - A_b) B2A_w = min(D, B_w + A2B_w) print(A_w - A2B_w + B2A_w)