Students in a class are making towers of blocks. Each student makes a (non-zero) tower by stacking pieces lengthwise on top of each other. n of the students use pieces made of two blocks and m of the students use pieces made of three blocks.The students don’t want to use too many blocks, but they also want to be unique, so no two students’ towers may contain the same number of blocks. Find the minimum height necessary for the tallest of the students' towers.

The first line of the input contains two space-separated integers n and m (0 ≤ n, m ≤ 1 000 000, n + m > 0) — the number of students using two-block pieces and the number of students using three-block pieces, respectively.

Print a single integer, denoting the minimum possible height of the tallest tower.

NoteIn the first case, the student using two-block pieces can make a tower of height 4, and the students using three-block pieces can make towers of height 3, 6, and 9 blocks. The tallest tower has a height of 9 blocks.In the second case, the students can make towers of heights 2, 4, and 8 with two-block pieces and towers of heights 3 and 6 with three-block pieces, for a maximum height of 8 blocks.

#if DEBUG
using System.Reflection;
using System.Threading.Tasks;
#endif

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace vc3
{
    class Program
    {
        static string _inputFilename = "input.txt";
        static string _outputFilename = "output.txt";
#if DEBUG
        static bool _useFileInput = false;
#else
        static bool _useFileInput = false;
#endif

        static void Main(string[] args)
        {
            StreamWriter file = null;
            if (_useFileInput)
            {
                Console.SetIn(File.OpenText(_inputFilename));
                file = new StreamWriter(_outputFilename);
                Console.SetOut(file);
            }

#if DEBUG
			if (!_useFileInput)
			{
				Console.SetIn(getInput());
			}
#endif

            try
            {
                solution();
            }
            finally
            {
                if (_useFileInput)
                {
                    file.Close();
                }
            }
        }

        static void solution()
        {
            #region SOLUTION
            var a = readIntArray();
            var n = a[0];
            var m = a[1];
            var h2 = 2;
            var h3 = 0;

            if (n == 0)
            {
                Console.WriteLine(3 * m);
                return;
            }

            if (m == 0)
            {
                Console.WriteLine(2 * n);
                return;
            }

            if (m >= n)
            {
                var rem = m - n;
                var h = (n / 2) * 6 + (n % 2) * 3 + rem * 3;
                Console.WriteLine(h);
                return;
            }
            else
            {

                var count = 0;
                while (true)
                {
                    if (n - 3 >= m - 1 && m > 0)
                    {
                        n -= 3;
                        m--;
                        count++;
                    }
                    else
                    {
                        break;
                    }
                }

                var rem = n - m;
                var h = count * 6 + (m / 2) * 6;
                h += Math.Max(m % 2 * 3, m % 2 * 2 + rem * 2);

                //var ct = rem / 2;
                //ct = Math.Min(ct, m);
                //var r = rem % 2;

                //var rc = n - ct * 3 - r;
                //var rcm = m - ct;
                //var mm = Math.Min(rcm, rc);

                //var h = (mm / 2) * 6 + ct * 6;// +(rc % 2) * 3 + ct * 6;
                //var add = Math.Max((mm % 2) * 3, r * 2 + (mm % 2) * 2);
                Console.WriteLine(h);
                return;
            }

            //while (true)
            //{
            //    if (m > 0)
            //    {
            //        if (h3 < h2 || n == 0)
            //        {
            //            while (h3 < h2 && m > 0)
            //            {
            //                h3 += 3;
            //                m--;
            //            }

            //            continue;
            //        }
            //    }

            //    if (n > 0)
            //    {
            //        if (h2 < h3 || m == 0)
            //        {
            //            while (h2 < h3 && n > 0)
            //            {
            //                h2 += 2;
            //                n--;
            //            }

            //            continue;
            //        }
            //    }

            //    if (h2 == h3)
            //    {
            //        var p2 = (n + 1) * 2;
            //        var p3 = (m + 1) * 3;

            //        if (p2 > p3)
            //        {

            //        }
            //    }
            //}

            //var n = readInt();
            //var m = readInt();

            //var a = readIntArray();
            //var b = readIntArray();
            #endregion
        }

        static int readInt()
        {
            return int.Parse(Console.ReadLine());
        }

        static long readLong()
        {
            return long.Parse(Console.ReadLine());
        }

        static int[] readIntArray()
        {
            return Console.ReadLine().Split(' ').Where(i => !string.IsNullOrEmpty(i)).Select(i => int.Parse(i)).ToArray();
        }

        static long[] readLongArray()
        {
            return Console.ReadLine().Split(' ').Where(i => !string.IsNullOrEmpty(i)).Select(i => long.Parse(i)).ToArray();
        }

#if DEBUG
		static StreamReader getInput()
		{
			var resName = Assembly.GetCallingAssembly().GetManifestResourceNames()[0];
			var resource = Assembly.GetCallingAssembly().GetManifestResourceStream(resName);

			return new StreamReader(resource);
		}
#endif
    }
}

using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;

namespace Codeforces
{
    class Program
    {
        static StreamReader reader;
        static StreamWriter writer;
        static Random rand = new Random(0);

        static void Main(string[] args)
        {
            //#if DEBUG
            reader = new StreamReader(Console.OpenStandardInput(32768), Encoding.ASCII, false, 32768);
            writer = new StreamWriter(Console.OpenStandardOutput(32768), Encoding.ASCII, 32768);
            //#else
            //            StreamReader streamReader = new StreamReader(Console.OpenStandardInput(32768), Encoding.ASCII, false, 32768);
            //            StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(32768), Encoding.ASCII, 32768);
            //#endif
            InputReader input = new InputReader(reader);

            int n = input.NextInt();
            int m = input.NextInt();
            SortedList<int, byte> sl2 = new SortedList<int, byte>();
            SortedList<int, byte> sl3 = new SortedList<int, byte>();
            for (int i = 1; i <= n; i++)
            {
                sl2.Add(i * 2, 0);
            }
            for (int j = 1; j <= m; j++)
            {
                sl3.Add(j * 3, 0);
            }
            for (int i = 0; i < sl2.Count; i++)
            {
                if (sl3.ContainsKey(sl2.Keys[i]))
                {
                    int ntwo = sl2.Keys[sl2.Count - 1] + 2;
                    int nthree = sl3.Keys[sl3.Count - 1] + 3;
                    if (ntwo < nthree)
                    {
                        sl2.Add(ntwo, 0);
                    }
                    else
                    {
                        sl3.Add(nthree, 0);
                    }
                }
            }
            int max = int.MinValue;
            if (sl2.Count > 0)
            {
                max = sl2.Keys[sl2.Count - 1];
            }
            if (sl3.Count > 0)
            {
                max = Math.Max(sl3.Keys[sl3.Count - 1], max);
            }
            writer.WriteLine(max);

#if DEBUG
                Console.BackgroundColor = ConsoleColor.White;
            Console.ForegroundColor = ConsoleColor.Black;
#endif
            writer.Flush();
            writer.Close();
            reader.Close();
        }

    }

    class LuckyNumber : IComparable<LuckyNumber>
    {
        public int four, seven;

        public LuckyNumber()
        {
            this.four = (int)1e7;
            this.seven = (int)1e7;
        }

        public LuckyNumber(int four, int seven)
        {
            this.four = four;
            this.seven = seven;
        }

        public int CompareTo(LuckyNumber other)
        {
            int digDif = this.four + this.seven - (other.four + other.seven);
            if (digDif != 0)
            {
                return digDif;
            }
            return other.four - this.four;
        }

        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < four; i++)
            {
                sb.Append('4');
            }
            for (int i = 0; i < seven; i++)
            {
                sb.Append('7');
            }
            return sb.ToString();
        }
    }

    class MyInt
    {
        public int data;

    }

    class MyPair
    {
        public int x, y;

        public MyPair(int x, int y)
        {
            this.x = x;
            this.y = y;
        }
    }

    // this class is copy
    class InputReader
    {
        private char[] _inbuf;
        private int _lenbuf = 0, _ptrbuf = 0;
        private StreamReader _reader;

        public InputReader(StreamReader reader)
        {
            _reader = reader;
            _inbuf = new char[1024];
            _lenbuf = 0;
            _ptrbuf = 0;
        }

        private int ReadByte()
        {
            if (_lenbuf == -1)
                throw new Exception();
            if (_ptrbuf >= _lenbuf)
            {
                _ptrbuf = 0;
                try
                {
                    _lenbuf = _reader.Read(_inbuf, 0, 1024);
                }
                catch (IOException e)
                {
                    throw e;
                }
                if (_lenbuf <= 0)
                    return -1;
            }
            return _inbuf[_ptrbuf++];
        }

        private bool IsSpaceChar(int c)
        {
            return !(c >= 33 && c <= 126);
        }

        private int Skip()
        {
            int b;
            while ((b = ReadByte()) != -1 && IsSpaceChar(b)) ;
            return b;
        }

        public int NextInt()
        {
            return int.Parse(this.Next());
        }

        public int[] NextIntArray(int n)
        {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
            {
                a[i] = NextInt();
            }
            return a;
        }

        public long NextLong()
        {
            return long.Parse(this.Next());
        }

        public string Next()
        {
            var b = Skip();
            var sb = new StringBuilder();
            while (!(IsSpaceChar(b)))
            {
                sb.Append((char)b);
                b = ReadByte();
            }
            return sb.ToString();
        }

        public double NextDouble()
        {
            return double.Parse(Next(), CultureInfo.InvariantCulture);
        }

        internal long[] NextLongArray(long n)
        {
            long[] a = new long[(int)n];
            for (int i = 0; i < a.Length; i++)
            {
                a[i] = NextLong();
            }
            return a;
        }

        internal double[] NextDoubleArray(int n)
        {
            double[] a = new double[n];
            for (int i = 0; i < a.Length; i++)
            {
                a[i] = NextDouble();
            }
            return a;
        }
    }
}

