#include<bits/stdc++.h>
using namespace std;
#define int long long 
int32_t main(){
  int H,W;
  cin>>H>>W;
  if(H%3==0 || W%3==0) cout<<0;
  else{
    int ans=1000000000000;
  for(int i=1;i<=H;i++){
    int a1 = W*i;
    int a2 = (W/2)*(H-i);
    int a3 = H*W -a1-a2;
    ans=min(ans,max(a1,max(a2,a3))-min(a1,min(a2,a3)));
            }
            swap(H,W);
            for(int i=1;i<=H;i++){
    int a1 = W*i;
    int a2 = (W/2)*(H-i);
    int a3 = H*W -a1-a2;
    ans=min(ans,max(a1,max(a2,a3))-min(a1,min(a2,a3)));
            }
            cout<<min(ans,min(H,W));
  }
}
