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