using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;

namespace Codeforces
{
    class Program
    {
        static StreamReader reader;
        static StreamWriter writer;
        static Random rand = new Random(0);

        static void Main(string[] args)
        {
            //#if DEBUG
            reader = new StreamReader(Console.OpenStandardInput(32768), Encoding.ASCII, false, 32768);
            writer = new StreamWriter(Console.OpenStandardOutput(32768), Encoding.ASCII, 32768);
            //#else
            //            StreamReader streamReader = new StreamReader(Console.OpenStandardInput(32768), Encoding.ASCII, false, 32768);
            //            StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(32768), Encoding.ASCII, 32768);
            //#endif
            InputReader input = new InputReader(reader);

            int n = input.NextInt();
            int m = input.NextInt();
            HashSet<int> set3 = new HashSet<int>();
            for (int j = 1, i = 3; j <= m; j++, i += 3)
            {
                set3.Add(i);
            }
            int max2 = n << 1;
            int max3 = m * 3;
            for (int idx = 1, tw = 2; idx <= n; idx++, tw += 2)
            {
                if (set3.Contains(tw))
                {
                    int ntwo = max2 + 2;
                    int nthree = max3 + 3;
                    if (ntwo < nthree)
                    {
                        n++;
                        max2 = ntwo;
                    }
                    else
                    {
                        set3.Add(nthree);
                        max3 = nthree;
                    }
                }
            }
            writer.WriteLine(Math.Max(max2, max3));

#if DEBUG
                Console.BackgroundColor = ConsoleColor.White;
            Console.ForegroundColor = ConsoleColor.Black;
#endif
            writer.Flush();
            writer.Close();
            reader.Close();
        }

    }

    class LuckyNumber : IComparable<LuckyNumber>
    {
        public int four, seven;

        public LuckyNumber()
        {
            this.four = (int)1e7;
            this.seven = (int)1e7;
        }

        public LuckyNumber(int four, int seven)
        {
            this.four = four;
            this.seven = seven;
        }

        public int CompareTo(LuckyNumber other)
        {
            int digDif = this.four + this.seven - (other.four + other.seven);
            if (digDif != 0)
            {
                return digDif;
            }
            return other.four - this.four;
        }

        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < four; i++)
            {
                sb.Append('4');
            }
            for (int i = 0; i < seven; i++)
            {
                sb.Append('7');
            }
            return sb.ToString();
        }
    }

    class MyInt
    {
        public int data;

    }

    class MyPair
    {
        public int x, y;

        public MyPair(int x, int y)
        {
            this.x = x;
            this.y = y;
        }
    }

    // this class is copy
    class InputReader
    {
        private char[] _inbuf;
        private int _lenbuf = 0, _ptrbuf = 0;
        private StreamReader _reader;

        public InputReader(StreamReader reader)
        {
            _reader = reader;
            _inbuf = new char[1024];
            _lenbuf = 0;
            _ptrbuf = 0;
        }

        private int ReadByte()
        {
            if (_lenbuf == -1)
                throw new Exception();
            if (_ptrbuf >= _lenbuf)
            {
                _ptrbuf = 0;
                try
                {
                    _lenbuf = _reader.Read(_inbuf, 0, 1024);
                }
                catch (IOException e)
                {
                    throw e;
                }
                if (_lenbuf <= 0)
                    return -1;
            }
            return _inbuf[_ptrbuf++];
        }

        private bool IsSpaceChar(int c)
        {
            return !(c >= 33 && c <= 126);
        }

        private int Skip()
        {
            int b;
            while ((b = ReadByte()) != -1 && IsSpaceChar(b)) ;
            return b;
        }

        public int NextInt()
        {
            return int.Parse(this.Next());
        }

        public int[] NextIntArray(int n)
        {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
            {
                a[i] = NextInt();
            }
            return a;
        }

        public long NextLong()
        {
            return long.Parse(this.Next());
        }

        public string Next()
        {
            var b = Skip();
            var sb = new StringBuilder();
            while (!(IsSpaceChar(b)))
            {
                sb.Append((char)b);
                b = ReadByte();
            }
            return sb.ToString();
        }

        public double NextDouble()
        {
            return double.Parse(Next(), CultureInfo.InvariantCulture);
        }

        internal long[] NextLongArray(long n)
        {
            long[] a = new long[(int)n];
            for (int i = 0; i < a.Length; i++)
            {
                a[i] = NextLong();
            }
            return a;
        }

        internal double[] NextDoubleArray(int n)
        {
            double[] a = new double[n];
            for (int i = 0; i < a.Length; i++)
            {
                a[i] = NextDouble();
            }
            return a;
        }
    }
}

using System;

class Program
{
    public static void Main(string[] args)
    {
        string s = Console.ReadLine();
        int n = Convert.ToInt32(s.Split(' ')[0]);
        int m = Convert.ToInt32(s.Split(' ')[1]);
        int x = 1;
        while(true)
        {
            if(n <= x / 2 && m <= x / 3 && n + m <= x / 2 + x / 3 - x / 6)
            {
                Console.WriteLine(x);
                goto exit;
            }
            x++;
        }
        exit:;
    }
}

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Globalization;

#if DEBUG
using System.Diagnostics;
#endif

namespace CompetitiveProgramming
{
    class Program
    {
        static bool s_IsMultipleTestCases = false;
        static void Main(string[] args)
        {
#if DEBUG
            var streamReader = new StreamReader("../../input.txt", Encoding.ASCII, false, 32768);
            var streamWriter = new StreamWriter("../../output.txt", false, Encoding.ASCII, 32768);
            var timer = new Stopwatch();
            timer.Start();
#else
            var streamReader = new StreamReader(Console.OpenStandardInput(32768), Encoding.ASCII, false, 32768);
            var streamWriter = new StreamWriter(Console.OpenStandardOutput(32768), Encoding.ASCII, 32768);
#endif
            var reader = new InputReader(streamReader);

            var numberOfTest = 1;
            if (s_IsMultipleTestCases)
            {
                numberOfTest = reader.NextInt();
            }
            for (var testNumber = 1; testNumber <= numberOfTest; ++testNumber)
            {
                Task solver = new Task();
                solver.Solve(testNumber, reader, streamWriter);
            }
#if DEBUG
            streamWriter.WriteLine("\nEslapsed Time: " + timer.ElapsedMilliseconds + " ms");
#endif
            streamReader.Close();
            streamWriter.Close();
        }
    }

    class Task
    {
        public void Solve(int testNumber, InputReader reader, StreamWriter writer)
        {
            var n = reader.NextInt();
            var m = reader.NextInt();

            int cnt2 = 0, cnt3 = 0, cnt6 = 0;
            for (int i = 1; ; i++)
            {
                if (i % 6 == 0)
                {
                    cnt6++;
                }
                else if (i % 2 == 0)
                {
                    cnt2++;
                }
                else if (i % 3 == 0)
                {
                    cnt3++;
                }
                if (cnt2 + cnt3 + cnt6 >= m + n && Math.Max(0, (n - cnt2)) + Math.Max(0, (m - cnt3)) <= cnt6)
                {
                    writer.WriteLine(i);
                    break;
                }
            }
        }
    }

    class InputReader
    {
        private char[] _inbuf;
        private int _lenbuf = 0, _ptrbuf = 0;
        private StreamReader _reader;

        public InputReader(StreamReader reader)
        {
            _reader = reader;
            _inbuf = new char[1024];
            _lenbuf = 0;
            _ptrbuf = 0;
        }

        private int ReadByte()
        {
            if (_lenbuf == -1)
                throw new Exception();
            if (_ptrbuf >= _lenbuf)
            {
                _ptrbuf = 0;
                try
                {
                    _lenbuf = _reader.Read(_inbuf, 0, 1024);
                }
                catch (IOException e)
                {
                    throw e;
                }
                if (_lenbuf <= 0)
                    return -1;
            }
            return _inbuf[_ptrbuf++];
        }

        private bool IsSpaceChar(int c)
        {
            return !(c >= 33 && c <= 126);
        }

        private int Skip()
        {
            int b;
            while ((b = ReadByte()) != -1 && IsSpaceChar(b)) ;
            return b;
        }

