use std::{collections::{BinaryHeap, HashMap}, cmp::Reverse};

const INF: usize = 1usize << 60;

fn main() {
    let mut t = String::new();
    std::io::stdin().read_line(&mut t).ok();
    let t: isize = t.trim().parse().unwrap();
    let mut xa = String::new();
    std::io::stdin().read_line(&mut xa).ok();
    let xa: Vec<usize> = xa.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();
    let x = xa[0];
    let a = xa[1] as isize;
    let mut yb = String::new();
    std::io::stdin().read_line(&mut yb).ok();
    let yb: Vec<usize> = yb.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();
    let y = yb[0];
    let b = yb[1] as isize;

    let goal = t;
    let mut checked = HashMap::new();
    checked.insert(0isize, 0usize);
    let mut pque = BinaryHeap::new();
    pque.push((Reverse(0), 0isize));
    let get_cost = |p: isize, checked: &HashMap<isize, usize>| { *checked.get(&p).unwrap_or(&INF) };
    while let Some((Reverse(cost), pos)) = pque.pop() {
        if get_cost(goal, &checked) <= cost { break; }
        if get_cost(pos, &checked) < cost { continue; }
        let prev_cost = get_cost(pos+1, &checked);
        if pos+1 <= goal && prev_cost > cost + 1 {
            pque.push((Reverse(cost+1), pos+1));
            checked.insert(pos+1, cost+1);
        }
        if pos < goal && get_cost(pos+a, &checked) > cost + x {
            pque.push((Reverse(cost+x), pos+a));
            checked.insert(pos+a, cost+x);
        }
        if pos > goal && get_cost(pos-b, &checked) > cost + y {
            pque.push((Reverse(cost+y), pos-b));
            checked.insert(pos-b, cost+y);
        }
    }
    println!("{}", checked.get(&goal).unwrap());
}