using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    static class Solver
    {
        static IO io = new IO();

        public static void Solve()
        {
            io.ReadSplit();
            int H = io.Int();
            int W = io.Int();

            io.WriteLine(Math.Min(Ans(H, W), Ans(W, H)).ToString());
        }
        static int Ans(int H, int W)
        {
            List<int> ans = new List<int>();
            if (W % 3 == 0)
            {
                ans.Add(0);
            }
            else if (W % 3 == 1)
            {
                if (H % 2 == 0)
                {
                    ans.Add(H / 2);
                }
                else
                {
                    int h = (H - 1) / 2;
                    int w = (W - 1) / 3;
                    ans.Add(H);
                    ans.Add(Math.Max(w + h + 1, 2 * w + 1));
                    ans.Add(Math.Max(w + 2 * h + 1, 2 * w));
                }
            }
            else
            {
                if (H % 2 == 0)
                {
                    ans.Add(H / 2);
                }
                else
                {
                    int h = (H - 1) / 2;
                    int w = (W - 2) / 3;
                    ans.Add(H);
                    ans.Add(Math.Max(2 * w + 2, w + 2 * h + 2));
                    ans.Add(Math.Max(2 * w + 1, w + h + 1));
                    ans.Add(Math.Max(Math.Max(2 * w, w - 4 * h - 2), 4 * h + w + 2));
                }
            }
            return ans.Min();
        }
    }
}
namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            Solver.Solve();
        }
    }
    class IO
    {
        private string[] _Inputs;
        private int _Index;
        public void Read()
        {
            _Inputs = new string[1];
            _Inputs[0] = Console.ReadLine();
            _Index = 0;
        }
        public void ReadSplit()
        {
            _Inputs = Console.ReadLine().Split(' ');
            _Index = 0;
        }
        public string String()
        {
            return _Inputs[_Index++];
        }
        public string[] String(int xCount)
        {
            string[] rv = new string[xCount];
            Array.Copy(_Inputs, _Index, rv, 0, xCount);
            _Index += xCount;
            return rv;
        }
        public int Int()
        {
            return int.Parse(_Inputs[_Index++]);
        }
        public int[] Int(int xCount)
        {
            int[] rv = new int[xCount];
            for (int i = 0; i < xCount; ++i)
            {
                rv[i] = int.Parse(_Inputs[_Index++]);
            }
            return rv;
        }
        public long Long()
        {
            return long.Parse(_Inputs[_Index++]);
        }
        public long[] Long(int xCount)
        {
            long[] rv = new long[xCount];
            for (int i = 0; i < xCount; ++i)
            {
                rv[i] = long.Parse(_Inputs[_Index++]);
            }
            return rv;
        }
        public void Write(string xStr)
        {
            Console.Write(xStr);
        }
        public void WriteLine(string xStr)
        {
            Console.WriteLine(xStr);
        }
    }
}

Measured memory_bytes: 13268