#include <bits/stdc++.h>

int main() {
    freopen("seabattle.in", "r", stdin);
    freopen("seabattle.out", "w", stdout);
    int n, m, x, y, k;
    scanf("%d%d%d%d%d", &n, &m, &x, &y, &k);
    if (k > n || k > m) {
        y = (n > m ? x : y);
        n = std::max(n, m);
        int ans = k;
        if (k == n || y == 1 || y == n)
            ans = k - 1;
        printf("%d\n", ans);
        return 0;
    }
    if (k == 1) {   
        printf("0\n");
        return 0;
    }
    int ans = 1000;
    for (int it = 0; it < 2; it++) {
        int ansx = 2 - (x < k || n - x + 1 < k);
        int ansy = k;
        if (k == m || y == 1 || y == m)
            ansy = k - 1;
        ans = std::min(ans, ansx + ansy);
        std::swap(n, m);
        std::swap(x, y);
    }
    printf("%d\n", ans);
    return 0;
}