        public int NextInt()
        {
            int num = 0, b;
            var minus = false;
            while ((b = ReadByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
            if (b == '-')
            {
                minus = true;
                b = ReadByte();
            }

            while (true)
            {
                if (b >= '0' && b <= '9')
                {
                    num = num * 10 + (b - '0');
                }
                else
                {
                    return minus ? -num : num;
                }
                b = ReadByte();
            }
        }

        public long NextLong()
        {
            long num = 0, b;
            var minus = false;
            while ((b = ReadByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
            if (b == '-')
            {
                minus = true;
                b = ReadByte();
            }

            while (true)
            {
                if (b >= '0' && b <= '9')
                {
                    num = num * 10 + (b - '0');
                }
                else
                {
                    return minus ? -num : num;
                }
                b = ReadByte();
            }
        }

        public string Next()
        {
            var b = Skip();
            var sb = new StringBuilder();
            while (!(IsSpaceChar(b)))
            {
                sb.Append((char)b);
                b = ReadByte();
            }
            return sb.ToString();
        }

        public double NextDouble()
        {
            return double.Parse(Next(), CultureInfo.InvariantCulture);
        }
    }

}

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

namespace CFTraining._8VCVentureCup2016
{

    class FastScanner : StreamReader
    {
        private string[] _line;
        private int _iterator;

        public FastScanner(Stream stream) : base(stream)
        {
            _line = null;
            _iterator = 0;
        }
        public int NextInt()
        {
            if (_line == null || _iterator >= _line.Length)
            {
                _line = base.ReadLine().Split(' ');
                _iterator = 0;
            }
            if (_line.Count() == 0) throw new IndexOutOfRangeException("Input string is empty");
            return Convert.ToInt32(_line[_iterator++]);
        }
        public long NextLong()
        {
            if (_line == null || _iterator >= _line.Length)
            {
                _line = base.ReadLine().Split(' ');
                _iterator = 0;
            }
            if (_line.Count() == 0) throw new IndexOutOfRangeException("Input string is empty");
            return Convert.ToInt64(_line[_iterator++]);
        }
    }
    class BlockTowersC
    {
        public static void Main(string[] args)
        {
            using (FastScanner fs = new FastScanner(new BufferedStream(Console.OpenStandardInput())))
            using (StreamWriter writer = new StreamWriter(new BufferedStream(Console.OpenStandardOutput())))
            {
                int n = fs.NextInt(), m = fs.NextInt(), p2 = 2, p3 = 3;
                int[] a = new int[(int)1e7];
                for (int i = 1; i <= n; i++)
                {
                    a[p2]++;
                    p2 += 2;
                }
                for (int i = 1; i <= m; i++)
                {
                    a[p3]++;
                    p3 += 3;
                }
                while (a[p2] != 0) p2 += 2;
                while (a[p3] != 0) p3 += 3;
                for (int i = 1; i < a.Length; i++)
                {
                    if (a[i] == 2)
                    {
                        if (p2 <= p3)
                        {
                            a[p2]++;
                            while (a[p2] != 0) p2 += 2;
                        }
                        else
                        {
                            a[p3]++;
                            while (a[p3] != 0) p3 += 3;
                        }
                    }
                }
                writer.WriteLine(Math.Max(p2 - 2, p3 - 3));
            }
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace ConsoleApplication1
{
    class EVC3
    {
        static void Main(string[] args)
        {
            //Console.SetIn(new StreamReader(@"D:\Sergey\Code\1.txt"));

            string strT = Console.ReadLine();
            string[] strParams = strT.Split(new char[] { ' ' });
            ulong n = ulong.Parse(strParams[0]);
            ulong m = ulong.Parse(strParams[1]);

            int b = Math.Min((int)(m / 2), (int)(n / 3));

            while (b > 0)
            {
                if (n * 2 > m * 3)
                {
                    m++;
                    if (m % 2 == 0 && m * 3 < n * 2)
                        m++;
                    else if (m % 2 == 0 && m * 3 == n * 2)
                        n++;
                    b--;
                }
                else
                {
                    n++;
                    if (n % 3 == 0 && m * 3 >= n * 2)
                        n++;
                    b--;
                }
                if (n * 2 == m * 3)
                    n++;
            }

            ulong r = Math.Max(n * 2, m * 3);

            Console.WriteLine(r.ToString());
        }
    }
}

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

namespace ConsoleApplication2
{
    class Program
    {
        static int roundTo23(double val)
        {
            int cell = (int)Math.Ceiling(val);
            int floor = (int)Math.Floor(val);
            if (floor % 2 == 0 || floor % 3 == 0)
                return floor;
            else
                return cell;
        }

        static void Main(string[] args)
        {
            //while (true)
            //{
                string[] s = Console.ReadLine().Split(' ');
                //if (s[0] == "-1")
                //    return;
                int n = int.Parse(s[0]);
                int m = int.Parse(s[1]);

                int x = Math.Max(n * 2, Math.Max(m * 3, roundTo23(1.5 * (double)(n + m))));
                Console.WriteLine(x);
                //Console.ReadLine();
            //}
        }
    }
}

using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;

// (づ°ω°)づﾐe★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜
public class Solver
{
    public void Solve()
    {
        int n = ReadInt();
        int m = ReadInt();

        int l = 1, r = 10000000;
        while (l < r)
        {
            int mid = (l + r) / 2;
            int x6 = mid / 6;
            int x2 = mid / 2 - x6;
            int x3 = mid / 3 - x6;
            int xn = Math.Max(0, n - x2);
            int xm = Math.Max(0, m - x3);
            if (xn + xm > x6)
                l = mid + 1;
            else
                r = mid;
        }

        Write(l);
    }

    #region Main

    protected static TextReader reader;
    protected static TextWriter writer;
    static void Main()
    {
#if DEBUG
        reader = new StreamReader("..\\..\\input.txt");
        //reader = new StreamReader(Console.OpenStandardInput());
        writer = Console.Out;
        //writer = new StreamWriter("..\\..\\output.txt");
#else
        reader = new StreamReader(Console.OpenStandardInput());
        writer = new StreamWriter(Console.OpenStandardOutput());
        //reader = new StreamReader("input.txt");
        //writer = new StreamWriter("output.txt");
#endif
        try
        {
            //var thread = new Thread(new Solver().Solve, 1024 * 1024 * 128);
            //thread.Start();
            //thread.Join();
            new Solver().Solve();
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex);
#if DEBUG
#else
            throw;
#endif
        }
        reader.Close();
        writer.Close();
    }

    #endregion

    #region Read / Write
    private static Queue<string> currentLineTokens = new Queue<string>();
    private static string[] ReadAndSplitLine() { return reader.ReadLine().Split(new[] { ' ', '\t', }, StringSplitOptions.RemoveEmptyEntries); }
    public static string ReadToken() { while (currentLineTokens.Count == 0)currentLineTokens = new Queue<string>(ReadAndSplitLine()); return currentLineTokens.Dequeue(); }
    public static int ReadInt() { return int.Parse(ReadToken()); }
    public static long ReadLong() { return long.Parse(ReadToken()); }
    public static double ReadDouble() { return double.Parse(ReadToken(), CultureInfo.InvariantCulture); }
    public static int[] ReadIntArray() { return ReadAndSplitLine().Select(int.Parse).ToArray(); }
    public static long[] ReadLongArray() { return ReadAndSplitLine().Select(long.Parse).ToArray(); }
    public static double[] ReadDoubleArray() { return ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray(); }
    public static int[][] ReadIntMatrix(int numberOfRows) { int[][] matrix = new int[numberOfRows][]; for (int i = 0; i < numberOfRows; i++)matrix[i] = ReadIntArray(); return matrix; }
    public static int[][] ReadAndTransposeIntMatrix(int numberOfRows)
    {
        int[][] matrix = ReadIntMatrix(numberOfRows); int[][] ret = new int[matrix[0].Length][];
        for (int i = 0; i < ret.Length; i++) { ret[i] = new int[numberOfRows]; for (int j = 0; j < numberOfRows; j++)ret[i][j] = matrix[j][i]; } return ret;
    }
    public static string[] ReadLines(int quantity) { string[] lines = new string[quantity]; for (int i = 0; i < quantity; i++)lines[i] = reader.ReadLine().Trim(); return lines; }
    public static void WriteArray<T>(IEnumerable<T> array) { writer.WriteLine(string.Join(" ", array)); }
    public static void Write(params object[] array) { WriteArray(array); }
    public static void WriteLines<T>(IEnumerable<T> array) { foreach (var a in array)writer.WriteLine(a); }
    private class SDictionary<TKey, TValue> : Dictionary<TKey, TValue>
    {
        public new TValue this[TKey key]
        {
            get { return ContainsKey(key) ? base[key] : default(TValue); }
            set { base[key] = value; }
        }
    }
    private static T[] Init<T>(int size) where T : new() { var ret = new T[size]; for (int i = 0; i < size; i++)ret[i] = new T(); return ret; }
    #endregion
}

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

class PairVariable : IComparable<PairVariable>
{
    public int a, b;
    public PairVariable()
    {
        a = b = 0;
    }
    public PairVariable(string s)
    {
        string[] q = s.Split();
        a = int.Parse(q[0]);
        b = int.Parse(q[1]);
    }
    public PairVariable(int a, int b)
    {
        this.a = a;
        this.b = b;
    }

    public int CompareTo(PairVariable other)
    {
        return other.a.CompareTo(this.a);
    }
}

namespace ConsoleApplication254
{

    class Program
    {

        static void Main(string[] args)
        {
            string[] ss = Console.ReadLine().Split();
            int n = int.Parse(ss[0]);
            int m = int.Parse(ss[1]);
            int i = 0;
            for (i = 0; i / 2 < n || i / 3 < m || i / 2 + i / 3 - i / 6 < n + m; i++)
            {

            }
            Console.WriteLine(i);
        }
    }
}

using System;
using System.Linq;

namespace _626C
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var n = s[0]; var m = s[1];
            int i = 0;
            int j = 0;
            int[] tower = new int[10*1000*1000+3];
            int sumI = n * 2;
            int sumJ = m * 3;
            while (m > 0 && n > 0)
            {
                if (i + 2 < j + 3)
                {
                    i += 2;
                    if (tower[i] == 0) { n--; tower[i]++; }
                }
                else if (j + 3 < i + 2)
                {
                    j += 3;
                    if (tower[j] == 0) { m--; tower[j]++; }
                }

                else if ( j + 3 == i + 2)
                {
                    if (sumJ >= sumI && tower[j+3] == 0)
                    {
                        j += 3; m--; sumI += 2; tower[j]++;
                    }
                    else if (sumJ < sumI && tower[i+2] == 0)
                    { i += 2; n--; sumJ += 3; tower[i]++; }
                }
            }

            while (n>0)
            {
                i+=2;
                if (tower[i] == 0) { n--; tower[i]++; }
            }
            while (m>0)
            {
                j += 3;
                 if (tower[j] == 0) { m--; tower[j]++; }
            }

            Console.WriteLine(Math.Max(i,j));
        }
    }
}

using System;
using System.Linq;

namespace _626C
{
    class Program
    {
        static void Main()
        {
            var s = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var n = s[0]; var m = s[1];
            int sumI = n * 2;
            int sumJ = m * 3;

            for (int i = 6; i <= sumI && i <= sumJ; i+=6 )
            {
                if (sumI + 2 > sumJ + 3) sumJ += 3;
                else sumI += 2;
            }
                Console.WriteLine(Math.Max(sumI, sumJ));
        }
    }
}

using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Linq;

class Program
{
    public class Pair : IComparable<Pair>
    {
        public int L;
        public int R;
        public int Index;
        public bool Inverted;
        public Pair Next;

        public void Invert(int h)
        {
            this.Inverted = !this.Inverted;
            int tmp = L;
            L = h - R;
            R = h - tmp;
        }
        public void Sort(int h)
        {
            if (L <= R && L > h - R)
            {
                this.Invert(h);
            }

            if (L > R && L < h - R)
            {
                this.Invert(h);
            }
        }

        public int CompareTo(Pair other)
        {
            return (this.R - this.L) * this.L.CompareTo(other.L);
        }

        public override string ToString()
        {
            return L + " " + R;
        }
    }

    static void Main(string[] args)
    {
        int n = ReadInt();
        int m = ReadInt();
        int x = 0;
        for (int i = 2; ; i++)
        {
            if (i % 2 == 0) n--;
            if (i % 3 == 0) m--;

            if (i % 6 == 0) x++;
            while (m < 0 && x > 0)
            {
                m++;
                x--;
            }
            while (n < 0 && x > 0)
            {
                n++;
                x--;
            }

            if (m <= 0 && n <= 0 && x<=0)
            {
                Console.WriteLine(i);
                return;
            }
        }
        /*
        int h = ReadInt();
        int n = ReadInt();

        Pair[] m  = new Pair[n];
        Pair[] used = new Pair[h + 1];
        for (int i = 0; i < n; i++)
        {
            m[i] = new Pair()
            {
                L = ReadInt(),
                R = ReadInt(),
                Index = i + 1
            };
            m[i].Sort(h);

            if ((m[0].R - m[0].L != m[i].R - m[i].L) ||
                (m[0].R == m[0].L && m[i].L != m[0].L))
            {
                Console.WriteLine(0);
                return;
            }

            if (m[0].R != m[0].L)
            {
                if (used[m[i].L] == null)
                {
                    used[m[i].L] = m[i];
                }
                else
                {
                    m[i].Invert(h);
                    if (used[m[i].L].Next != null)
                    {
                        Console.WriteLine(0);
                        return;
                    }

                    used[m[i].L].Next = m[i];
                }
            }
        }

        int[] ans = new int[n];
        int start = m[0].L;
        if (m[0].L < m[0].R) start = m.Min(x => x.L);
        if (m[0].L > m[0].R) start = m.Max(x => x.L);

        int d = m[0].R - m[0].L;
        int xx = 0;
        while (true)
        {
            Pair c = null;
            if (used[start] != null)
            {
                c = used[start];
                used[start] = used[start].Next;
            }
            else
            {
                int pos = h - start;
                c = used[pos];
                if (c == null)
                {
                    break;
                }
                used[pos] = used[pos].Next;
                c.Invert(h);
            }

            ans[xx++] = (c.Inverted ? -1 : 1) * c.Index;
            start = c.R;
        }

        if (xx != n)
        {
            Console.WriteLine(0);
            return;
        }

        Console.WriteLine(string.Join(" ", ans));*/
    }

    private static List<int>[] ReadGraph(int n, int m)
    {
        List<int>[] g = new List<int>[n + 1];
        for (int i = 0; i <= n; i++) g[i] = new List<int>();
        for (int i = 0; i < m; i++)
        {
            int a = ReadInt();
            int b = ReadInt();
            g[a].Add(b);
            g[b].Add(a);
        }

        return g;
    }

    private static int[,] ReadGraphAsMatrix(int n, int m)
    {
        int[,] matrix = new int[n + 1, n + 1];
        for (int i = 0; i < m; i++)
        {
            int a = ReadInt();
            int b = ReadInt();
            matrix[a, b] = matrix[b, a] = 1;
        }

        return matrix;
    }

    private static void Sort(ref int a, ref int b)
    {
        if (a > b) Swap(ref a, ref b);
    }

    private static void Swap(ref int a, ref int b)
    {
        int tmp = a;
        a = b;
        b = tmp;
    }

    private const int BufferSize = 1 << 16;
    private static readonly StreamReader consoleReader = new StreamReader(Console.OpenStandardInput(BufferSize), Encoding.ASCII, false, BufferSize);

    private static int ReadInt()
    {
        int ans = 0;
        int mul = 1;
        do
        {
            ans = consoleReader.Read();
            if (ans == -1)
                return 0;
            if (ans == '-') mul = -1;
        } while (ans < '0' || ans > '9');

        ans -= '0';
        while (true)
        {
            int chr = consoleReader.Read();
            if (chr < '0' || chr > '9')
                return ans * mul;
            ans = ans * 10 + chr - '0';
        }
    }

    private static ulong ReadULong()
    {
        ulong ans = 0;
        int chr;
        do
        {
            chr = consoleReader.Read();
            if (chr == -1)
                return 0;
        } while (chr < '0' || chr > '9');

        ans = (uint)(chr - '0');
        while (true)
        {
            chr = consoleReader.Read();
            if (chr < '0' || chr > '9')
                return ans;
            ans = ans * 10 + (uint)(chr - '0');
        }
    }

    private static long ReadLong()
    {
        long ans = 0;
        int mul = 1;
        do
        {
            ans = consoleReader.Read();
            if (ans == -1)
                return 0;
            if (ans == '-') mul = -1;
        } while (ans < '0' || ans > '9');

        ans -= '0';
        while (true)
        {
            int chr = consoleReader.Read();
            if (chr < '0' || chr > '9')
                return ans * mul;
            ans = ans * 10 + chr - '0';
        }
    }

    private static int[] ReadIntArray(int n)
    {
        int[] ans = new int[n];
        for (int i = 0; i < n; i++)
            ans[i] = ReadInt();
        return ans;
    }

    private static long[] ReadLongArray(int n)
    {
        long[] ans = new long[n];
        for (int i = 0; i < n; i++)
            ans[i] = ReadLong();
        return ans;
    }

    private static char[] ReadString()
    {
        int ans;

        do
        {
            ans = consoleReader.Read();
        } while (ans < 'a' || ans > 'z');

        List<char> s = new List<char>();
        do
        {
            s.Add((char)ans);
            ans = consoleReader.Read();
        } while (ans >= 'a' && ans <= 'z');

        return s.ToArray();
    }

    private static char[] ReadString(int n)
    {
        int ans;

        do
        {
            ans = consoleReader.Read();
        } while (ans < 'a' || ans > 'z');

        char[] s = new char[n];
        int pos = 0;
        do
        {
            s[pos++] = (char)ans;
            ans = consoleReader.Read();
        } while (ans >= 'a' && ans <= 'z');

        return s;
    }

    private static char ReadLetter()
    {
        while (true)
        {
            int ans = consoleReader.Read();
            if ((ans >= 'a' && ans <= 'z') || (ans >= 'A' && ans <= 'Z'))
                return (char)ans;
        }
    }

    private static char ReadDigit()
    {
        while (true)
        {
            int ans = consoleReader.Read();
            if (ans >= '0' && ans <= '9')
                return (char)ans;
        }
    }

    private static int ReadDigitInt()
    {
        while (true)
        {
            return ReadDigit() - (int)'0';
        }
    }

    private static char ReadAnyChar()
    {
        return (char)consoleReader.Read();
    }
}

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

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){

		int r=3*(A+B+1);
		int l=0;
		int c=0;
		while(r-l>1){
			c=(r+l)/2;
			if(isOk(c)){
				r=c;
			}else{
				l=c;
			}
		}
		while(isOk(c))c--;
		while(!isOk(c))c++;
		Console.WriteLine(c);

	}

