#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <queue>
#include <iomanip>

typedef char                SINT8;
typedef unsigned char       UINT8;
typedef short               SINT16;
typedef unsigned short      UINT16;
typedef int                 SINT32;
typedef unsigned int        UINT32;
typedef long long           SINT64;
typedef unsigned long long  UINT64;
typedef double              DOUBLE;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))
#define rep(i,a,b) for(int (i)=int(a);(i)<int(b);(i)++)
#define mrep(i,a,b) for(int (i)=int(a);(i)>=int(b);(i)--)

#define INF 1000000001
#define MOD 1000000007
#define INF64 1000000000000000001

#define F first
#define S second

#define Pii  pair<SINT32,SINT32>
#define Pll  pair<SINT64,SINT64>
#define Piii pair<SINT32,pair<SINT32,SINT32>>
#define Plll pair<SINT64,pair<SINT64,SINT64>>


using namespace std;

int main() {

	SINT64 N,M;
	cin >> N >> M;
	SINT64 ans = MAX(N,M);

	if ((N%3) == 0) {
		cout << 0 << endl;
		return 0;
	} else {
		ans = MIN(ans,M);
	}
	if ((M%3) == 0) {
		cout << 0 << endl;
		return 0;
	} else {
		ans = MIN(ans,N);
	}

	rep(i,1,N) {
		SINT64 buf1 = M*i;
		SINT64 buf2 = 0;
		SINT64 buf3 = 0;
		if ((M%2) == 0) {
			ans = MIN(ans,ABS(buf1- (N-i)*(M/2)));
		} else {
			buf2 = (N-i)*(M/2);
			buf3 = (N-i)*((M/2)+1);
			SINT64 ma,mi;
			mi = min(buf1,buf2);
			mi = min(mi,buf3);
			ma = max(buf1,buf2);
			ma = max(ma,buf3);
			ans = MIN(ans,ma-mi);
		}
	}
	SINT64 buf;
	buf = M;
	M = N;
	N = buf;

	rep(i,1,N) {
		SINT64 buf1 = M*i;
		SINT64 buf2 = 0;
		SINT64 buf3 = 0;
		if ((M%2) == 0) {
			ans = MIN(ans,ABS(buf1- (N-i)*(M/2)));
		} else {
			buf2 = (N-i)*(M/2);
			buf3 = (N-i)*((M/2)+1);
			SINT64 ma,mi;
			mi = min(buf1,buf2);
			mi = min(mi,buf3);
			ma = max(buf1,buf2);
			ma = max(ma,buf3);

			ans = MIN(ans,ma-mi);
		}
	}


	cout << ans << endl;
	return 0;
}

//	sort(data.begin(),data.end());
//	sort(data.begin(),data.end(),std::greater<SINT32>());
//	__gcd(A,B);

//	data.emplace_back(BUF);			//後ろに追加

//  data.erase(std::unique(data.begin(), data.end()), data.end());	//ソート後に使用 同じ値を消す

//	data.insert(data.begin() + X, 0);	//X番目の要素に0を挿入


//	vector<vector<SINT32>> data(N,vector<SINT32>(3));	//2次元配列

/*
	vector<Pii> data(N);
	rep(i,0,N) {
		cin >> data[i].F;
		cin >> data[i].S;
	}
	sort(data.begin(),data.end());
*/

/*
	vector<Piii> data(N);
	rep(i,0,N) {
		cin >> data[i].F;
		cin >> data[i].S.F;
		cin >> data[i].S.S;
	}
	sort(data.begin(),data.end());
*/


// posi = lower_bound(data.begin(),data.end(), X) - data.begin();				// X以上を探す
// posi = lower_bound(data.begin(),data.end(),make_pair(X,0)) - data.begin();	//pair


/* 文字列回転
	string N;
	cin >> N;
	N = N[N.length()-1] + N.substr(0,N.length()-1);
*/
/* 文字列合成
	string N,M;
	cin >> N >> M;
	SINT64 ans = 0;
	ans = stoi(N+M);
*/

/*
//ワーシャルフロイド
vector<vector<SINT32>> dist(N,vector<SINT32>(N));
rep(i,0,N) {
	rep(j,0,N) {
		if (i != j) {
			dist[i][j] = INF;
		}
	}
}
rep(k,0,N) {
	rep(i,0,N) {
		rep(j,0,N) {
			dist[i][j] = MIN(dist[i][j], dist[i][k]+dist[k][j]);
		}
	}
}
*/



/* SET コンテナ
	set<SINT32> DATA;
	for (SINT32 i = 0; i < N; i++) {
		SINT32 buf;
		cin >> buf;
		DATA.insert(buf);
	}

	//全表示
    set<string>::iterator it; //  イテレータを用意
    for(it = DATA.begin(); it != DATA.end(); it++) {
        cout << *it << endl;
    }

	//N番目を一部表示
	set<string>::iterator it; //  イテレータを用意
	it = DATA.begin();
	rep (i,0,N) {
		it++;
	}
	cout << *it << endl;
*/

/* map
	map<string,SINT32> mp;
	SINT32 N = 0;
	SINT32 mx = 0;

	cin >> N;
	for (SINT32 i = 0; i < N; i++) {
		string s;
		cin >> s;
		mp[s]++;
	}
	for(auto it=mp.begin();it!=mp.end();it++) {
		mx=max(mx,it->second);
	}
*/

/*
	//順列全表示
	//sortしてからでないと全列挙にならない
	sort(DATA.begin(),DATA.end());
	do {
		cout << buf << endl;
		rep(i,0,R) {
			cout << DATA[i] << " ";
		}
		cout << endl;

    } while (next_permutation(DATA.begin(),DATA.end()));
*/

//  桁指定表示
//  ans = ans * M_PI;
//	cout << setprecision(15) << ans << endl;

Measured memory_bytes: 256