"use strict";
function Main(input) {
    let N = input.split("\n").map((v) => v - 0);
    let T = new Array(6).fill(0);
    let M = T[0] = N[0];
    N = N.slice(1, 6);
    let t = 0;
    while (T[5] < M) {
        for (let n = 4; n >= 0; n--) {
            if (T[n] < 1) continue;
            let r = (T[n] > N[n]) ? N[n] : T[n];
            T[n] -= r;
            T[n+1] += r;
        }
        t++;
    }
    console.log(t);
}
if (typeof window === 'undefined') Main(require("fs").readFileSync("/dev/stdin", "utf8"));
