#include <bits/stdc++.h>

using namespace std;

typedef long long int64;

int64 good(int64 a, int64 b, int64 c) {
    return a > 0 && b > 0 && (a > c / b || a == c / b && a * b >= c);
}

bool fits(int64 n, int64 a, int64 b, int64 w, int64 h, int64 d) {
    int64 ad = a + 2 * d;
    int64 bd = b + 2 * d;
    int64 ac = w / ad;
    int64 bc = h / bd;
    // ac * bc >= n?
    if (good(ac, bc, n)) {
        return true;
    } else {
        return false;
    }
}

int main() {
    freopen("space.in", "r", stdin);
    freopen("space.out", "w", stdout);

    int64 n, a, b, w, h;
    cin >> n >> a >> b >> w >> h;

    int64 ans = 0;
    for (int64 wn = 1; wn * wn <= n; wn++) {
        int64 ws = w / wn;
        int64 hn = (n + wn - 1) / wn;
        int64 hs = h / hn;
        if (ws >= a && hs >= b) {
            int64 d = min((ws - a) / 2, (hs - b) / 2);
            if (d > ans) {
                ans = d;
            }
        } 
        if (ws >= b && hs >= a) {
            int64 d = min((ws - b) / 2, (hs - a) / 2);
            if (d > ans) {
                ans = d;
            }
        } 
    }
    for (int64 wn = 1; wn * wn <= n; wn++) {
        int64 ws = h / wn;
        int64 hn = (n + wn - 1) / wn;
        int64 hs = w / hn;
        if (ws >= a && hs >= b) {
            int64 d = min((ws - a) / 2, (hs - b) / 2);
            if (d > ans) {
                ans = d;
            }
        } 
        if (ws >= b && hs >= a) {
            int64 d = min((ws - b) / 2, (hs - a) / 2);
            if (d > ans) {
                ans = d;
            }
        } 
    }
    cout << ans << endl;
    
    return 0;
}