	bool isOk(int t){
		int n2=t/2;
		int n3=t/3;
		int n6=t/6;
		n2-=n6;
		n3-=n6;
		for(int i=0;i<=n6;i++){
			if(n2+i>=A && n3+(n6-i)>=B)return true;
		}
		return false;
	}

	int A,B;
	public Sol(){
		var d=ria();
		A=d[0];B=d[1];
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}

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

namespace BlockTowers
{
    class Program
    {
        static void Main(string[] args)
        {
            int n, m, a = 2;
            string[] input = Console.ReadLine().Split(' ');
            n = int.Parse(input[0]);
            m = int.Parse(input[1]);
            if (n == 0)
            {
                Console.WriteLine(m * 3);
            }
            else if (m == 0)
            {
                Console.WriteLine(n * 2);
            }
            else if (n != 0 && m != 0)
            {
                while (n != 0 || m != 0)
                {
                    if (a % 2 == 0 && a % 3 == 0)
                    {
                        if (n > m && n > 0)
                        {
                            n--;
                        }
                        else if (m > n && m > 0)
                        {
                            m--;
                        }
                        else if (n == m && m > 0)
                        {
                            m--;
                        }
                    }
                    else if (a % 2 == 0 && n > 0)
                    {
                        n--;
                    }
                    else if (a % 3 == 0 && m > 0)
                    {
                        m--;
                    }
                    a++;
                }
                Console.WriteLine(a - 1);
            }
        }
    }
}

using System;
using System.IO;
using System.Text;

namespace Block_Towers
{
    internal class Program
    {
        private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024*10), Encoding.ASCII, false, 1024*10);
        private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024*10), Encoding.ASCII, 1024*10);

        private static void Main(string[] args)
        {
            int n = Next();
            int m = Next();

            int l = 1, r = 5000000;
            while (l < r)
            {
                int mid = (l + r)/2;

                int d6 = mid/6;
                int d2 = mid/2 - d6;
                int d3 = mid/3 - d6;

                if (d6 >= (Math.Max(0, n - d2) + Math.Max(0, m - d3)))
                {
                    r = mid;
                }
                else
                {
                    l = mid + 1;
                }
            }

            writer.WriteLine(l);
            writer.Flush();
        }

        private static int Next()
        {
            int c;
            int res = 0;
            do
            {
                c = reader.Read();
                if (c == -1)
                    return res;
            } while (c < '0' || c > '9');
            res = c - '0';
            while (true)
            {
                c = reader.Read();
                if (c < '0' || c > '9')
                    return res;
                res *= 10;
                res += c - '0';
            }
        }
    }
}

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

