use std::io::Read; fn main() { let mut s = String::new(); std::io::stdin().read_to_string(&mut s).ok(); let mut n: Vec = s.split_whitespace().flat_map(str::parse).collect(); let w = 0.max(n[4] - n[1]); n[0] -= w; n[2] += w; let w = n[2].min(n[5]); n[0] += w; println!("{}", n[0]); }