#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long ints;
int main() {
	ints h, w;
	cin >> h >> w;
	if (!(h % 3) || !(w % 3))cout << "0\n";
	else {
		ints ans = min(h, w);
		for (ints i = 1; i < h; i++) {
			ints a = i*w, b = (h - i)*ceil((double)w / 2), c = (h - i)*(w / 2);
			ans = min(ans, max(a, max(b, c)) - min(min(a, b), c));
		}
		for (ints i = 1; i < w; i++) {
			ints a = i*h, b = (w - i)*ceil((double)h / 2), c = (w - i)*(h / 2);
			ans = min(ans, max(a, max(b, c)) - min(min(a, b), c));
		}
		cout << ans << endl;
	}
	return 0;
}