namespace ConsoleApplication4
{
    class Program
    {
        static void Main(string[] args)
        {
            var numbers = Console.ReadLine().Split(new char[] { ' ' }).Select(x => int.Parse(x)).ToArray();
            if (numbers[0] == 0)
                Console.WriteLine(numbers[1] * 3);
            if (numbers[1] == 0)
                Console.WriteLine(numbers[0] * 2);
            if (numbers[0] != 0 && numbers[1] != 0)
            {
                var problemsCount = Math.Min((numbers[0] * 2) / 6, (numbers[1] * 3) / 6);
                var firstMaxHeight = numbers[0] * 2;
                var secondMaxHeight = numbers[1] * 3;
                while (problemsCount > 0)
                {
                    if (firstMaxHeight <= secondMaxHeight)
                    {
                        firstMaxHeight += 2;
                        if (firstMaxHeight % 6 == 0 && firstMaxHeight <= secondMaxHeight)
                            problemsCount++;
                    } else
                    if (firstMaxHeight > secondMaxHeight)
                    {
                        secondMaxHeight += 3;
                        if (secondMaxHeight % 6 == 0 && firstMaxHeight >= secondMaxHeight)
                            problemsCount++;
                    }
                    problemsCount--;
                }
                Console.WriteLine(Math.Max(firstMaxHeight, secondMaxHeight));
            }
        }
    }
}

using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Data;
using System.Numerics;

namespace ConsoleApplication1
{
    class Program : ProgramBase
    {
        private const long commonMod = 1000000007;
        private int index = 0;
        static void Main(string[] args)
        {
            var p = new Program();
            var x = p.Get();
            p.Out(x);
        }
        class Cut
        {
            public int a;
            public int b;
            public int line;
        }

        object Get() {
            checked
            {
                var a = ReadInts();
                var n = a[0];
                var m = a[1];
                var nh = a[0] * 2;
                var mh = a[1] * 3;
                var i = 6;
                while (i <= Math.Min(nh, mh))
                {
                    if (nh <= mh)
                        nh += 2;
                    else
                        mh += 3;
                    i += 6;
                }
                return Math.Max(mh, nh);
            }
        }

        public string Besides(char a)
        {
            if (a == 'B')
                return "GR";
            if (a == 'G')
                return "BR";
            if (a == 'R')
                return "BG";
            throw new Exception("huj");
        }

        public string Other(char a, char b)
        {
            if (a == 'B' && b == 'G')
                return "R";
            if (a == 'G' && b == 'R')
                return "B";
            if (a == 'B' && b == 'R')
                return "G";
            throw new Exception("huj");
        }
        object GetC()
        {
            FileName = "space";
            checked
            {
                var s = Read();
                var first = GetNext(s);
                var second = GetNext(s);
                var single = new Dictionary<char, int>();
                var twin = new Dictionary<Tuple<char, char>, List<Tuple<int, int>>>();
                single[first.Item1] = first.Item2;
                if (second == null)
                    return first.Item2;

                do
                {
                    if (!single.ContainsKey(second.Item1) || single[second.Item1] < second.Item2)
                        single[second.Item1] = second.Item2;
                    var pair = Tuple.Create(first.Item1, second.Item1);
                    if (!twin.ContainsKey(pair))
                        twin[pair] = new List<Tuple<int, int>>();
                    twin[pair].Add(Tuple.Create(first.Item2, second.Item2));
                    first = second;
                    second = GetNext(s);
                } while (second != null);
                long result = single.Select(x => x.Value).Sum();
                foreach (var kv in single)
                    result += kv.Value;
                //foreach (var kv in twin)
                //{
                //    ProcessPair(kv.Value);
                //}

                return result;

            }
        }

        //public long ProcessPair(List<Tuple<int, int>> counts)
        //{
        //    counts.Sort()
        //}

        public Tuple<char, int> GetNext(string s)
        {
            if (index == s.Length)
                return null;
            var ch = s[index];
            var count = 0;
            while (index < s.Length && ch == s[index])
            {
                count++;
                index++;
            }
            return Tuple.Create(ch, count);
        }

        public double ProcessPair(long[] a, long[] b, int p)
        {
            return ((double)NumberOfDivs(a, p) * 2000) / Count(a) +
                ((double)NumberOfDivs(b, p) * 2000) / Count(b) -
                ((double)(NumberOfDivs(a, p) * NumberOfDivs(b, p))) * 2000 / (Count(a) * Count(b));
        }

        public long NumberOfDivs(long[] a, int p)
        {
            return a[1] / p - (a[0] - 1) / p;
        }

        public long Count(long[] a)
        {
            return a[1] - a[0] + 1;
        }

        bool DoubleEquals(double a, double b)
        {
            return Math.Abs(a - b) < 0.0000000001;
        }

        bool SameLine(double[] a, double[] b, double[] c)
        {
            var x = a[0];
            var y = a[1];
            var x1 = b[0];
            var y1 = b[1];
            var x2 = c[0];
            var y2 = c[1];
            return DoubleEquals((x - x1) * (y2 - y1), (y - y1) * (x2 - x1));
        }

        double Distance(double[] a, double[] b)
        {
            return Math.Sqrt((a[0] - b[0]) * (a[0] - b[0]) + (a[1] - b[1]) * (a[1] - b[1]));
        }

        object Get2()
        {
            checked
            {
                var m = ReadInt();
                var p = ReadLongs();
                var arr = p.GroupBy(x => x).Select(g => new { g.Key, Count = g.Count() }).ToArray();
                var even = arr.Where(x => (x.Count & 1) == 0).FirstOrDefault();
                if (even != null)
                {
                    var index = Array.IndexOf(arr, even);
                    //arr[index].Count = arr[index].Count / 2;
                }
                long divs = 1;
                long result = 1;
                foreach (var a in arr)
                {
                    var pi = a.Key;
                    var curr = pi;
                    var olddivs = divs;
                    var oldres = result;
                    for (int i = 0; i < a.Count; i++)
                    {
                        result = (result * oldres % commonMod) * FastPow(curr, olddivs, commonMod) % commonMod;
                        curr = curr * pi % commonMod;
                        divs = (divs + olddivs) % (commonMod - 1);
                    }
                }
                return result;
            }
        }

        public long FastPow(long x, BigInteger pow, long mod)
        {
            if (pow == 0)
                return 1;
            if ((pow & 1) == 0)
                return FastPow(x * x % mod, pow / 2, mod);
            return x * FastPow(x, pow - 1, mod) % mod;
        }

        //object Get3()
        //{
        //    FileName = "";
        //    checked
        //    {
        //        var n = ReadInt();
        //        var hor = new List<Cut>();
        //        var ver = new List<Cut>();
        //        for (int i = 0; i < n; i++)
        //        {
        //            var a = ReadInts();
        //            if (a[0] == a[2])
        //                ver.Add(new Cut() { a = Math.Min(a[1], a[3]), b = Math.Max(a[1], a[3]), line = a[0] });
        //            else
        //                hor.Add(new Cut() { a = Math.Min(a[0], a[2]), b = Math.Max(a[0], a[2]), line = a[1] });
        //        }
        //        ver = Merge(ver);
        //        hor = Merge(hor);

        //    }
        //}

        List<Cut> Merge(List<Cut> l)
        {
            var a = l.OrderBy(x => x.line).ThenBy(x => x.a).ToArray();
            Cut previous = null;
            var result = new List<Cut>();
            for (int i = 0; i < a.Length; i++)
                if (previous == null)
                    previous = a[i];
                else
                    if (previous.line == a[i].line && previous.b >= a[i].a)
                        previous.b = Math.Max(previous.b, a[i].b);
                    else
                    {
                        result.Add(previous);
                        previous = a[i];
                    }
            if (previous != null)
                result.Add(previous);
            return result;
        }

    }
    abstract class ProgramBase
    {
        bool? prod = null;
        StreamReader f;
        protected string FileName { private get; set; }

        protected string Read()
        {
            if (string.IsNullOrEmpty(FileName))
                return Console.ReadLine();
            if (f == null)
                f = new StreamReader((GetProd() ? "" : "c:\\dev\\") + FileName + ".in");
            return f.ReadLine();
        }

