#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)
    {
        //only one direction for boat
        if (m < k)
            cout << "-1" << endl; //boat can't be placed on field
        else 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 (n == k)
    {
        if (m == k)
            cout << k << endl; //only two way to place boat
        else if (y == 1 || y == m)
            cout << k << endl; //----||----
        else
            cout << k + 1 << endl;
    }
    else
    {
        if (x > 1 && x < n && y > 1 && y < m)  
            cout << k + 2 << endl; // not near the border
        else if ((x > 1 && x < n) || (y > 1 && y < m)) 
            cout << k + 1 << endl; // near the border and not corner
        else 
            cout << k << endl; // corner
    }
    return 0;
}