#include <cstdio>
#include <iostream>

using namespace std;

int main() {
 	freopen("seabattle.in", "r", stdin);
	freopen("seabattle.out", "w", stdout);
	         	
	int n, m, k, x, y;
	cin >> n >> m >> x >> y >> k;
	if (max(n, m) < k) {
	 	cout << -1 << endl;
		return 0;
	}
	if (k == 1) {
	 	cout << 0 << endl;
		return 0;
	}

	int missx1 = (n >= k) + (x >= k && x + k - 1 <= n);
	int missx2 = (n > k) * (x != 1 && x != n);

	int missy1 = (m >= k) + (y >= k && y + k - 1 <= m);
	int missy2 = (m > k) * (y != 1 && y != m);

	int ans = (k - 1) + min(missx1 + missy2, missy1 + missx2);

	cout << ans << endl;

	return 0;
}