        protected int ReadInt()
        {
            return Convert.ToInt32(Read());
        }
        protected int[] ReadInts()
        {
            return Read().Split(' ').Select(x => Convert.ToInt32(x)).ToArray();
        }

        protected long ReadLong()
        {
            return Convert.ToInt64(Read());
        }

        protected long[] ReadLongs()
        {
            return Read().Split(' ').Select(x => Convert.ToInt64(x)).ToArray();
        }

        public void Out(object r)
        {
            if (string.IsNullOrEmpty(FileName))
                Console.WriteLine(r);
            else if (GetProd())
                File.WriteAllText(FileName + ".out", r.ToString());
            else
                Console.WriteLine(r);
        }

        private bool GetProd()
        {
            if (!prod.HasValue)
                try
                {
                    prod = Environment.MachineName != "RENADEEN-NB-W7";
                }
                catch (Exception)
                {
                    prod = true;
                }
            return prod.Value;
        }
    }

    public static class Huj
    {
        public static T MinBy<T>(this IEnumerable<T> source, Func<T, double> func) where T : class
        {
            T result = null;
            var min = double.MaxValue;
            foreach (var item in source)
            {
                var current = func(item);
                if (min > current)
                {
                    min = current;
                    result = item;
                }
            }
            return result;
        }

        public static T MaxBy<T>(this IEnumerable<T> source, Func<T, double> func)
        {
            T result = default(T);
            var max = double.MinValue;
            foreach (var item in source)
            {
                var current = func(item);
                if (max < current)
                {
                    max = current;
                    result = item;
                }
            }
            return result;
        }

        public static string JoinStrings(this IEnumerable<string> source, string delimeter)
        {
            return string.Join(delimeter, source.ToArray());
        }
    }
}

using System;

class Program
{
    static void Main(string[] args)
    {
        var inp = Console.ReadLine().Split(' ');
        int n = int.Parse(inp[0]), tn = 0;
        int m = int.Parse(inp[1]), tm = 0;

        tm = m * 3;
        tn = n * 2;
        for (int i = 6; i <= tn && i <= tm; i += 6)
        {
            if (tn > tm)
                tm += 3;
            else
                tn += 2;
        }
        int max = Math.Max(tn, tm);

        Console.WriteLine(max);
        Console.ReadLine();
    }
}

#if DEBUG
using System.Reflection;
using System.Threading.Tasks;
#endif

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace vce3
{
    class Program
    {
        static string _inputFilename = "input.txt";
        static string _outputFilename = "output.txt";
#if DEBUG
        static bool _useFileInput = false;
#else
        static bool _useFileInput = false;
#endif

        static void Main(string[] args)
        {
            StreamWriter file = null;
            if (_useFileInput)
            {
                Console.SetIn(File.OpenText(_inputFilename));
                file = new StreamWriter(_outputFilename);
                Console.SetOut(file);
            }

#if DEBUG
			if (!_useFileInput)
			{
				Console.SetIn(getInput());
			}
#endif

            try
            {
                solution();
            }
            finally
            {
                if (_useFileInput)
                {
                    file.Close();
                }
            }
        }

        static void solution()
        {
            #region SOLUTION
            var d = readIntArray();
            var n = d[0];
            var m = d[1];
            var max2 = n * 2;
            var max3 = m * 3;

            var need = Math.Min(max2, max3) / 6;
            for (int i = 0; i < need; i++)
            {
                if (max2 == max3)
                {
                    max2 += 2;
                }
                else if (max2 > max3)
                {
                    max3 += 3;
                    //var n3 = max3 + 3;
                    if (max3 % 6 == 0 && max2 >= max3)
                    {
                        need++;
                    }
                }
                else
                {
                    max2 += 2;
                    if (max2 % 6 == 0 && max3 >= max2)
                    {
                        need++;
                    }
                }
            }

            var res = Math.Max(max2, max3);
            Console.WriteLine(res);

            //var n = readInt();
            //var m = readInt();

            //var a = readIntArray();
            //var b = readIntArray();
            #endregion
        }

        static int readInt()
        {
            return int.Parse(Console.ReadLine());
        }

        static long readLong()
        {
            return long.Parse(Console.ReadLine());
        }

        static int[] readIntArray()
        {
            return Console.ReadLine().Split(' ').Where(i => !string.IsNullOrEmpty(i)).Select(i => int.Parse(i)).ToArray();
        }

        static long[] readLongArray()
        {
            return Console.ReadLine().Split(' ').Where(i => !string.IsNullOrEmpty(i)).Select(i => long.Parse(i)).ToArray();
        }

#if DEBUG
		static StreamReader getInput()
		{
			var resName = Assembly.GetCallingAssembly().GetManifestResourceNames()[0];
			var resource = Assembly.GetCallingAssembly().GetManifestResourceStream(resName);

			return new StreamReader(resource);
		}
#endif
    }
}

#if DEBUG
using System.Reflection;
using System.Threading.Tasks;
#endif

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace vc3
{
    class Program
    {
        static string _inputFilename = "input.txt";
        static string _outputFilename = "output.txt";
#if DEBUG
        static bool _useFileInput = false;
#else
        static bool _useFileInput = false;
#endif

        static void Main(string[] args)
        {
            StreamWriter file = null;
            if (_useFileInput)
            {
                Console.SetIn(File.OpenText(_inputFilename));
                file = new StreamWriter(_outputFilename);
                Console.SetOut(file);
            }

#if DEBUG
			if (!_useFileInput)
			{
				Console.SetIn(getInput());
			}
#endif

            try
            {
                solution();
            }
            finally
            {
                if (_useFileInput)
                {
                    file.Close();
                }
            }
        }

        static void solution()
        {
            #region SOLUTION
            var a = readIntArray();
            var n = a[0];
            var m = a[1];
            var h2 = 2;
            var h3 = 0;

            if (n == 0)
            {
                Console.WriteLine(3 * m);
                return;
            }

            if (m == 0)
            {
                Console.WriteLine(2 * n);
                return;
            }

            if (m >= n)
            {
                var rem = m - n;
                var h = (n / 2) * 6 + (n % 2) * 3 + rem * 3;
                Console.WriteLine(h);
                return;
            }
            else
            {
                var rem = n - m;
                var ct = rem / 2;
                var r = rem % 2;

                var rc = n - ct * 3;
                var h = (rc / 2) * 6 + (rc % 2) * 2 + ct * 6;
                Console.WriteLine(h);
                return;
            }

            //while (true)
            //{
            //    if (m > 0)
            //    {
            //        if (h3 < h2 || n == 0)
            //        {
            //            while (h3 < h2 && m > 0)
            //            {
            //                h3 += 3;
            //                m--;
            //            }

            //            continue;
            //        }
            //    }

            //    if (n > 0)
            //    {
            //        if (h2 < h3 || m == 0)
            //        {
            //            while (h2 < h3 && n > 0)
            //            {
            //                h2 += 2;
            //                n--;
            //            }

            //            continue;
            //        }
            //    }

            //    if (h2 == h3)
            //    {
            //        var p2 = (n + 1) * 2;
            //        var p3 = (m + 1) * 3;

            //        if (p2 > p3)
            //        {

            //        }
            //    }
            //}

            //var n = readInt();
            //var m = readInt();

            //var a = readIntArray();
            //var b = readIntArray();
            #endregion
        }

        static int readInt()
        {
            return int.Parse(Console.ReadLine());
        }

        static long readLong()
        {
            return long.Parse(Console.ReadLine());
        }

        static int[] readIntArray()
        {
            return Console.ReadLine().Split(' ').Where(i => !string.IsNullOrEmpty(i)).Select(i => int.Parse(i)).ToArray();
        }

        static long[] readLongArray()
        {
            return Console.ReadLine().Split(' ').Where(i => !string.IsNullOrEmpty(i)).Select(i => long.Parse(i)).ToArray();
        }

#if DEBUG
		static StreamReader getInput()
		{
			var resName = Assembly.GetCallingAssembly().GetManifestResourceNames()[0];
			var resource = Assembly.GetCallingAssembly().GetManifestResourceStream(resName);

			return new StreamReader(resource);
		}
#endif
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace ConsoleApplication1
{
    class EVC3
    {
        static void Main(string[] args)
        {
            //Console.SetIn(new StreamReader(@"D:\Sergey\Code\1.txt"));

            string strT = Console.ReadLine();
            string[] strParams = strT.Split(new char[] { ' ' });
            ulong n = ulong.Parse(strParams[0]);
            ulong m = ulong.Parse(strParams[1]);

            int b = Math.Min((int)(m / 2), (int)(n / 3));

            while (b > 0)
            {
                if (n * 2 > m * 3)
                {
                    m++;
                    b--;
                }
                else
                {
                    n++;
                    b--;
                }
                if (n * 2 == m * 3)
                    n++;
            }

            ulong r = Math.Max(n * 2, m * 3);

            Console.WriteLine(r.ToString());
        }
    }
}

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

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');
            int n = int.Parse(s[0]);
            int m = int.Parse(s[1]);

            int x = Math.Max(n * 2, Math.Max(m * 3, (int)Math.Ceiling(1.5 * (double)(n + m))));
            Console.WriteLine(x);
            Console.ReadLine();
        }
    }
}

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

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');
            int n = int.Parse(s[0]);
            int m = int.Parse(s[1]);

            int x = Math.Max(n * 2, Math.Max(m * 3, (int)Math.Floor(1.5 * (double)(n + m))));
            Console.WriteLine(x);
            Console.ReadLine();
        }
    }
}

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

