using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC062_ChocolateBar
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] input = Console.ReadLine().Split(' ').Select(elem => int.Parse(elem)).ToArray();
            int H = input[0];
            int W = input[1];

            Box boxParent = BoxFactory.CreateBox(H, W);
            long diff = long.MaxValue;

            for (int x = 1; x <= W - 1; x++)
            {
                Box[] children = boxParent.VerticalSplit(x);

                List<Box> boxList = new List<Box>();
                boxList.Add(children[0]);

                // children[1]に対して再度実施
                {
                    // 縦3つの分割
                    if (children[1].Width >= 2)
                    {
                        boxList.AddRange(children[1].VerticalSplit(children[1].Width / 2));
                        diff = Math.Min(diff, boxList.Max(elem => elem.Area) - boxList.Min(elem => elem.Area));
                        boxList.RemoveRange(1, 2);
                    }

                    // 縦、横の分割
                    if (children[1].Height >= 2)
                    {
                        boxList.AddRange(children[1].HorizonalSplit(children[1].Height / 2));
                        diff = Math.Min(diff, boxList.Max(elem => elem.Area) - boxList.Min(elem => elem.Area));
                        boxList.RemoveRange(1, 2);
                    }
                }
            }

            for (int y = 1; y < H - 1; y++)
            {
                Box[] children = boxParent.HorizonalSplit(y);

                List<Box> boxList = new List<Box>();
                boxList.Add(children[0]);

                // children[1]に対して再度実施
                {
                    // 横、縦の分割
                    if (children[1].Width >= 2)
                    {
                        boxList.AddRange(children[1].VerticalSplit(children[1].Width / 2));
                        diff = Math.Min(diff, boxList.Max(elem => elem.Area) - boxList.Min(elem => elem.Area));
                        boxList.RemoveRange(1, 2);
                    }

                    // 横3つの分割
                    if (children[1].Height >= 2)
                    {
                        boxList.AddRange(children[1].HorizonalSplit(children[1].Height / 2));
                        diff = Math.Min(diff, boxList.Max(elem => elem.Area) - boxList.Min(elem => elem.Area));
                        boxList.RemoveRange(1, 2);
                    }
                }
            }

            // 出力
            Console.WriteLine(diff.ToString());
        }
    }

    public static class BoxFactory
    {
        private static Dictionary<string, Box> cache = new Dictionary<string, Box>();

        public static Box CreateBox(int height, int width)
        {
            string key = height.ToString() + "," + width.ToString();
            if (cache.ContainsKey(key))
            {
                return cache[key];
            }
            else
            {
                Box box = new Box(height, width);
                cache.Add(key, box);
                return box;
            }
        }
    }

    public class Box
    {
        public Box(int height, int width)
        {
            this.Height = height;
            this.Width = width;
            this.Area = (long)height * (long)width;
        }

        public int Height { get; set; }
        public int Width { get; set; }
        public long Area { get; set; }

        public Box[] HorizonalSplit(int y)
        {
            Box[] ret = new Box[2];
            ret[0] = BoxFactory.CreateBox(y, this.Width);
            ret[1] = BoxFactory.CreateBox(this.Height - y, this.Width);

            return ret;
        }

        public Box[] VerticalSplit(int x)
        {
            Box[] ret = new Box[2];
            ret[0] = BoxFactory.CreateBox(this.Height, x);
            ret[1] = BoxFactory.CreateBox(this.Height, this.Width - x);

            return ret;
        }
    }
}


Measured memory_bytes: 66624