#include <bits/stdc++.h>

using namespace std;

int good(int a, int b, int c) {
    return 1LL * a * b >= c;
}

bool fits(int n, int a, int b, int w, int h, int d) {
    int ad = a + 2 * d;
    int bd = b + 2 * d;
    int ac = w / ad;
    int 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);

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

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