class PairVariable : IComparable<PairVariable>
{
    public int a, b;
    public PairVariable()
    {
        a = b = 0;
    }
    public PairVariable(string s)
    {
        string[] q = s.Split();
        a = int.Parse(q[0]);
        b = int.Parse(q[1]);
    }
    public PairVariable(int a, int b)
    {
        this.a = a;
        this.b = b;
    }

    public int CompareTo(PairVariable other)
    {
        return other.a.CompareTo(this.a);
    }
}

namespace ConsoleApplication254
{

    class Program
    {

        static void Main(string[] args)
        {
            string[] ss = Console.ReadLine().Split();
            int n = int.Parse(ss[0]);
            int m = int.Parse(ss[1]);
            long x = (long)n * 2;
            long y = (long)m * 3;
            if (x > y)
            {
                Console.WriteLine(x);
            }
            else if (y > x)
            {
                Console.WriteLine(y);
            }
            else
            {
                Console.WriteLine(x+2);
            }

        }
    }
}

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

class PairVariable : IComparable<PairVariable>
{
    public int a, b;
    public PairVariable()
    {
        a = b = 0;
    }
    public PairVariable(string s)
    {
        string[] q = s.Split();
        a = int.Parse(q[0]);
        b = int.Parse(q[1]);
    }
    public PairVariable(int a, int b)
    {
        this.a = a;
        this.b = b;
    }

    public int CompareTo(PairVariable other)
    {
        return other.a.CompareTo(this.a);
    }
}

namespace ConsoleApplication254
{

    class Program
    {

        static void Main(string[] args)
        {
            string[] ss = Console.ReadLine().Split();
            int n = int.Parse(ss[0]);
            int m = int.Parse(ss[1]);
            List<int> l = new List<int>();
            bool f = false;
            for (int i = 1; i <= n; i++)
            {
                if (i * 2 <= m * 3 && (i * 2) % 3 == 0)
                {
                    f = true;
                    l.Add(i * 2);
                }
            }
            if (f)
            {
                int max1 = 0;
                int max2 = 0;
                l.Sort();
                int[] l2 = new int[l.Count];
                for (int i = 0; i < l.Count; i++)
                {
                    l2[i] = (l[i]);
                }
                l[0] = n * 2 + 2;
                for (int i = 1; i < l.Count; i++)
                {
                    l[i] = l[i - 1] + 2;
                }
                l2[0] = m * 3 + 3;
                for (int i = 1; i < l2.Length; i++)
                {
                    l2[i] = l2[i - 1] + 2;
                }
                Console.WriteLine(Math.Min(l.Max(), l2.Max()));

            }
            else
            {
                long x = (long)n * 2;
                long y = (long)m * 3;
                if (x > y)
                {
                    Console.WriteLine(x);
                }
                else if (y > x)
                {
                    Console.WriteLine(y);
                }
                else
                {
                    Console.WriteLine(x + 2);
                }
            }
        }
    }
}

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

class PairVariable : IComparable<PairVariable>
{
    public int a, b;
    public PairVariable()
    {
        a = b = 0;
    }
    public PairVariable(string s)
    {
        string[] q = s.Split();
        a = int.Parse(q[0]);
        b = int.Parse(q[1]);
    }
    public PairVariable(int a, int b)
    {
        this.a = a;
        this.b = b;
    }

    public int CompareTo(PairVariable other)
    {
        return other.a.CompareTo(this.a);
    }
}

namespace ConsoleApplication254
{

    class Program
    {

        static void Main(string[] args)
        {
            string[] ss = Console.ReadLine().Split();
            int n = int.Parse(ss[0]);
            int m = int.Parse(ss[1]);
            List<int> l = new List<int>();
            bool f = false;
            for (int i = 1; i <= n; i++)
            {
                if (i * 2 <= m * 3 && (i * 2) % 3 == 0)
                {
                    f = true;
                    l.Add(i * 2);
                }
            }
            if (f)
            {
                l.Sort();
                l[0] = l.Max() + 2;
                for (int i = 1; i < l.Count; i++)
                {
                    l[i] = l[i - 1] + 2;
                }

                //Console.WriteLine();
                Console.WriteLine(l.Max());
            }
            else
            {
                long x = (long)n * 2;
                long y = (long)m * 3;
                if (x > y)
                {
                    Console.WriteLine(x);
                }
                else if (y > x)
                {
                    Console.WriteLine(y);
                }
                else
                {
                    Console.WriteLine(x + 2);
                }
            }
        }
    }
}

using System;
using System.Linq;

namespace _626C
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var n = s[0]; var m = s[1];
            int i = 0;
            int j = 0;
            int[] tower = new int[3*1000*1000+3];
            while (m > 0)
            {
                j += 3; m--; tower[j]++;
            }
            while (n > 0)
            {
                i += 2;
                if (tower[i] == 0)
                {
                    n--; tower[i]++;
                }
            }
            Console.WriteLine(Math.Max(i,j));
        }
    }
}

using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Linq;

class Program
{
    public class Pair : IComparable<Pair>
    {
        public int L;
        public int R;
        public int Index;
        public bool Inverted;
        public Pair Next;

        public void Invert(int h)
        {
            this.Inverted = !this.Inverted;
            int tmp = L;
            L = h - R;
            R = h - tmp;
        }
        public void Sort(int h)
        {
            if (L <= R && L > h - R)
            {
                this.Invert(h);
            }

            if (L > R && L < h - R)
            {
                this.Invert(h);
            }
        }

        public int CompareTo(Pair other)
        {
            return (this.R - this.L) * this.L.CompareTo(other.L);
        }

        public override string ToString()
        {
            return L + " " + R;
        }
    }

    static void Main(string[] args)
    {
        int n = ReadInt();
        int m = ReadInt();
        int x = 0;
        for (int i = 2; i < 5555; i++)
        {
            if (i % 2 == 0) n--;
            if (i % 3 == 0) m--;

            if (i % 6 == 0) x++;
            while (m < 0 && x > 0)
            {
                m++;
                x--;
            }
            while (n < 0 && x > 0)
            {
                n++;
                x--;
            }

            if (m <= 0 && n <= 0 && x<=0)
            {
                Console.WriteLine(i);
                return;
            }
        }
        /*
        int h = ReadInt();
        int n = ReadInt();

        Pair[] m  = new Pair[n];
        Pair[] used = new Pair[h + 1];
        for (int i = 0; i < n; i++)
        {
            m[i] = new Pair()
            {
                L = ReadInt(),
                R = ReadInt(),
                Index = i + 1
            };
            m[i].Sort(h);

            if ((m[0].R - m[0].L != m[i].R - m[i].L) ||
                (m[0].R == m[0].L && m[i].L != m[0].L))
            {
                Console.WriteLine(0);
                return;
            }

            if (m[0].R != m[0].L)
            {
                if (used[m[i].L] == null)
                {
                    used[m[i].L] = m[i];
                }
                else
                {
                    m[i].Invert(h);
                    if (used[m[i].L].Next != null)
                    {
                        Console.WriteLine(0);
                        return;
                    }

                    used[m[i].L].Next = m[i];
                }
            }
        }

        int[] ans = new int[n];
        int start = m[0].L;
        if (m[0].L < m[0].R) start = m.Min(x => x.L);
        if (m[0].L > m[0].R) start = m.Max(x => x.L);

        int d = m[0].R - m[0].L;
        int xx = 0;
        while (true)
        {
            Pair c = null;
            if (used[start] != null)
            {
                c = used[start];
                used[start] = used[start].Next;
            }
            else
            {
                int pos = h - start;
                c = used[pos];
                if (c == null)
                {
                    break;
                }
                used[pos] = used[pos].Next;
                c.Invert(h);
            }

            ans[xx++] = (c.Inverted ? -1 : 1) * c.Index;
            start = c.R;
        }

        if (xx != n)
        {
            Console.WriteLine(0);
            return;
        }

        Console.WriteLine(string.Join(" ", ans));*/
    }

    private static List<int>[] ReadGraph(int n, int m)
    {
        List<int>[] g = new List<int>[n + 1];
        for (int i = 0; i <= n; i++) g[i] = new List<int>();
        for (int i = 0; i < m; i++)
        {
            int a = ReadInt();
            int b = ReadInt();
            g[a].Add(b);
            g[b].Add(a);
        }

        return g;
    }

    private static int[,] ReadGraphAsMatrix(int n, int m)
    {
        int[,] matrix = new int[n + 1, n + 1];
        for (int i = 0; i < m; i++)
        {
            int a = ReadInt();
            int b = ReadInt();
            matrix[a, b] = matrix[b, a] = 1;
        }

        return matrix;
    }

    private static void Sort(ref int a, ref int b)
    {
        if (a > b) Swap(ref a, ref b);
    }

    private static void Swap(ref int a, ref int b)
    {
        int tmp = a;
        a = b;
        b = tmp;
    }

    private const int BufferSize = 1 << 16;
    private static readonly StreamReader consoleReader = new StreamReader(Console.OpenStandardInput(BufferSize), Encoding.ASCII, false, BufferSize);

    private static int ReadInt()
    {
        int ans = 0;
        int mul = 1;
        do
        {
            ans = consoleReader.Read();
            if (ans == -1)
                return 0;
            if (ans == '-') mul = -1;
        } while (ans < '0' || ans > '9');

        ans -= '0';
        while (true)
        {
            int chr = consoleReader.Read();
            if (chr < '0' || chr > '9')
                return ans * mul;
            ans = ans * 10 + chr - '0';
        }
    }

