// Original C++ solution (slower):
#include <iostream>

#include <string>

#include <algorithm>

#include <iomanip>

#include <vector>

#include <map>

#include <cmath>

#include <queue>

#include <utility>

#include <functional>

#include <deque>

#include <cctype>

#include <stack>

#include <bitset>



using ll = long long;

typedef unsigned long long ull;

typedef std::pair<ll, ll>P;



ll gcd(ll a, ll b) {

	if (b == 0) return a;

	return gcd(b, a%b);

}

ll lcm(ll a, ll b) {

	ll g = gcd(a, b);

	return a / g * b;

}



const ll mod = 1000000007;

const ll INF = 1 << 30;

const ll INF2 = 9000000000000000000LL;

bool fl = true;

int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };

std::string abc = "abcdefghijklmnopqrstuvwxyz";

struct edge { ll to, cost; };

struct edge1 { ll from, to, cost; };

double pai = 3.141592653589793;

std::vector<P>v[100010];



int main() {

	ll h, w, ans = INF2;

	std::cin >> h >> w;

	if (h % 3 == 0 || w % 3 == 0) {

		std::cout << 0 << std::endl;

		exit(0);

	}

	if (h == 2 && w == 2)ans = 1;

	for (int i = 1;i < w - 1;i++) {

		ll a, b, c, max = 0, min = INF;

		a = h*i;

		b = h*((w - i) / 2);

		c = h*(w - (i + (w - i) / 2));

		max = std::max(a, std::max(b, c));

		min = std::min(a, std::min(b, c));

		ans = std::min(max - min, ans);

	}

	for (int i = 1;i < w-1;i++) {

		ll a, b, c, max = 0, min = INF;

		a = h*i;

		b = (w-i)*(h / 2);

		c = (w-i)*(h - h / 2);

		max = std::max(a, std::max(b, c));

		min = std::min(a, std::min(b, c));

		ans = std::min(max - min, ans);

	}

	for (int i = 1;i < h-1;i++) {

		ll a, b, c, max = 0, min = INF;

		a = w*i;

		b = w*((h - i) / 2);

		c = w*(h - (i + (h - i) / 2));

		max = std::max(a, std::max(b, c));

		min = std::min(a, std::min(b, c));

		ans = std::min(max - min, ans);

	}

	for (int i = 1;i < h - 1;i++) {

		ll a, b, c, max = 0, min = INF;

		a = w*i;

		b = (h-i)*(w / 2);

		c = (h-i)*(w - w / 2);

		max = std::max(a, std::max(b, c));

		min = std::min(a, std::min(b, c));

		ans = std::min(max - min, ans);

	}

	std::cout << ans << std::endl;

}

// Optimized solution to the same problem (faster):
#include <iostream>

#include <algorithm>

#include <cmath>

#include <map>

#include <vector>

#include <queue>

#include <functional>

#include <string>

#include <stack>

#include <set>

#include <sstream>

#include <iomanip>

#include <limits>

#include <cstring>



using namespace std;

using ll = long long;

typedef unsigned long long ull;

typedef pair<ll, ll> P;

typedef pair<double, double >pd;

typedef pair<string, string> sP;

typedef pair<ll, P> PP;

typedef pair<P, P> PPP;



const ll MOD = 1e9 + 7;

const ll MOD2 = 998244353;

const ll INF = 1 << 30;

const ll INF2 = 9e18;

const double INF3 = 5e14;

const double eps = 1e-10;

const double PI = acos(-1);

const int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };

const int tx[8] = { -1,-1,-1,0,0,1,1,1 }, ty[8] = { -1,0,1,-1,1,-1,0,1 };



#define ALL(x) (x).begin(),(x).end()

#define ALLR(x) (x).rbegin(),(x).rend()

#define pb push_back

#define eb emplace_back

#define fr first

#define sc second



ll h, w, ans = INF2;



int main() {

	cin >> h >> w;

	if (h % 3 == 0 || w % 3 == 0) {

		cout << 0 << endl;

		return 0;

	}

	ans = min(h, w);

	for (int i = 1;i < h;i++) {

		ll tp = i * w, l = (h - i)*(w / 2), r = (h - i)*(w - w / 2);

		ans = min(ans, max({ tp,l,r })-min({ tp, l, r }));

	}

	for (int i = 1;i < w;i++) {

		ll tp = i * h, l = (w - i)*(h / 2), r = (w - i)*(h - h / 2);

		ans = min(ans, max({ tp,l,r }) - min({ tp, l, r }));

	}

	cout << ans << endl;

	return 0;

}

// Fastest known solution for this problem: