#include <cstdio>
#include <algorithm>
#include <iostream>
using namespace std;

int main()
{
    int n, m, x, y, k;
    freopen("seabattle.in", "r", stdin);
    freopen("seabattle.out", "w", stdout);
    cin >> n >> m >> x >> y >> k;
    if (n > m)
        swap(n, m), swap(x, y);
    if (k == 1)
        cout << 0 << endl;
    else if (n < k)
    {
        if (m == k)
            cout << k - 1 << endl; //only one way to place boat
        else if (y == 1 || y == m)
            cout << k - 1 << endl; //----||----
        else
            cout << k << endl;
    } 
    else 
    {   
        if ((x == 1 || x == n) && (y == 1 || y == m))
            cout << k << endl;
        else if (x == 1 || x == n || y == 1 || y == m)
        {
            if (y == 1 || y == m)
                swap(n, m), swap(x, y);
            cout << k + (y >= k && (m - y + 1) >= k) << endl;
        }
        else
        {
            bool fx0 = n > k;
            bool fy0 = m > k;
            bool fx1 = n >= k;
            bool fy1 = m >= k;
            bool fx2 = x >= k;
            bool fy2 = y >= k;
            bool fx3 = (n - x + 1) >= k;        
            bool fy3 = (m - y + 1) >= k;
            cout << k - 1 + min(fx0 + fy1 + fy2 * fy3, fy0 + fx1 + fx2 * fx3) << endl;
        }
    }
    return 0;
}