    private static ulong ReadULong()
    {
        ulong ans = 0;
        int chr;
        do
        {
            chr = consoleReader.Read();
            if (chr == -1)
                return 0;
        } while (chr < '0' || chr > '9');

        ans = (uint)(chr - '0');
        while (true)
        {
            chr = consoleReader.Read();
            if (chr < '0' || chr > '9')
                return ans;
            ans = ans * 10 + (uint)(chr - '0');
        }
    }

    private static long ReadLong()
    {
        long ans = 0;
        int mul = 1;
        do
        {
            ans = consoleReader.Read();
            if (ans == -1)
                return 0;
            if (ans == '-') mul = -1;
        } while (ans < '0' || ans > '9');

        ans -= '0';
        while (true)
        {
            int chr = consoleReader.Read();
            if (chr < '0' || chr > '9')
                return ans * mul;
            ans = ans * 10 + chr - '0';
        }
    }

    private static int[] ReadIntArray(int n)
    {
        int[] ans = new int[n];
        for (int i = 0; i < n; i++)
            ans[i] = ReadInt();
        return ans;
    }

    private static long[] ReadLongArray(int n)
    {
        long[] ans = new long[n];
        for (int i = 0; i < n; i++)
            ans[i] = ReadLong();
        return ans;
    }

    private static char[] ReadString()
    {
        int ans;

        do
        {
            ans = consoleReader.Read();
        } while (ans < 'a' || ans > 'z');

        List<char> s = new List<char>();
        do
        {
            s.Add((char)ans);
            ans = consoleReader.Read();
        } while (ans >= 'a' && ans <= 'z');

        return s.ToArray();
    }

    private static char[] ReadString(int n)
    {
        int ans;

        do
        {
            ans = consoleReader.Read();
        } while (ans < 'a' || ans > 'z');

        char[] s = new char[n];
        int pos = 0;
        do
        {
            s[pos++] = (char)ans;
            ans = consoleReader.Read();
        } while (ans >= 'a' && ans <= 'z');

        return s;
    }

    private static char ReadLetter()
    {
        while (true)
        {
            int ans = consoleReader.Read();
            if ((ans >= 'a' && ans <= 'z') || (ans >= 'A' && ans <= 'Z'))
                return (char)ans;
        }
    }

    private static char ReadDigit()
    {
        while (true)
        {
            int ans = consoleReader.Read();
            if (ans >= '0' && ans <= '9')
                return (char)ans;
        }
    }

    private static int ReadDigitInt()
    {
        while (true)
        {
            return ReadDigit() - (int)'0';
        }
    }

    private static char ReadAnyChar()
    {
        return (char)consoleReader.Read();
    }
}

using System;

class Program
{
    static void Main(string[] args)
    {
        var inp = Console.ReadLine().Split(' ');
        int n = int.Parse(inp[0]), tn = 0;
        int m = int.Parse(inp[1]), tm = 0;

        tm = m * 3;
        tn = n * 2;
        for (int i = 0; i < n && i < m; i += 3)
        {
            if (tn >= tm + 3)
                tm += 3;
            else
                tn += 2;
        }
        int max = Math.Max(tn, tm);

        Console.WriteLine(max);
        Console.ReadLine();
    }
}

using System;

class Program
{
    static void Main(string[] args)
    {
        var inp = Console.ReadLine().Split(' ');
        int n = int.Parse(inp[0]), tn1 = 0, tn2 = 0;
        int m = int.Parse(inp[1]), tm1 = 0, tm2 = 0;

        for (int i = 0; i < n; i++)
        {
            //tn1 += 2;
            tn2 += 2;
            if (tn2 % 3 == 0 && m * 3 >= tn2)
                tn2 += 2;
        }
        tm2 = m * 3;
        int max = -1;
        //max = (tn1 < max) ? tn1 : max;
        max = (tn2 > max) ? tn2 : max;
        //max = (tm1 < max) ? tm1 : max;
        max = (tm2 > max) ? tm2 : max;

        Console.WriteLine(max);
        Console.ReadLine();
    }
}

using System;

class Program
{
    static void Main(string[] args)
    {
        var inp = Console.ReadLine().Split(' ');
        int n = int.Parse(inp[0]), tn = 0;
        int m = int.Parse(inp[1]), tm = 0;

        tm = m * 3;
        tn = n * 2;
        for (int i = 0; i < n && i < m; i += 6)
        {
            if (tn >= tm + 3)
                tm += 3;
            else
                tn += 2;
        }
        int max = Math.Max(tn, tm);

        Console.WriteLine(max);
        Console.ReadLine();
    }
}

using System;

class Program
{
    static void Main(string[] args)
    {
        var inp = Console.ReadLine().Split(' ');
        int n = int.Parse(inp[0]), tn = 0;
        int m = int.Parse(inp[1]), tm = 0;

        tm = m * 3;
        tn = n * 2;
        for (int i = 6; i <= tn && i <= tm; i += 6)
        {
            if (tn >= tm + 3)
                tm += 3;
            else
                tn += 2;
        }
        int max = Math.Max(tn, tm);

        Console.WriteLine(max);
        Console.ReadLine();
    }
}

using System;

class Program
{
    static void Main(string[] args)
    {
        var inp = Console.ReadLine().Split(' ');
        int n = int.Parse(inp[0]), tn1 = 0, tn2 = 0;
        int m = int.Parse(inp[1]), tm1 = 0, tm2 = 0;

        for (int i = 0; i < n; i++)
        {
            //tn1 += 2;
            tn2 += 2;
            if (tn2 % 3 == 0 && m * 3 >= tn2)
                tn2 += 2;
        }
        for (int i = 0; i < m; i++)
        {
            //tm1 += 3;
            tm2 += 3;
            //if (tm2 % 2 == 0 && n * 2 >= tm2)
                //tm2 += 3;
        }
        int max = -1;
        //max = (tn1 < max) ? tn1 : max;
        max = (tn2 > max) ? tn2 : max;
        //max = (tm1 < max) ? tm1 : max;
        max = (tm2 > max) ? tm2 : max;

        Console.WriteLine(max);
        Console.ReadLine();
    }
}

#if DEBUG
using System.Reflection;
using System.Threading.Tasks;
#endif

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace vc3
{
    class Program
    {
        static string _inputFilename = "input.txt";
        static string _outputFilename = "output.txt";
#if DEBUG
        static bool _useFileInput = false;
#else
        static bool _useFileInput = false;
#endif

        static void Main(string[] args)
        {
            StreamWriter file = null;
            if (_useFileInput)
            {
                Console.SetIn(File.OpenText(_inputFilename));
                file = new StreamWriter(_outputFilename);
                Console.SetOut(file);
            }

#if DEBUG
			if (!_useFileInput)
			{
				Console.SetIn(getInput());
			}
#endif

            try
            {
                solution();
            }
            finally
            {
                if (_useFileInput)
                {
                    file.Close();
                }
            }
        }

        static void solution()
        {
            #region SOLUTION
            var a = readIntArray();
            var n = a[0];
            var m = a[1];
            var h2 = 2;
            var h3 = 0;

            if (n == 0)
            {
                Console.WriteLine(3 * m);
                return;
            }

            if (m == 0)
            {
                Console.WriteLine(2 * n);
                return;
            }

            if (m >= n)
            {
                var rem = m - n;
                var h = (n / 2) * 6 + (n % 2) * 3 + rem * 3;
                Console.WriteLine(h);
                return;
            }
            else
            {
                var rem = n - m;
                var ct = rem / 2;
                var r = rem % 2;

                var rc = n - ct * 3 - r;

                var h = (rc / 2) * 6 + ct * 6;// +(rc % 2) * 3 + ct * 6;
                var add = Math.Max((rc % 2) * 3, r * 2 + (rc % 2) * 2);
                Console.WriteLine(h + add);
                return;
            }

            //while (true)
            //{
            //    if (m > 0)
            //    {
            //        if (h3 < h2 || n == 0)
            //        {
            //            while (h3 < h2 && m > 0)
            //            {
            //                h3 += 3;
            //                m--;
            //            }

            //            continue;
            //        }
            //    }

            //    if (n > 0)
            //    {
            //        if (h2 < h3 || m == 0)
            //        {
            //            while (h2 < h3 && n > 0)
            //            {
            //                h2 += 2;
            //                n--;
            //            }

            //            continue;
            //        }
            //    }

            //    if (h2 == h3)
            //    {
            //        var p2 = (n + 1) * 2;
            //        var p3 = (m + 1) * 3;

            //        if (p2 > p3)
            //        {

            //        }
            //    }
            //}

            //var n = readInt();
            //var m = readInt();

            //var a = readIntArray();
            //var b = readIntArray();
            #endregion
        }

        static int readInt()
        {
            return int.Parse(Console.ReadLine());
        }

        static long readLong()
        {
            return long.Parse(Console.ReadLine());
        }

        static int[] readIntArray()
        {
            return Console.ReadLine().Split(' ').Where(i => !string.IsNullOrEmpty(i)).Select(i => int.Parse(i)).ToArray();
        }

        static long[] readLongArray()
        {
            return Console.ReadLine().Split(' ').Where(i => !string.IsNullOrEmpty(i)).Select(i => long.Parse(i)).ToArray();
        }

#if DEBUG
		static StreamReader getInput()
		{
			var resName = Assembly.GetCallingAssembly().GetManifestResourceNames()[0];
			var resource = Assembly.GetCallingAssembly().GetManifestResourceStream(resName);

			return new StreamReader(resource);
		}
#endif
    }
}