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

using namespace std;

typedef long long int ll;
typedef std::numeric_limits<double> dbl;
const long long int LL_INF=1LL<<60;

vector<string> split(const string& input, char delimiter)
{
    stringstream stream(input);
    
    string field;
    vector<string> result;
    while (getline(stream, field, delimiter)) {
        result.push_back(field);
    }
    return result;
}

//#define DEBUG

ll A, B, M, N, D, K, Q, W, H, T, X, Y;

int main()
{
    cin >> H >> W;

    if (H % 3 == 0 || W % 3 == 0)
        cout << 0 << endl;
    else {

        ll minimum = INT64_MAX;

        for (int h = 1; h < H; ++h) {
            ll restH = H - h;
            ll top = W * h;
            if (restH % 2 == 0) {
                ll rTop = restH / 2 * W;
                minimum = min(minimum, abs(top - rTop));
            } else {
                for (int i = 0; i < 2; ++i) {
                    ll rTop = (restH / 2 + i) * W;
                    ll rBottom = (H * W - top) - rTop;
                    minimum = min(minimum, max(top, max(rTop, rBottom)) -
                                            min(top, min(rTop, rBottom)));
                }
            }
            if (W % 2 == 0) {
                ll left = W / 2 * restH;
                minimum = min(minimum, abs(top - left));
            } else {
                for (int i = 0; i < 2; ++i) {
                    ll left = (W / 2 + i) * restH;
                    ll right = (H * W - top) - left;
                    //cout << top << " " << left << " " << right << endl;
                    minimum = min(minimum, max(top, max(left, right)) -                    
                                            min(top, min(left, right)));
                }
            }
        }

        swap(W, H);

        for (int h = 1; h < H; ++h) {
            ll restH = H - h;
            ll top = W * h;
            if (restH % 2 == 0) {
                ll rTop = restH / 2 * W;
                minimum = min(minimum, abs(top - rTop));
            } else {
                for (int i = 0; i < 2; ++i) {
                    ll rTop = (restH / 2 + i) * W;
                    ll rBottom = (H * W - top) - rTop;
                    minimum = min(minimum, max(top, max(rTop, rBottom)) -
                                            min(top, min(rTop, rBottom)));
                }
            }
            if (W % 2 == 0) {
                ll left = W / 2 * restH;
                minimum = min(minimum, abs(top - left));
            } else {
                for (int i = 0; i < 2; ++i) {
                    ll left = (W / 2 + i) * restH;
                    ll right = (H * W - top) - left;
                    //cout << top << " " << left << " " << right << endl;
                    minimum = min(minimum, max(top, max(left, right)) -                    
                                            min(top, min(left, right)));
                }
            }
        }

        cout << minimum << endl;

    }
    //cout << fixed << setprecision(10) << M_PI * (double)rad << endl;

    return 0;
}

Measured memory_bytes: 256