import java.util.Scanner; public class No149 { public static void main(String[] args) { Scanner s = new Scanner(System.in); int aw = s.nextInt() , ab = s.nextInt() , bw = s.nextInt() , bb = s.nextInt() , c = s.nextInt() , d = s.nextInt(); s.close(); if(Math.min(ab, c) == ab){ aw -= c - ab; bw += c - ab; bb = ab; }else{ bb = c; } if(Math.min(bw, d) == bw){ aw += bw; }else{ aw += d; } System.out.println(aw); } }