//package its_ulure;
import java.io.*;
import java.util.*;
public class Main{
    FastReader in;
    PrintWriter out;
    final long mod = 1000000009;
    final int MAXN = 1000000;
    final int lgN = 20;
    final long INF = (long)1e18 + 1;
    final int MAX_Ai = 1000001;
    public static void main(String[] args) throws java.lang.Exception{
        new Main().run();
    }
    void run() throws Exception{
        in = new FastReader(System.in);
        out = new PrintWriter(System.out);
        int t = 1;
        while(t-->0)
            solve();
        out.flush();
        out.close();
    }
    void solve(){
        char[] arr = new char[3];
        int[] x = new int[3];
        int i = 0;
        for(i = 0; i < 3; i++){
            String st = n();
            arr[i] = st.charAt(1);
            x[i] = st.charAt(0) - '0';
        }
        if(arr[0] == arr[1] && arr[1] == arr[2] && arr[0] == arr[2]){
            Arrays.sort(x);
            if(x[0] == x[2])
                pn(0);
            else if(x[0] + 1 == x[1] && x[1] + 1 == x[2])
                pn(0);
            else{
                int diff1 = x[1] - x[0];
                int diff2 = x[2] - x[1];
                if(diff1 == 0 || diff2 == 0)
                    pn(1);
                else if(diff1 <= 2 || diff2 <= 2)
                    pn(1);
                else
                    pn(2);
            }
        }
        else if(arr[0] == arr[1] || arr[0] == arr[2] || arr[1] == arr[2]){
            if(arr[0] == arr[1]){
                int diff = Math.abs(x[0] - x[1]);
                if(diff <= 2)
                    pn(1);
                else
                    pn(2);
            }
            else if(arr[1] == arr[2]){
                int diff = Math.abs(x[1] - x[2]);
                if(diff <= 2)
                    pn(1);
                else
                    pn(2);
            }
            else{
                int diff = Math.abs(x[0] - x[2]);
                if(diff <= 2)
                    pn(1);
                else
                    pn(2);
            }
        }
        else
            pn(2);
    }
    static final Comparator<Pair> com = new Comparator<Pair>(){
        public int compare(Pair a, Pair b){
            if(Integer.compare(a.x, b.x) != 0)
                return Integer.compare(a.x, b.x);
            else
                return Integer.compare(a.y, b.y);
        }
    };

    class Pair{
        int x;
        int y;
        Pair(int p, int q){
            x = p;
            y = q;
        }
    }
    class Edge{
        int u , v;
        Edge(int a, int b){
            u = a;
            v = b;
        }
        int other(int x) {
            return u ^ v ^ x;
        }
    }
    long gcd(long a, long b){return (b==0)?a:gcd(b,a%b);}
    int gcd(int a, int b){return (b==0)?a:gcd(b,a%b);}
    int bitcount(long n){return (n==0)?0:(1+bitcount(n&(n-1)));}
    void p(Object o){out.print(o);}
    void pn(Object o){out.println(o);}
    void pni(Object o){out.println(o);out.flush();}
    String n(){return in.next();}
    String nln(){return in.nextLine();}
    int ni(){return Integer.parseInt(in.next());}
    long nl(){return Long.parseLong(in.next());}
    double nd(){return Double.parseDouble(in.next());}

    long mul(long a,long b){
        if(a>=mod)a%=mod;
        if(b>=mod)b%=mod;
        a*=b;
        if(a>=mod)a%=mod;
        return a;
    }
    long modPow(long a, long p){
        long o = 1;
        while(p>0){
            if((p&1)==1)o = mul(o,a);
            a = mul(a,a);
            p>>=1;
        }
        return o;
    }

    class FastReader{
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public FastReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1)
                throw new UnknownError();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new UnknownError();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int peek() {
            if (numChars == -1)
                return -1;
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    return -1;
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar];
        }

        public void skip(int x) {
            while (x-- > 0)
                read();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public String nextString() {
            return next();
        }

        public String next() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuffer res = new StringBuffer();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));

            return res.toString();
        }

        public String nextLine() {
            StringBuffer buf = new StringBuffer();
            int c = read();
            while (c != '\n' && c != -1) {
                if (c != '\r')
                    buf.appendCodePoint(c);
                c = read();
            }
            return buf.toString();
        }

        public double nextDouble() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            double res = 0;
            while (!isSpaceChar(c) && c != '.') {
                if (c == 'e' || c == 'E')
                    return res * Math.pow(10, nextInt());
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            if (c == '.') {
                c = read();
                double m = 1;
                while (!isSpaceChar(c)) {
                    if (c == 'e' || c == 'E')
                        return res * Math.pow(10, nextInt());
                    if (c < '0' || c > '9')
                        throw new InputMismatchException();
                    m /= 10;
                    res += (c - '0') * m;
                    c = read();
                }
            }
            return res * sgn;
        }

        public boolean hasNext() {
            int value;
            while (isSpaceChar(value = peek()) && value != -1)
                read();
            return value != -1;
        }

        private boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }
    }
}


import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;

public class Main {
	public static void main(String[] args) {
		InputReader in = new InputReader();
		PrintWriter out = new PrintWriter(System.out);
		Thread th = new Thread(null, new Runnable(){public void run(){new Task1().solve(in, out);}},"Task1",1<<24);
		try{
			th.start();
			th.join();
		} catch(InterruptedException e){}
		out.close();
	}

	static class Task1{
		static final long MAX = Long.MAX_VALUE;

		public void solve(InputReader in, PrintWriter out){
			long[] cost = new long[32];
			Arrays.fill(cost, MAX);
			int n = in.nextInt(), L = in.nextInt();

			for(int i=0; i<n; i++){
				cost[i] = in.nextLong();
			}
			for(int i=1; i<32; i++)
				cost[i] = Math.min(cost[i], 2*cost[i-1]);

			String binary = new StringBuilder(Integer.toBinaryString(L)).reverse().toString();
			long ans1 = MAX, ans2 = 0;
			for(int i=binary.length(); i<32; i++)
				ans1 = Math.min(ans1, cost[i]);

			for(int i=0; i<binary.length(); i++){
				ans2 += binary.charAt(i)=='1'?cost[i]:0;
				ans2 = Math.min(ans2, cost[i+1]);
			}

			out.println(Math.min(ans1, ans2));
		}

		long gcd(long a, long b){
			while(a>0){
				long rem = b%a;
				b = a;
				a = rem;
			}
			return b;
		}
		long expo(long a, long b, long MOD){
			long result = 1;
			while (b>0){
				if (b%2==1) result=(result*a)%MOD;
				b>>=1;
				a=(a*a)%MOD;
			}
			return result%MOD;
		}
		long inverseModullo(long numerator, long denominator, long MOD){
			return ((numerator )*(expo(denominator, MOD-2, MOD))) ;
		}
	}

	static class InputReader{
		final InputStream stream;
		final byte[] buf = new byte[8192];
		int curChar, numChars;
		SpaceCharFilter filter;
		public InputReader(){
			this.stream = System.in;
		}
		public int read(){
			if(numChars == -1) throw new InputMismatchException();
			if(curChar >= numChars){
				curChar = 0;
				try{
					numChars = stream.read(buf);
				} catch(IOException e){
					throw new InputMismatchException();
				}
				if(numChars <= 0) return -1;
			}
			return buf[curChar++];
		}
		public int nextInt(){
			int c = read();
			while(isSpaceChar(c)) c = read();
			int sgn = 1;
			if(c == '-'){
				sgn = -1;
				c = read();
			}
			int res = 0;
			do{
				if(c<'0' || c>'9') throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while(!isSpaceChar(c));
			return res*sgn;
		}
		public long nextLong(){
			int c = read();
			while(isSpaceChar(c)) c = read();
			int sgn = 1;
			if(c == '-'){
				sgn = -1;
				c = read();
			}
			long res = 0;
			do{
				if(c<'0' || c>'9') throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while(!isSpaceChar(c));
			return res*sgn;
		}
		public String next(){
			int c = read();
			while(isSpaceChar(c)) c = read();
			StringBuilder res = new StringBuilder();
			do{
				res.appendCodePoint(c);
				c = read();
			}while(!isSpaceChar(c));
			return res.toString();
		}
		public boolean isSpaceChar(int c){
			if(filter != null) return filter.isSpaceChar(c);
			return c==' ' || c=='\n' || c=='\r' || c=='\t' || c==-1;
		}
		public interface SpaceCharFilter{
			public boolean isSpaceChar(int ch);
		}
	}
	static class SegmentTree{
		static Integer[] segTree;
		public SegmentTree(Integer[] input){
			int n=input.length;
			int size=(int)Math.ceil(Math.log(n)/Math.log(2));
			segTree=new Integer[pow(2,size+1)-1];
			buildSegmentTree(input, 0, n-1, 0);
		}

		void buildSegmentTree(Integer[] input, int lo, int hi, int pos){
			if(lo==hi){
				segTree[pos]=input[lo];
				return;
			}
			int mid=lo+(hi-lo)/2;
			buildSegmentTree(input, lo, mid, 2*pos+1);
			buildSegmentTree(input, mid+1, hi, 2*pos+2);
			segTree[pos]=Math.max(segTree[2*pos+1], segTree[2*pos+2]);
		}

		int rangeMaxQuery(int lo, int hi, int qlo, int qhi, int pos){
			if(qlo>hi || qhi<lo) return -1;
			else if(qlo<=lo && qhi>=hi) return segTree[pos];
			int mid=lo+(hi-lo)/2;
			return Math.max(
					rangeMaxQuery(lo, mid, qlo, qhi, 2*pos+1),
					rangeMaxQuery(mid+1, hi, qlo, qhi, 2*pos+2)
					);
		}

		void updateSegmentTree(int lo, int hi, int index, int value, int pos){
			if(lo==hi){
				segTree[pos]=value;
				return;
			}
			int mid=lo+(hi-lo)/2;
			if(index<=mid) updateSegmentTree(lo, mid, index, value, 2*pos+1);
			else updateSegmentTree(mid+1, hi, index, value, 2*pos+2);
			segTree[pos]=Math.max(segTree[2*pos+1], segTree[2*pos+2]);
		}

		private static int pow(int a, int b){
			int result = 1, MOD=Integer.MAX_VALUE;
			while (b>0){
				if (b%2==1) result=(result*a)%MOD;
				b>>=1;
				a=(a*a)%MOD;
			}
			return result%MOD;
		}
	}
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author lewin
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        EBalancedBinarySearchTrees solver = new EBalancedBinarySearchTrees();
        solver.solve(1, in, out);
        out.close();
    }

    static class EBalancedBinarySearchTrees {
        public void solve(int testNumber, InputReader in, OutputWriter out) {
            int n = in.nextInt();
            int[] r = new int[]{1, 2, 4, 5, 9, 10, 20, 21, 41, 42, 84, 85, 169, 170, 340, 341, 681, 682, 1364, 1365, 2729, 2730, 5460, 5461, 10921, 10922, 21844, 21845, 43689, 43690, 87380, 87381, 174761, 174762, 349524, 349525, 699049, 699050};
            boolean print = false;
            for (int j : r)
                if (n == j) {
                    out.println(1);
                    print = true;
                }
            if (!print) out.println(0);
//        dp = new int[2][n+1];
//        AUtils.deepFill(dp, -1);
//        out.println((count(n, 0) + count(n, 1)) % mod);
//        dp = new int[2][1000000+1];
//        AUtils.deepFill(dp, -1);
//        ArrayList<Integer> tt = new ArrayList<>();
//        int ct = 0;
//        int sh = 0;
//        for (int n = 1; n <= 1000000; n++) {
//            mxn = n-10;
//            long ans = (count(n, 0) + count(n, 1)) % mod;
//            if (ans != 0) {
//                Debug.print(n,ans);
//                tt.add(n);
//                sh = 1;
////                Debug.print(n,Integer.toString(n,2));
//            }
//            ct += sh;
//            if (ct == 5) {
//                n = Math.max(n, n * 2 - 10);
//                ct = 0;
//                sh = 0;
//            }
//        }
//        out.println(tt);
        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void close() {
            writer.close();
        }

        public void println(int i) {
            writer.println(i);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1 << 16];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (this.numChars == -1) {
                throw new InputMismatchException();
            } else {
                if (this.curChar >= this.numChars) {
                    this.curChar = 0;

                    try {
                        this.numChars = this.stream.read(this.buf);
                    } catch (IOException var2) {
                        throw new InputMismatchException();
                    }

                    if (this.numChars <= 0) {
                        return -1;
                    }
                }

                return this.buf[this.curChar++];
            }
        }

        public int nextInt() {
            int c;
            for (c = this.read(); isSpaceChar(c); c = this.read()) {
                ;
            }

            byte sgn = 1;
            if (c == 45) {
                sgn = -1;
                c = this.read();
            }

            int res = 0;

            while (c >= 48 && c <= 57) {
                res *= 10;
                res += c - 48;
                c = this.read();
                if (isSpaceChar(c)) {
                    return res * sgn;
                }
            }

            throw new InputMismatchException();
        }

        public static boolean isSpaceChar(int c) {
            return c == 32 || c == 10 || c == 13 || c == 9 || c == -1;
        }

    }
}


import java.util.*;
import java.io.*;

//cuba orz

public class BNew {
    public static void main(String[] args) throws IOException{
        BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        int t = Integer.parseInt(f.readLine());
        while(t-->0){
            StringTokenizer st = new StringTokenizer(f.readLine());
            int n = Integer.parseInt(st.nextToken());
            long k = Long.parseLong(st.nextToken());
            long l = Long.parseLong(st.nextToken());
            long[] depths = new long[n];
            st = new StringTokenizer(f.readLine());
            boolean good = true;
            for(int i = 0; i < n; i++){
                depths[i] = l-Long.parseLong(st.nextToken());
                if(depths[i] < 0){
                    good = false;
                    break;
                }
            }
            if(!good){
                out.println("No");
                continue;
            }
            int ptr = 0;
            while(ptr < n){
                long left = 1;
                long right = 2*k-1;
                int count = 0;
                while(ptr+count < n){
                    if(depths[ptr+count] >= k) break;
                    long templ = k-depths[ptr+count];
                    long tempr = k+depths[ptr+count];
                    templ+=count;
                    tempr+=count;
                    if(templ > right || tempr < left){
                        good = false;
                        break;
                    }
                    if(templ >= left && tempr <= right){
                        left = templ;
                        right = tempr;
                    }else if(templ <= left && tempr <= right){
                        right = tempr;
                    }else if(templ >= left && tempr >= right){
                        left = templ;
                    }
                    count++;
                }
                if(!good) break;
                ptr+=(count+1);
            }
            if(!good){
                out.println("No");
            }else{
                out.println("Yes");
            }

        }

        out.close();
    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            boolean[] isRed = new boolean[n];
            int[] red = new int[n];
            int[] blue = new int[n];
            int cntRed = 0;
            for (int i = 0; i < n; ++i) {
                isRed[i] = in.next().equals("R");
                if (isRed[i]) ++cntRed;
                red[i] = in.nextInt();
                blue[i] = in.nextInt();
            }
            if (cntRed > n / 2) {
                for (int i = 0; i < n; ++i) {
                    isRed[i] = !isRed[i];
                    int t = red[i];
                    red[i] = blue[i];
                    blue[i] = t;
                }
                cntRed = n - cntRed;
            }
            byte[][] minBlueWaste = new byte[1 << n][((n - 1) + (n - cntRed)) * cntRed / 2 + 1];
            for (byte[] x : minBlueWaste) Arrays.fill(x, Byte.MAX_VALUE);
            minBlueWaste[0][0] = 0;
            for (int set = 0; set < (1 << n); ++set) {
                byte[] old = minBlueWaste[set];
                int numRed = 0;
                int numBlue = 0;
                for (int nxt = 0; nxt < n; ++nxt)
                    if ((set & (1 << nxt)) != 0) {
                        if (isRed[nxt]) ++numRed;
                        else ++numBlue;
                    }
                int extraBlueWaste = 0;
                int extraRedWaste = 0;
                for (int nxt = 0; nxt < n; ++nxt)
                    if ((set & (1 << nxt)) == 0) {
                        if (red[nxt] <= numRed) {
                            ++extraRedWaste;
                        }
                        if (blue[nxt] <= numBlue) {
                            ++extraBlueWaste;
                        }
                    }
                for (int nxt = 0; nxt < n; ++nxt)
                    if ((set & (1 << nxt)) == 0) {
                        int gotBlueWaste = extraBlueWaste;
                        int gotRedWaste = extraRedWaste;
                        if (red[nxt] <= numRed) {
                            --gotRedWaste;
                        }
                        if (blue[nxt] <= numBlue) {
                            --gotBlueWaste;
                        }
                        byte[] dst = minBlueWaste[set | (1 << nxt)];
                        for (int ow = 0; ow < old.length; ++ow)
                            if (old[ow] < Byte.MAX_VALUE) {
                                if (isRed[nxt]) {
                                    dst[ow + gotRedWaste] = (byte) Math.min(dst[ow + gotRedWaste], old[ow] + (n - cntRed - numBlue));
                                } else {
                                    dst[ow + cntRed - numRed] = (byte) Math.min(dst[ow + cntRed - numRed], old[ow] + gotBlueWaste);
                                }
                            }
                    }
            }
            int totalRed = 0;
            int totalBlue = 0;
            for (int x : red) totalRed += x;
            for (int x : blue) totalBlue += x;
            byte[] fin = minBlueWaste[(1 << n) - 1];
            int res = Integer.MAX_VALUE;
            for (int ow = 0; ow < fin.length; ++ow)
                if (fin[ow] < Byte.MAX_VALUE) {
                    int gotRed = totalRed + ow - (n - 1 + n - cntRed) * cntRed / 2;
                    int gotBlue = totalBlue + fin[ow] - (n - 1 + cntRed) * (n - cntRed) / 2;
                    res = Math.min(res, Math.max(gotRed, gotBlue) + n);
                }
            out.println(res);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}


import java.io.*;
import java.util.*;
import java.math.*;
import static java.lang.Math.*;

public class Main implements Runnable {

    long MOD = 1000000009;
    public void solve() throws IOException {
        int n = nextInt();
        long[] ans = new long[n + 1];
        long[] q = new long[n + 1];
        long[] Q = new long[n + 1];
        q[0] = Q[0] = 1;
        for(int i = 1; i <= n; ++i) {
            q[i] = (2 * (1 + q[i - 1]) + 1) % MOD;
            Q[i] = (q[i] * Q[i - 1]) % MOD;
        }
        ans[2] = 2;
        for(int t = 4; t <= n; t += 2) {
            long qq = (Q[(t - 4) / 2]);
            ans[t] = (ans[t - 2] + 4 * qq) % MOD;
        }
        long tmp = ans[n];
        //pw.println(tmp);
        long p = (tmp * tmp + 1) * 2 % MOD;
        pw.println(p);
    }

    static final String filename = "A";
    static final boolean fromConsole = true;

    public void run() {
        try {
            if (!fromConsole) {
                in = new BufferedReader(new FileReader(filename + ".in"));
                pw = new PrintWriter(filename + ".out");
            } else {
                in = new BufferedReader(new InputStreamReader(System.in));
                pw = new PrintWriter(System.out);
            }
            st = new StringTokenizer("");
            long st = System.currentTimeMillis();
            solve();
            //pw.printf("\nWorking time: %d ms\n", System.currentTimeMillis() - st);
            pw.close();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(-1);
        }
    }

    private StringTokenizer st;
    private BufferedReader in;
    private PrintWriter pw;

    boolean hasNext() throws IOException {
        while (!st.hasMoreTokens()) {
            String line = in.readLine();
            if (line == null) {
                return false;
            }
            st = new StringTokenizer(line);
        }
        return st.hasMoreTokens();
    }

    String next() throws IOException {
        return hasNext() ? st.nextToken() : null;
    }

    int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    BigInteger nextBigInteger() throws IOException {
        return new BigInteger(next());
    }

    long nextLong() throws IOException {
        return Long.parseLong(next());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(next());
    }

    public static void main(String[] args) {
        new Thread(new Main()).start();
    }
}


import java.io.*;
import java.util.*;
import java.util.Map.Entry;
import java.lang.Math;
import java.math.BigInteger;

public class Problem {

	void solve() throws IOException {

		int n = rI();
		int m = rI();
		int[] a;

		if(n%2==1){
			n++;
			a = new int[n];
			a[n-1] = 0;
			for(int i=0;i<n-1;++i){
				a[i] = rI();
			}
		}else{
			a = rA(n);
		}

		long bp = binPow(2, n/2);
		TreeSet<Integer> st1 = new TreeSet<>();
		TreeSet<Integer> st2 = new TreeSet<>();
		for (int mask = 0; mask < bp; ++mask) {
			int sum = 0;
			for (int bit = 0; bit < n/2; ++bit) {
				if (checkBit(mask, bit) == 1) {
					sum = (sum + a[bit] % m) % m;
				}
			}
			st1.add(sum);
		}

		for (int mask = 0; mask < bp; ++mask) {
			int sum = 0;
			for (int bit = 0; bit < n/2 ; ++bit) {
				if (checkBit(mask, bit) == 1) {
					sum = (sum + a[n/2+bit] % m) % m;
				}
			}
			st2.add(sum);
		}

		int ans = 0;

		for(int i: st1){
			int j = 0;
			if(st2.lower(m-i)!=null){
				j = st2.lower(m-i);
			}
			ans = Math.max(ans, i+j);
		}

		for(int i: st2){
			int j = 0;
			if(st1.lower(m-i)!=null){
				j = st1.lower(m-i);
			}
			ans = Math.max(ans, i+j);
		}
		out.println(ans);
	}

	class SegmentTree {
		int[] t;

		SegmentTree(int[] a, int n) {
			t = new int[4 * n];
			build(a, 1, 1, n);
		}

		void build(int[] a, int v, int tl, int tr) {
			if (tl == tr) {
				t[v] = a[tl];
				return;
			}

			int tm = (tl + tr) / 2;
			build(a, 2 * v, tl, tm);
			build(a, 2 * v + 1, tm + 1, tr);
			t[v] = Math.min(t[2 * v], t[2 * v + 1]);
		}

		void update(int v, int tl, int tr, int pos, int value) {
			if (tl == tr) {
				t[v] = value;
				return;
			}
			int tm = (tl + tr) / 2;
			if (pos <= tm) {
				update(2 * v, tl, tm, pos, value);
			} else {
				update(2 * v + 1, tm + 1, tr, pos, value);
			}

			t[v] = Math.min(t[2 * v], t[2 * v + 1]);
		}

		int getMin(int v, int tl, int tr, int l, int r) {
			if (l > r) {
				return INF;
			}
			if (tl == l && tr == r) {
				return t[v];
			}

			int tm = (tl + tr) / 2;

			int min1 = getMin(2 * v, tl, tm, l, Math.min(tm, r));
			int min2 = getMin(2 * v + 1, tm + 1, tr, Math.max(l, tm + 1), r);

			return Math.min(min1, min2);
		}
	}

	int checkBit(int mask, int bit) {
		return (mask >> bit) & 1;
	}

	public static void main(String[] args) throws IOException {

		new Problem().run();
	}

	boolean isLower(char a) {
		return ((int) a) >= 97 ? true : false;
	}

	int INF = Integer.MAX_VALUE - 12345;

	int[][] STEPS = { { 0, 1 }, { 1, 0 }, { -1, 0 }, { 0, -1 } };

	BufferedReader in;
	PrintWriter out;
	StringTokenizer tok;
	Random rnd = new Random();
	static final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;

	Problem() throws FileNotFoundException {

		try {
			in = new BufferedReader(new FileReader("input.txt"));
			out = new PrintWriter("output.txt");
		} catch (Exception e) {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
		}

		tok = new StringTokenizer("");
	}

	long checkBit(long mask, int bit) {
		return (mask >> bit) & 1;
	}

	// ======================================================

	// ======================================================
	void run() throws IOException {
		solve();
		out.close();
	}

	char[] reverseCharArray(char[] arr) {
		char[] ans = new char[arr.length];
		for (int i = 0; i < arr.length; ++i) {
			ans[i] = arr[arr.length - i - 1];
		}
		return ans;
	}

	int sqrt(double m) {
		int l = 0;
		int r = 1000000000 + 9;
		int i = 1000;
		while (r - l > 1) {
			int mid = (r + l) / 2;
			if (mid * mid > m) {
				r = mid;
			} else {
				l = mid;
			}
		}
		return l;
	}

	int countPow(int m, int n) {
		int ans = 0;
		while (m % n == 0 && m > 0) {
			ans++;
			m /= n;
		}
		return ans;
	}

	long binPow(long a, long b) {
		if (b == 0) {
			return 1;
		}
		if (b % 2 == 1) {
			return a * binPow(a, b - 1);
		} else {
			long c = binPow(a, b / 2);
			return c * c;
		}

	}

	int gcd(int a, int b) {
		return b == 0 ? a : gcd(b, a % b);
	}

	long pow(long x, long k) {
		long ans = 1;
		for (int i = 0; i < k; ++i) {
			ans *= x;
		}
		return ans;
	}

	class Fenwik {
		private long[] t;
		private int length;

		Fenwik(int[] a) {
			this.length = a.length + 100;
			this.t = new long[length];
			for (int i = 0; i < a.length; ++i) {
				this.inc(i, a[i]);
			}
		}

		void inc(int i, int delta) {
			for (; i < this.length; i = i | (i + 1)) {
				this.t[i] += delta;
			}
		}

		long getSum(int r) {
			long sum = 0;

			for (; r >= 0; r = (r & (r + 1)) - 1) {
				sum += this.t[r];
			}

			return sum;
		}
	}

	// ////////////////////////////////////////////////////////////////////

	String delimiter = " ";

	String readLine() throws IOException {
		return in.readLine();
	}

	String rS() throws IOException {
		while (!tok.hasMoreTokens()) {
			String nextLine = readLine();
			if (null == nextLine)
				return null;

			tok = new StringTokenizer(nextLine);
		}

		return tok.nextToken(delimiter);
	}

	int rI() throws IOException {
		return Integer.parseInt(rS());
	}

	long rL() throws IOException {
		return Long.parseLong(rS());
	}

	double rD() throws IOException {
		return Double.parseDouble(rS());
	}

	int[] rA(int b) {
		int a[] = new int[b];
		for (int i = 0; i < b; i++) {
			try {
				a[i] = rI();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return a;
	}

	int[] readSortedIntArray(int size) throws IOException {
		Integer[] array = new Integer[size];

		for (int index = 0; index < size; ++index) {
			array[index] = rI();
		}
		Arrays.sort(array);

		int[] sortedArray = new int[size];
		for (int index = 0; index < size; ++index) {
			sortedArray[index] = array[index];
		}

		return sortedArray;
	}

	int[] sortedIntArray(int size, int[] array) throws IOException {
		for (int index = 0; index < size; ++index) {
			array[index] = rI();
		}
		Arrays.sort(array);

		int[] sortedArray = new int[size];
		for (int index = 0; index < size; ++index) {
			sortedArray[index] = array[index];
		}

		return sortedArray;
	}
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.stream.IntStream;
import java.util.List;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.ArrayList;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int m = in.nextInt();
            if (n > m) {
                int t = n;
                n = m;
                m = t;
            }

            long V = (long) n * m;

            if (V < 100) {
                List<Integer>[] g = new List[(int) V];
                for (int i = 0; i < V; i++) {
                    g[i] = new ArrayList<>();
                }
                for (int i = 0; i < V; i++) {
                    for (int j = 0; j < V; j++) {
                        int r1 = i / m;
                        int c1 = i % m;
                        int r2 = j / m;
                        int c2 = j % m;
                        if (Math.abs(r1 - r2) + Math.abs(c1 - c2) == 3) {
                            g[i].add(j);
                        }
                    }
                }

                int res = maxMatching(g) * 2;
                out.println(res);
            } else {
                long res;
                if (n == 1) {
                    res = m / 6 * 6 + (m % 6 == 4 ? 2 : 0) + (m % 6 == 5 ? 4 : 0);
                } else {
                    res = (long) n * m;
                    res -= res % 2;
                }
                out.println(res);
            }
        }

        static int maxMatching(List<Integer>[] graph) {
            int n = graph.length;
            int[] match = new int[n];
            Arrays.fill(match, -1);
            int[] p = new int[n];
            for (int i = 0; i < n; ++i) {
                if (match[i] == -1) {
                    int v = findPath(graph, match, p, i);
                    while (v != -1) {
                        int pv = p[v];
                        int ppv = match[pv];
                        match[v] = pv;
                        match[pv] = v;
                        v = ppv;
                    }
                }
            }
            return (int) Arrays.stream(match).filter(x -> x != -1).count() / 2;
        }

        static int findPath(List<Integer>[] graph, int[] match, int[] p, int root) {
            Arrays.fill(p, -1);
            int n = graph.length;
            int[] base = IntStream.range(0, n).toArray();

            boolean[] used = new boolean[n];
            int[] q = new int[n];
            int qt = 0;
            used[root] = true;
            q[qt++] = root;
            for (int qh = 0; qh < qt; qh++) {
                int u = q[qh];
                for (int v : graph[u]) {
                    if (base[u] == base[v] || match[u] == v) continue;
                    if (v == root || match[v] != -1 && p[match[v]] != -1) {
                        int curbase = lca(match, base, p, u, v);
                        boolean[] blossom = new boolean[n];
                        markPath(match, base, blossom, p, u, curbase, v);
                        markPath(match, base, blossom, p, v, curbase, u);
                        for (int i = 0; i < n; ++i)
                            if (blossom[base[i]]) {
                                base[i] = curbase;
                                if (!used[i]) {
                                    used[i] = true;
                                    q[qt++] = i;
                                }
                            }
                    } else if (p[v] == -1) {
                        p[v] = u;
                        if (match[v] == -1)
                            return v;
                        v = match[v];
                        used[v] = true;
                        q[qt++] = v;
                    }
                }
            }
            return -1;
        }

        static void markPath(int[] match, int[] base, boolean[] blossom, int[] p, int u, int curbase, int child) {
            for (; base[u] != curbase; u = p[match[u]]) {
                blossom[base[u]] = blossom[base[match[u]]] = true;
                p[u] = child;
                child = match[u];
            }
        }

        static int lca(int[] match, int[] base, int[] p, int a, int b) {
            boolean[] used = new boolean[match.length];
            while (true) {
                a = base[a];
                used[a] = true;
                if (match[a] == -1) break;
                a = p[match[a]];
            }
            while (true) {
                b = base[b];
                if (used[b]) return b;
                b = p[match[b]];
            }
        }

    }

    static class InputReader {
        final InputStream is;
        final byte[] buf = new byte[1024];
        int pos;
        int size;

        public InputReader(InputStream is) {
            this.is = is;
        }

        public int nextInt() {
            int c = read();
            while (isWhitespace(c))
                c = read();
            int sign = 1;
            if (c == '-') {
                sign = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res = res * 10 + c - '0';
                c = read();
            } while (!isWhitespace(c));
            return res * sign;
        }

        int read() {
            if (size == -1)
                throw new InputMismatchException();
            if (pos >= size) {
                pos = 0;
                try {
                    size = is.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (size <= 0)
                    return -1;
            }
            return buf[pos++] & 255;
        }

        static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Egor Kulikov (egor@egork.net)
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        BLittleCLoves3II solver = new BLittleCLoves3II();
        solver.solve(1, in, out);
        out.close();
    }

    static class BLittleCLoves3II {
        int[][][] answer;
        long n;
        long m;

        public void solve(int testNumber, InputReader in, OutputWriter out) {
            n = in.readInt();
            m = in.readInt();
            if (n > m) {
                long t = n;
                n = m;
                m = t;
            }
            if (n == 1) {
                long x = m % 6;
                if (x <= 3) {
                    out.printLine(m - x);
                    return;
                }
                if (x == 4) {
                    out.printLine(m - 2);
                    return;
                }
                out.printLine(m - 1);
                return;
            }
            if (n <= 5 && m <= 30) {
                answer = new int[(int) (m + 1)][(int) (n + 1)][1 << (3 * n)];
                ArrayUtils.fill(answer, -1);
                out.printLine(go(0, 0, 0));
                return;
            }
            out.printLine(n * m - n * m % 2);
        }

        private int go(int row, int col, int mask) {
            if (answer[row][col][mask] != -1) {
                return answer[row][col][mask];
            }
            if (row == m) {
                return answer[row][col][mask] = mask == 0 ? 0 : Integer.MIN_VALUE;
            }
            if (col == n) {
                return answer[row][col][mask] = go(row + 1, 0, mask);
            }
            if ((mask & 1) == 1) {
                return answer[row][col][mask] = go(row, col + 1, mask >> 1);
            }
            answer[row][col][mask] = go(row, col + 1, mask >> 1);
            answer[row][col][mask] =
                    Math.max(go(row, col + 1, (mask >> 1) + (1 << (3 * n - 1))) + 2, answer[row][col][mask]);
            if (col != 0 && (mask >> (2 * n - 1) & 1) == 0) {
                answer[row][col][mask] = Math.max(answer[row][col][mask], go(row, col + 1,
                        (mask >> 1) + (1 << (2 * n - 2))) + 2);
            }
            if (col != n - 1 && (mask >> (2 * n + 1) & 1) == 0) {
                answer[row][col][mask] = Math.max(answer[row][col][mask], go(row, col + 1,
                        (mask >> 1) + (1 << (2 * n))) + 2);
            }
            if (col >= 2 && (mask >> (n - 2) & 1) == 0) {
                answer[row][col][mask] = Math.max(answer[row][col][mask], go(row, col + 1,
                        (mask >> 1) + (1 << (n - 3))) + 2);
            }
            if (col < n - 1 && (mask >> (n + 2) & 1) == 0) {
                answer[row][col][mask] = Math.max(answer[row][col][mask], go(row, col + 1,
                        (mask >> 1) + (1 << (n + 1))) + 2);
            }
            return answer[row][col][mask];
        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void close() {
            writer.close();
        }

        public void printLine(long i) {
            writer.println(i);
        }

        public void printLine(int i) {
            writer.println(i);
        }

    }

    static class ArrayUtils {
        public static void fill(int[][] array, int value) {
            for (int[] row : array) {
                Arrays.fill(row, value);
            }
        }

        public static void fill(int[][][] array, int value) {
            for (int[][] subArray : array) {
                fill(subArray, value);
            }
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int readInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}


import java.io.*;
import java.util.*;

public class Main{
static int mod = (int)(Math.pow(10, 9) + 7);
   public static void main(String[] args) {
      MyScanner sc = new MyScanner();
      out = new PrintWriter(new BufferedOutputStream(System.out));
      long n = sc.nextInt(), m = sc.nextInt();
      if (m < n) {
    	  long temp = n;
    	  n = m;
    	  m = temp;
      }
      if (n <= 2 && m <= 2) {
    	  out.println(0);
      }
      else if (n == 1) {
    	  long res = m/6;
    	  res *= 6;
    	  long mod = m%6;
    	  if (mod >= 4) {
    		  mod -= 3;
    		  res += mod*2;
    	  }
    	  out.println(res);
      }
      else if (n == 2) {
    	  long res = n*m;
    	  if (m == 3) res=4;
    	  else if (m == 7) res = 12;
    	  out.println(res);
      }
      else {

    		  out.println(n*m/2 * 2);

      }
      out.close();
   }

   static long pow(long a, long N) {
	   if (N == 0) return 1;
	   else if (N == 1) return a;
	   else {
		   long R = pow(a,N/2);
		   if (N % 2 == 0) {
			   return R*R;
		   }
		   else {
			   return R*R*a;
		   }
	   }
   }

   static long powMod(long a, long N) {
	   if (N == 0) return 1;
	   else if (N == 1) return a % mod;
	   else {
		   long R = powMod(a,N/2) % mod;
		   R *= R % mod;
		   if (N % 2 == 1) {
			   R *= a % mod;
		   }
			   return R % mod;
	   }
   }
static void mergeSort(int[] A){ // low to hi sort, single array only
      int n = A.length;
      if (n < 2) return;
      int[] l = new int[n/2];
      int[] r = new int[n - n/2];

      for (int i = 0; i < n/2; i++){
        l[i] = A[i];
      }

      for (int j = n/2; j < n; j++){
        r[j-n/2] = A[j];
      }

      mergeSort(l);
      mergeSort(r);
      merge(l, r, A);
    }

    static void merge(int[] l, int[] r, int[] a){
      int i = 0, j = 0, k = 0;
      while (i < l.length && j < r.length && k < a.length){
        if (l[i] < r[j]){
          a[k] = l[i];
          i++;
        }
        else{
          a[k] = r[j];
          j++;
        }
        k++;
      }
      while (i < l.length){
        a[k] = l[i];
        i++;
        k++;
      }

      while (j < r.length){
        a[k] = r[j];
        j++;
        k++;
      }
    }

   //-----------PrintWriter for faster output---------------------------------
   public static PrintWriter out;

   //-----------MyScanner class for faster input----------
   public static class MyScanner {
      BufferedReader br;
      StringTokenizer st;

      public MyScanner() {
         br = new BufferedReader(new InputStreamReader(System.in));
      }

      String next() {
          while (st == null || !st.hasMoreElements()) {
              try {
                  st = new StringTokenizer(br.readLine());
              } catch (IOException e) {
                  e.printStackTrace();
              }
          }
          return st.nextToken();
      }

      int nextInt() {
          return Integer.parseInt(next());
      }

      long nextLong() {
          return Long.parseLong(next());
      }

      double nextDouble() {
          return Double.parseDouble(next());
      }

      String nextLine(){
          String str = "";
	  try {
	     str = br.readLine();
	  } catch (IOException e) {
	     e.printStackTrace();
	  }
	  return str;
      }

   }
   //--------------------------------------------------------
}


import java.util.*;
import java.io.*;
import java.math.*;
public class hi{

    public static void main(String[] args) throws IOException  {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long m = sc.nextLong();
        long rep = 0;
        if(n>=4&&m>=4){
            if(n%2==0||m%2==0) rep = n*m;
            else rep = n*m-1;
        }
        else{
            long min = Math.min(n,m);
            long max = Math.max(n,m);
            if(min==1){
                rep = max- (max%6);
                if(max%6==4) rep += 2;
                if(max%6==5) rep += 4;
            }
            else if(min==2){
                if(max<3) rep = 0;
                else if(max==3) rep = 4;
                else if(max==7) rep = 12;
                else rep = min * max;
            }
            else if(min==3) {
                if(max<3) rep = 0;
                else {
                    rep = min * max;
                    if(max%2==1) rep--;
                }
            }

        }
        System.out.println(rep);
    }

}


import java.io.DataInputStream;
import java.io.IOException;

public class PD {
    public static void main(String... args) throws IOException {
        Reader reader = new Reader();

        long n = reader.nextInt();
        long m = reader.nextInt();

        long x1 = Math.min(n, m);
        long x2 = Math.max(n, m);

        if(x1 == 1) {
            int memo[] = {0, 1, 2, 3, 2, 1};

            System.out.println(x1 * x2 - (memo[(int)(x2 % 6)]));
        } else if(x1 == 2) {
            if(x2 == 2) {
                System.out.println(0);
            } else if(x2 == 3 || x2 == 7) {
                System.out.println(x1 * x2 - 2);
            } else {
                System.out.println(x1 * x2);
            }
        } else if((x1 * x2) % 2 == 0) {
            System.out.println(x1 * x2);
        } else {
            System.out.println(x1 * x2 - 1);
        }
    }

    static class Reader {
        final private int BUFFER_SIZE = 1 << 16;
        private DataInputStream din;
        private byte[] buffer;
        private int bufferPointer, bytesRead;

        Reader() {
            din = new DataInputStream(System.in);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        String readLine() throws IOException {
            byte[] buf = new byte[64]; // line length
            int cnt = 0, c;
            while ((c = read()) != -1) {
                if (c == '\n')
                    break;
                buf[cnt++] = (byte) c;
            }
            return new String(buf, 0, cnt);
        }

        //Will read words with space as delimiters
        public String nextWord() throws IOException {
            byte[] buf = new byte[64]; // word length

            byte c = read();
            while (c == ' ')
                c = read();
            int cnt = 0;
            do {
                buf[cnt++] = c;
                c = read();
            } while (c != ' ' && c != '\n');

            return new String(buf, 0, cnt);
        }

        public int nextInt() throws IOException {
            int ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');

            if (neg)
                return -ret;
            return ret;
        }

        private void fillBuffer() throws IOException {
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
            if (bytesRead == -1)
                buffer[0] = -1;
        }

        private byte read() throws IOException {
            if (bufferPointer == bytesRead)
                fillBuffer();
            return buffer[bufferPointer++];
        }

        public void close() throws IOException {
            if (din == null)
                return;
            din.close();
        }
    }
}


import java.util.*;
import java.util.regex.Pattern;
public class Stub {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
long n = in.nextLong(); //
long m = in.nextLong();
long out = 0;
if (n+m < 5) {
    System.out.println("0"); // too small
} else {
    if (n==1 || m==1) {
        long l = n+m-1;
        long x = l/6;
        long y = 0;
        if (l%6 == 4) y+= 2;
        if (l%6 == 5) y += 4;
        out = x*6 + y;
        System.out.println(out);
        return;
    }
   out = (n*m)-(n*m)%2;
   if ((n%4 !=0) && (m%4 !=0) && (n+m)%4 == 1 && (n*m) <15) out -=2;
   // if ((n+m > 9) && (n==3 || m==3) && ((n+m)%4 == 2)) out -=2;

System.out.println(out); //
}

} // end main
}


import java.io.BufferedInputStream;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner s = new Scanner(new BufferedInputStream(System.in));
		int n = s.nextInt();
		int m = s.nextInt();
		if (n > m) {
			solution(m, n);
		} else {
			solution(n, m);
		}

	}

	private static void solution(int n, int m) {
		if (n == 1) {
			System.out.println(m / 6 * 3 + Math.max(m % 6 - 3, 0) << 1);
		} else if (n == 2) {
			System.out.println(m == 2 ? 0 : m == 3 ? 4 : m == 7 ? 12 : m << 1);
		} else {
			System.out.println(1l * n * m / 2 * 2);
		}

	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

    static BufferedReader br;

    public static void main(String[] args) throws IOException{
        br = new BufferedReader(new InputStreamReader(System.in));
        long[] nm = longs();
        long n = nm[0];
        long m = nm[1];
        if (n > m) {
            long tmp = n;
            n = m;
            m = tmp;
        }

        long sol = 0;

        if (m < 3) {
            System.out.println(sol);
            return;
        }

        if (n == 1) {
            sol = m % 6;
            if (sol > 3) sol = 6 - sol;
            System.out.println(m - sol);
            return;
        }

        if (n == 2) {
            sol = m * n;
            if (m == 3) sol = 4;
            if (m == 7) sol = 12;
        } else if (n == 3) {
            sol = m * n;
            if (m % 2 == 1) sol -= 1;
        } else {
            if (m % 2 == 1 && n % 2 == 1) sol = m * n - 1;
            else sol = m * n;
        }

        System.out.println(sol);
    }

    static int[] ints() throws IOException {
        String[] line = br.readLine().split(" ");
        int[] ints = new int[line.length];
        for (int i = 0; i < line.length; i++) ints[i] = Integer.parseInt(line[i]);
        return ints;
    }

    static long[] longs() throws IOException {
        String[] line = br.readLine().split(" ");
        long[] longs = new long[line.length];
        for (int i = 0; i < line.length; i++) longs[i] = Long.parseLong(line[i]);
        return longs;
    }

    static double[] doubles() throws IOException {
        String[] line = br.readLine().split(" ");
        double[] doubles = new double[line.length];
        for (int i = 0; i < line.length; i++) doubles[i] = Double.parseDouble(line[i]);
        return doubles;
    }

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @author Don Li
 */
public class LittleCLoves3II {
    void solve() {
        long n = in.nextInt(), m = in.nextInt();
        if (n > m) {
            long tmp = n; n = m; m = tmp;
        }

        if (n == 1) {
            out.println(m / 6 * 6 + Math.max(m % 6 - 3, 0) * 2);
            return;
        }

        if (n == 2) {
            if (m == 2) out.println(0);
            else if (m == 3) out.println(4);
            else if (m == 7) out.println(12);
            else out.println(n * m);
            return;
        }

        out.println(n * m / 2 * 2);
    }

    public static void main(String[] args) {
        in = new FastScanner(new BufferedReader(new InputStreamReader(System.in)));
        out = new PrintWriter(System.out);
        new LittleCLoves3II().solve();
        out.close();
    }

    static FastScanner in;
    static PrintWriter out;

    static class FastScanner {
        BufferedReader in;
        StringTokenizer st;

        public FastScanner(BufferedReader in) {
            this.in = in;
        }

        public String nextToken() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(in.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(nextToken());
        }

        public long nextLong() {
            return Long.parseLong(nextToken());
        }

        public double nextDouble() {
            return Double.parseDouble(nextToken());
        }
    }
}


import java.io.BufferedInputStream;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner s = new Scanner(new BufferedInputStream(System.in));
		int n = s.nextInt();
		int m = s.nextInt();
		if (n > m) {
			solve(m, n);
		} else {
			solve(n, m);
		}

	}

	private static void solve(int n, int m) {
		if (n == 1) {
			System.out.println(m / 6 * 3 + Math.max(m % 6 - 3, 0) << 1);
		} else if (n == 2) {
			System.out.println(m == 2 ? 0 : m == 3 ? 4 : m == 7 ? 12 : m << 1);
		} else {
			System.out.println(1l * n * m / 2 * 2);
		}

	}
}


/*
Keep solving problems.
*/

import java.util.*;
import java.io.*;

public class CFA {
    BufferedReader br;
    PrintWriter out;
    StringTokenizer st;
    boolean eof;
    private static final long MOD = 998244353L;
    private static final int[] dx = {0, -1, 0, 1};
    private static final int[] dy = {1, 0, -1, 0};
    private static final String yes = "Yes";
    private static final String no = "No";

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

    void solve() throws IOException {
        int n = nextInt();
        int m = nextInt();
        if (n > m) {
            int tmp = n;
            n = m;
            m = tmp;
        }

        if (n == 1) {
            m--;
            int[] left = {0, 0, 0, 2, 4, 6};
            long res = m / 6 * 6 + left[m % 6];
            outln(res);
            return;
        }
        else if (n == 2) {
            if (m < 20) {
                outln(bruteforce(n, m));
            }
            else {
                outln(1L * n * m);
            }
            return;
        }
        else if (n == 3) {
            if (m < 20) {
                outln(bruteforce(n, m));
            }
            else {
                long res = 1L * n * m;
                if (res % 2 != 0) {
                    res--;
                }
                outln(res);
            }
            return;
        }

        if (1L * n * m < 1000) {
            outln(bruteforce(n, m));
            return;
        }
        long res = 1L * n * m;
        if (res % 2 != 0) {
            res--;
        }
        outln(res);
    }

    int bruteforce(int n, int m) {
        List<Point> even = new ArrayList<>();
        List<Point> odd = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                int sum = i + j;
                if (sum % 2 == 0) {
                    even.add(new Point(i, j));
                }
                else {
                    odd.add(new Point(i, j));
                }
            }
        }

        boolean[][] match = new boolean[even.size()][odd.size()];
        for (int i = 0; i < match.length; i++) {
            for (int j = 0; j < match[0].length; j++) {
                int d = Math.abs(even.get(i).x - odd.get(j).x) + Math.abs(even.get(i).y - odd.get(j).y);
                if (d == 3) {
                    match[i][j] = true;
                }
            }
        }

        return 2 * maxMatching(match);
    }

    int maxMatching(boolean[][] graph) {
        int n1 = graph.length;
        int n2 = n1 == 0 ? 0 : graph[0].length;
        int[] matching = new int[n2];
        Arrays.fill(matching, -1);
        int matches = 0;
        for (int u = 0; u < n1; u++)
            if (findPath(graph, u, matching, new boolean[n1]))
                ++matches;
        return matches;
    }

    boolean findPath(boolean[][] graph, int u1, int[] matching, boolean[] vis) {
        vis[u1] = true;
        for (int v = 0; v < matching.length; ++v) {
            int u2 = matching[v];
            if (graph[u1][v] && (u2 == -1 || !vis[u2] && findPath(graph, u2, matching, vis))) {
                matching[v] = u1;
                return true;
            }
        }
        return false;
    }

    void shuffle(int[] a) {
        int n = a.length;
        for(int i = 0; i < n; i++) {
            int r = i + (int) (Math.random() * (n - i));
            int tmp = a[i];
            a[i] = a[r];
            a[r] = tmp;
        }
    }

    long gcd(long a, long b) {
        while(a != 0 && b != 0) {
            long c = b;
            b = a % b;
            a = c;
        }
        return a + b;
    }

    private void outln(Object o) {
        out.println(o);
    }
    private void out(Object o) {
        out.print(o);
    }
    private void formatPrint(double val) {
        System.out.format("%.9f%n", val);
    }
    public CFA() throws IOException {
        br = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        solve();
        out.close();
    }
    public static void main(String[] args) throws IOException {
        new CFA();
    }

    public long[] nextLongArr(int n) throws IOException{
        long[] res = new long[n];
        for(int i = 0; i < n; i++)
            res[i] = nextLong();
        return res;
    }
    public int[] nextIntArr(int n) throws IOException {
        int[] res = new int[n];
        for(int i = 0; i < n; i++)
            res[i] = nextInt();
        return res;
    }
    public String nextToken() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (Exception e) {
                eof = true;
                return null;
            }
        }
        return st.nextToken();
    }
    public String nextString() {
        try {
            return br.readLine();
        } catch (IOException e) {
            eof = true;
            return null;
        }
    }
    public int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }
    public long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }
    public double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }
}


import java.util.*;
import java.io.*;
import java.math.*;
public class Main{

    public static void main(String[] args) throws IOException  {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long m = sc.nextLong();
        long rep = 0;
        if(n>=4&&m>=4){
            if(n%2==0||m%2==0) rep = n*m;
            else rep = n*m-1;
        }
        else{
            long min = Math.min(n,m);
            long max = Math.max(n,m);
            if(min==1){
                rep = max- (max%6);
                if(max%6==4) rep += 2;
                if(max%6==5) rep += 4;
            }
            else if(min==2){
                if(max<3) rep = 0;
                else if(max==3) rep = 4;
                else if(max==7) rep = 12;
                else rep = min * max;
            }
            else if(min==3) {
                if(max<3) rep = 0;
                else {
                    rep = min * max;
                    if(max%2==1) rep--;
                }
            }

        }
        System.out.println(rep);
    }

}


/**
 * Created by Aminul on 9/21/2018.
 */

import java.io.*;
import java.util.*;
import static java.lang.Math.*;

public class D {
    public static void main(String[] args)throws Exception {
        FastReader in = new FastReader(System.in);
        PrintWriter pw = new PrintWriter(System.out);

        long n = in.nextLong(), m = in.nextLong();

        pw.println(solve(n, m));

        pw.close();
    }

    static long solve(long n, long m){
        if(n > m){
            long tmp = n; n = m; m = tmp;
        }
        long res = n*m;
        if(n % 2 == 1 && m % 2 == 1) res--;

        if(n == 1){
            long x = ((n*m)/6)*6;
            long y = (n*m) % 6;
            if(y == 4) x += 2;
            if(y == 5) x += 4;
            return x;
        }
        if(n == 2 && m == 2) return 0;
        if(n == 2 && m == 3) return 4;
        if(n == 2 && m == 7) return 12;

        return res;
    }

    static void debug(Object...obj) {
        System.err.println(Arrays.deepToString(obj));
    }

    static class FastReader {
        InputStream is;
        private byte[] inbuf = new byte[1024];
        private int lenbuf = 0, ptrbuf = 0;

        public FastReader(InputStream is) {
            this.is = is;
        }

        public int readByte() {
            if (lenbuf == -1) throw new InputMismatchException();
            if (ptrbuf >= lenbuf) {
                ptrbuf = 0;
                try {
                    lenbuf = is.read(inbuf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (lenbuf <= 0) return -1;
            }
            return inbuf[ptrbuf++];
        }

        public boolean isSpaceChar(int c) {
            return !(c >= 33 && c <= 126);
        }
        private boolean isEndOfLine(int c) {
            return c == '\n' || c == '\r' || c == -1;
        }

        public int skip() {
            int b;
            while ((b = readByte()) != -1 && isSpaceChar(b)) ;
            return b;
        }

        public String next() {
            int b = skip();
            StringBuilder sb = new StringBuilder();
            while (!(isSpaceChar(b))) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }

        public String nextLine() {
            int c = skip();
            StringBuilder sb = new StringBuilder();
            while (!isEndOfLine(c)){
                sb.appendCodePoint(c);
                c = readByte();
            }
            return sb.toString();
        }

        public int nextInt() {
            int num = 0, b;
            boolean 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 << 3) + (num << 1) + (b - '0');
                } else {
                    return minus ? -num : num;
                }
                b = readByte();
            }
        }

        public long nextLong() {
            long num = 0;
            int b;
            boolean 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 << 3) + (num << 1) + (b - '0');
                } else {
                    return minus ? -num : num;
                }
                b = readByte();
            }
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public char[] next(int n) {
            char[] buf = new char[n];
            int b = skip(), p = 0;
            while (p < n && !(isSpaceChar(b))) {
                buf[p++] = (char) b;
                b = readByte();
            }
            return n == p ? buf : Arrays.copyOf(buf, p);
        }

        public char readChar() {
            return (char) skip();
        }
    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.ArrayDeque;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author prakharjain
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        _1047D solver = new _1047D();
        solver.solve(1, in, out);
        out.close();
    }

    static class _1047D {
        int n;
        int m;

        public void solve(int testNumber, InputReader in, OutputWriter out) {
            n = in.nextInt();
            m = in.nextInt();

            long ans = 0;

            if (n > 100) {
                int nn = (n - 100) % 6;
                long nq = (n - 100) / 6;
                ans += nq * 6 * m;
                n = 100 + nn;
            }

            if (m > 100) {
                int nm = (m - 100) % 6;
                long mq = (m - 100) / 6;
                ans += mq * 6 * n;
                m = 100 + nm;
            }

            int[][] mat = new int[n + 1][m + 1];

            int u = 1;
            int v = 1;
            for (int i = 1; i <= n; i++) {
                for (int j = 1; j <= m; j++) {
                    if ((i + j) % 2 == 0) {
                        mat[i][j] = u;
                        u++;
                    }
                }
            }

            for (int i = 1; i <= n; i++) {
                for (int j = 1; j <= m; j++) {
                    if ((i + j) % 2 != 0) {
                        mat[i][j] = v;
                        v++;
                    }
                }
            }

            List[] g = new List[u];

            for (int i = 0; i < u; i++) {
                g[i] = new ArrayList();
            }

            for (int i = 1; i <= n; i++) {
                for (int j = 1; j <= m; j++) {
                    if ((i + j) % 2 == 0) {
                        addEdge(mat, g, i, j, i - 3, j);
                        addEdge(mat, g, i, j, i - 2, j - 1);
                        addEdge(mat, g, i, j, i - 2, j + 1);
                        addEdge(mat, g, i, j, i, j - 3);
                        addEdge(mat, g, i, j, i - 1, j - 2);
                        addEdge(mat, g, i, j, i + 1, j - 2);
                        addEdge(mat, g, i, j, i, j + 3);
                        addEdge(mat, g, i, j, i - 1, j + 2);
                        addEdge(mat, g, i, j, i + 1, j + 2);
                        addEdge(mat, g, i, j, i + 3, j);
                        addEdge(mat, g, i, j, i + 2, j - 1);
                        addEdge(mat, g, i, j, i + 2, j + 1);
                    }
                }
            }

            HopcroftKarpBipartiteMatching bpm = new HopcroftKarpBipartiteMatching(u - 1, v - 1, g);

            ans += 2 * bpm.maximumMatching();

            out.println(ans);
        }

        void addEdge(int[][] mat, List[] g, int i, int j, int s, int t) {
            if (s <= 0 || t <= 0 || s > n || t > m)
                return;

            g[mat[i][j]].add(mat[s][t]);
        }

        class HopcroftKarpBipartiteMatching {
            int m;
            int n;
            List[] g;
            int[] pairU;
            int[] pairV;
            int[] dis;
            int inf = 10000000;
            int NIL = 0;

            public HopcroftKarpBipartiteMatching(int m, int n, List[] g) {
                this.m = m;
                this.n = n;
                this.g = g;
                this.pairU = new int[m + 1];
                this.pairV = new int[n + 1];
                this.dis = new int[m + 1];
            }

            int maximumMatching() {

                Arrays.fill(pairU, NIL);
                Arrays.fill(pairV, NIL);

                int maxMatching = 0;

                while (bfs()) {
                    for (int i = 1; i <= m; i++) {
                        if (pairU[i] == NIL && dfs(i))
                            maxMatching++;
                    }
                }

                return maxMatching;
            }

            boolean bfs() {

                ArrayDeque<Integer> queue = new ArrayDeque<>();

                for (int i = 1; i <= m; i++) {
                    if (pairU[i] == NIL) {
                        queue.addLast(i);
                        dis[i] = 0;
                    } else {
                        dis[i] = inf;
                    }
                }

                dis[NIL] = inf;

                while (!queue.isEmpty()) {
                    int u = queue.removeFirst();

                    if (dis[u] < dis[NIL]) {
                        for (int v : (List<Integer>) g[u]) {
                            if (dis[pairV[v]] == inf) {
                                queue.addLast(pairV[v]);
                                dis[pairV[v]] = dis[u] + 2;
                            }
                        }
                    }
                }

                return dis[NIL] < inf;
            }

            boolean dfs(int u) {
                if (u != NIL) {
                    for (int v : (List<Integer>) g[u]) {
                        if (dis[pairV[v]] == dis[u] + 2) {
                            if (dfs(pairV[v])) {
                                pairV[v] = u;
                                pairU[u] = v;
                                return true;
                            }
                        }
                    }
                    dis[u] = inf;
                    return false;
                } else
                    return true;
            }

        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void close() {
            writer.close();
        }

        public void println(long i) {
            writer.println(i);
        }

    }
}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class B {
	static PrintWriter out = new PrintWriter(System.out);

	public static void main(String[] args) {
		FS in = new FS();
		long R = in.nextLong();
		long C = in.nextLong();
		long res = solve(Math.min(R, C), Math.max(R, C));
		out.println(res);
		out.close();
	}

	static long solve(long r, long c) {
		if(r < 3 && c < 3) return 0;
		if(r == 1) {
			long res = c;
			long m = c%6;
			if(m != 0) {
				if(m <= 3) res -= m;
				if(m == 4) res -= 2;
				if(m == 5) res -= 1;
			}
			return res;
		}
		if(r == 2) {
			if(c == 3 || c == 7) return r * (c-1);
			return r*c;
		}
		long res = r*c;
		if(res%2 == 0) return res;
		return res-1;
	}

//	static long solve(long r, long c) {
//		if(r > c) {
//			long tmp = r;
//			r = c;
//			c = tmp;
//		}
//		if(r < 3 && c < 3) return 0;
//
//		long res = 0;
//		long sp = (c%2 == 1 ? 1 : 0);
//		long s = c/2;
//
//		//see if anyone gets left out
//		long hd = s + sp;
//		if(hd >= 3 || ) res = s*r;

//		res += solve(sp, r);
//	}

	static class FS{
		BufferedReader br;
		StringTokenizer st;
		public FS() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
		String next() {
			while(st == null || !st.hasMoreElements()) {
				try {st = new StringTokenizer(br.readLine());}
				catch(Exception e) { throw null;}
			}
			return st.nextToken();
		}
		int nextInt() { return Integer.parseInt(next());}
		double nextDouble() { return Double.parseDouble(next());}
		long nextLong() { return Long.parseLong(next());}
		int[] NIA(int n) {
			int r[] = new int[n];
			for(int i = 0; i < n; i++) r[i] = nextInt();
			return r;
		}
		long[] NLA(int n) {
			long r[] = new long[n];
			for(int i = 0; i < n; i++) r[i] = nextLong();
			return r;
		}
		char[][] grid(int r, int c){
			char res[][] = new char[r][c];
			for(int i = 0; i < r; i++) {
				char l[] = next().toCharArray();
				for(int j = 0; j < c; j++) {
					res[i][j] = l[j];
				}
			}
			return res;
		}
	}

}


import java.util.Arrays;
import java.util.Scanner;

public class P1047D
{
	static int[][] grid;
	static int R, C;
	public static void main(String[] args)
	{
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int m = scan.nextInt();
		long min = Math.min(n, m);
		long max = Math.max(n, m);
		if (min == 1)
			System.out.println(max/6*6 + 2*Math.max(0, max%6-3));
		else if (min == 2 && max == 2)
			System.out.println(0);
		else if (min == 2 && max == 3)
			System.out.println(4);
		else if (min == 3 && max == 3)
			System.out.println(8);
		else if (min == 2 && max == 7)
			System.out.println(12);
		else if (max%2 == 0)
			System.out.println(min*max);
		else // if (max%2 == 1)
			System.out.println(min*max - min*max%2);
	}
	private static boolean can(int cur, int r, int c)
	{
		if (cur > R*C/2)
		{
//			for (int i = 0; i < grid.length; i++)
//			{
//				for (int j = 0; j < grid[0].length; j++)
//					System.out.printf("%3d", grid[i][j]);
//				System.out.println();
//			}
//			System.out.println();
			return true;
		}
		if (c >= C)
			return can(cur, r+1, 0);
		if (grid[r][c] != 0)
			return can(cur, r, c+1);
		grid[r][c] = cur;
		for (int dr = 0; dr <= 3; dr++)
		{
			for (int dc = -2; dc <= 3; dc++)
			{
				if (dr+Math.abs(dc) != 3)
					continue;
				if (ok(r+dr, c+dc))
				{
					grid[r+dr][c+dc] = cur;
					if (can(cur+1, r, c+1))
						return true;
					grid[r+dr][c+dc] = 0;
				}
			}
		}
		grid[r][c] = 0;
		return false;
	}
	private static boolean ok(int r, int c)
	{
		return r >= 0 && c >= 0 && r < R && c < C && grid[r][c] == 0;
	}
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.io.UncheckedIOException;
import java.util.List;
import java.io.Closeable;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) throws Exception {
        Thread thread = new Thread(null, new TaskAdapter(), "", 1 << 27);
        thread.start();
        thread.join();
    }

    static class TaskAdapter implements Runnable {
        @Override
        public void run() {
            InputStream inputStream = System.in;
            OutputStream outputStream = System.out;
            FastInput in = new FastInput(inputStream);
            FastOutput out = new FastOutput(outputStream);
            BLittleCLoves3II solver = new BLittleCLoves3II();
            solver.solve(1, in, out);
            out.close();
        }
    }

    static class BLittleCLoves3II {
        int n;
        int m;

        public void solve(int testNumber, FastInput in, FastOutput out) {
            n = in.readInt();
            m = in.readInt();

            long ans = 0;
            int remain = 30;
            if (n > remain) {
                int extra = n - remain;
                ans += (long) (extra - extra % 6) * m;
                n -= extra - extra % 6;
            }
            if (m > remain) {
                int extra = m - remain;
                ans += (long) (extra - extra % 6) * n;
                m -= extra - extra % 6;
            }

            KMAlgo km = new KMAlgo(n * m, n * m);
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    if ((i + j) % 2 != 0) {
                        continue;
                    }
                    for (int k = 0; k < n; k++) {
                        for (int t = 0; t < m; t++) {
                            if ((k + t) % 2 != 1) {
                                continue;
                            }
                            if (Math.abs(i - k) + Math.abs(j - t) == 3) {
                                km.addEdge(cellId(i, j), cellId(k, t), true);
                            }
                        }
                    }
                }
            }

            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    if (km.matchLeft(cellId(i, j))) {
                        ans += 2;
                    }
                }
            }

            out.println(ans);
        }

        int cellId(int i, int j) {
            return i * m + j;
        }

    }

    static class FastInput {
        private final InputStream is;
        private byte[] buf = new byte[1 << 20];
        private int bufLen;
        private int bufOffset;
        private int next;

        public FastInput(InputStream is) {
            this.is = is;
        }

        private int read() {
            while (bufLen == bufOffset) {
                bufOffset = 0;
                try {
                    bufLen = is.read(buf);
                } catch (IOException e) {
                    bufLen = -1;
                }
                if (bufLen == -1) {
                    return -1;
                }
            }
            return buf[bufOffset++];
        }

        public void skipBlank() {
            while (next >= 0 && next <= 32) {
                next = read();
            }
        }

        public int readInt() {
            int sign = 1;

            skipBlank();
            if (next == '+' || next == '-') {
                sign = next == '+' ? 1 : -1;
                next = read();
            }

            int val = 0;
            if (sign == 1) {
                while (next >= '0' && next <= '9') {
                    val = val * 10 + next - '0';
                    next = read();
                }
            } else {
                while (next >= '0' && next <= '9') {
                    val = val * 10 - next + '0';
                    next = read();
                }
            }

            return val;
        }

    }

    static class FastOutput implements AutoCloseable, Closeable, Appendable {
        private StringBuilder cache = new StringBuilder(10 << 20);
        private final Writer os;

        public FastOutput append(CharSequence csq) {
            cache.append(csq);
            return this;
        }

        public FastOutput append(CharSequence csq, int start, int end) {
            cache.append(csq, start, end);
            return this;
        }

        public FastOutput(Writer os) {
            this.os = os;
        }

        public FastOutput(OutputStream os) {
            this(new OutputStreamWriter(os));
        }

        public FastOutput append(char c) {
            cache.append(c);
            return this;
        }

        public FastOutput println(long c) {
            cache.append(c);
            println();
            return this;
        }

        public FastOutput println() {
            cache.append(System.lineSeparator());
            return this;
        }

        public FastOutput flush() {
            try {
                os.append(cache);
                os.flush();
                cache.setLength(0);
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
            return this;
        }

        public void close() {
            flush();
            try {
                os.close();
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
        }

        public String toString() {
            return cache.toString();
        }

    }

    static class KMAlgo {
        KMAlgo.Node[] leftSides;
        KMAlgo.Node[] rightSides;
        int version;

        public KMAlgo(int l, int r) {
            leftSides = new KMAlgo.Node[l];
            for (int i = 0; i < l; i++) {
                leftSides[i] = new KMAlgo.Node();
                leftSides[i].id = i;
                leftSides[i].leftSide = true;
            }
            rightSides = new KMAlgo.Node[r];
            for (int i = 0; i < r; i++) {
                rightSides[i] = new KMAlgo.Node();
                rightSides[i].id = i;
            }
        }

        public void addEdge(int lId, int rId, boolean urge) {
            leftSides[lId].nodes.add(rightSides[rId]);
            rightSides[rId].nodes.add(leftSides[lId]);
            if (urge && leftSides[lId].partner == null && rightSides[rId].partner == null) {
                leftSides[lId].partner = rightSides[rId];
                rightSides[rId].partner = leftSides[lId];
            }
        }

        private void prepare() {
            version++;
        }

        public boolean matchLeft(int id) {
            if (leftSides[id].partner != null) {
                return true;
            }
            prepare();
            return findPartner(leftSides[id]);
        }

        private boolean findPartner(KMAlgo.Node src) {
            if (src.visited == version) {
                return false;
            }
            src.visited = version;
            for (KMAlgo.Node node : src.nodes) {
                if (!tryRelease(node)) {
                    continue;
                }
                node.partner = src;
                src.partner = node;
                return true;
            }
            return false;
        }

        private boolean tryRelease(KMAlgo.Node src) {
            if (src.visited == version) {
                return false;
            }
            src.visited = version;
            if (src.partner == null) {
                return true;
            }
            if (findPartner(src.partner)) {
                src.partner = null;
                return true;
            }
            return false;
        }

        public String toString() {
            StringBuilder builder = new StringBuilder();
            for (int i = 0; i < leftSides.length; i++) {
                if (leftSides[i].partner == null) {
                    continue;
                }
                builder.append(leftSides[i].id).append(" - ").append(leftSides[i].partner.id).append("\n");
            }
            return builder.toString();
        }

        public static class Node {
            List<KMAlgo.Node> nodes = new ArrayList<>();
            int visited;
            KMAlgo.Node partner;
            int id;
            boolean leftSide;

            public String toString() {
                return "" + id;
            }

        }

    }
}


import java.io.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.text.DecimalFormat;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    static StreamTokenizer in=new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
    static int nextInt() throws IOException{
        in.nextToken();
        return (int)in.nval;
    }
    static double nextDouble() throws IOException{
        in.nextToken();
        return in.nval;
    }
    static PrintWriter out =new PrintWriter(new OutputStreamWriter(System.out));
    static int t;
    static long n,m;
    static int ans;
    //static Scanner jin=new Scanner(System.in);

    public static void main(String args[])throws IOException{
        n = nextInt();
        m = nextInt();
        if(n>m){
            long tmp = m;
            m = n;
            n =tmp;
        }
        if(n == 1){
            if(m%6==0){
                out.println(n*m);
            }
            else if(m%6==1){
                out.println(n*m-1);
            }
            else if(m%6==2){
                out.println(n*m-2);
            }
            else if(m%6==3){
                out.println(n*m-3);
            }
            else if(m%6==4){
                out.println(n*m-2);
            }
            else if(m%6==5){
                out.println(n*m-1);
            }
        }
        else if(n == 2){
            if(m==2){
                out.println(n*m-4);
            }
            else if(m==3){
                out.println(n*m-2);
            }
            else if(m==7){
                out.println(n*m-2);
            }
            else{
                out.println(n*m);
            }
        }
        else if(n == 3){
            if(m%2==0){
                out.println(n*m);
            }
            else if(m%2==1){
                out.println(n*m-1);
            }
        }
        else{
            if(n%2==1&&m%2==1){
                out.println(n*m-1);
            }
            else{
                out.println(n*m);
            }
        }
        out.flush();
    }
}


import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Queue;
import java.util.Random;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

import static java.util.Arrays.fill;

/**
 * Created by timur on 28.03.15.
 */

public class TaskD {
    boolean eof;
    BufferedReader br;
    StringTokenizer st;
    PrintWriter out;

    public static void main(String[] args) throws IOException {
        new TaskD().run();
    }

    public String nextToken() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (Exception e) {
                eof = true;
                return "-1";
            }
        }
        return st.nextToken();
    }

    public int nextInt() {
        return Integer.parseInt(nextToken());
    }

    public long nextLong() {
        return Long.parseLong(nextToken());
    }

    double nextDouble() {
        return Double.parseDouble(nextToken());
    }

    String nextLine() throws IOException {
        return br.readLine();
    }

    void run() throws IOException {
        InputStream input = System.in;
        PrintStream output = System.out;
        try {
            File f = new File("a.in");
            if (f.exists() && f.canRead()) {
                input = new FileInputStream(f);
                output = new PrintStream("a.out");
            }
        } catch (Throwable e) {
        }
        br = new BufferedReader(new InputStreamReader(input));
        out = new PrintWriter(output);
        solve();
        br.close();
        out.close();
    }

    void solve() {
        long n = nextLong(), m = nextLong();
        long x;
        if (n > m) {
            x = m;
            m = n;
            n = x;
        }
        if (n > 3) {
            out.print(n * m - (n * m) % 2);
        } else {
            long s = m - m % 6;
            long h = 0, o = m % 6;
            if (n == 1) {
                if (o == 4) {
                    h = 2;
                } else if (o == 5) {
                    h = 4;
                } else {
                    h = 0;
                }
            } else if (n == 2) {
                if (o == 3) {
                    h = 4;
                } else if (o == 4) {
                    h = 8;
                } else if (o == 5) {
                    h = 10;
                } else {
                    h = 0;
                }
            } else if (n == 3) {
                if (o == 2) {
                    h = 4;
                } else if (o == 3) {
                    h = 8;
                } else if (o == 4) {
                    h = 12;
                } else if (o == 5) {
                    h = 14;
                } else {
                    h = 0;
                }
            }
            if (n + m > 9 && n > 1) {
                out.print(n * m - (n * m) % 2);
                return;
            }
            out.print(s * n + h);
        }

    }

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
744444444747477777774
44444447474747777777
 */

/**
 *
 * @author Andy Phan
 */
public class b {
    public static void main(String[] args) {
        FS in = new FS(System.in);
        PrintWriter out = new PrintWriter(System.out);

        int n = in.nextInt();
        int m = in.nextInt();
        if(n > m) {
            n ^= m;
            m ^= n;
            n ^= m;
        }
        if(n > 2) System.out.println((long)n*m/2*2);
        else if(n == 1) System.out.println(m/6*6+2*Math.max((m%6-3), 0));
        else if(m == 2) System.out.println(0);
        else if(m == 3) System.out.println(4);
        else if(m == 7) System.out.println(12);
        else System.out.println(2*m);

        out.close();
    }

    static class FS {

        BufferedReader in;
        StringTokenizer token;

        public FS(InputStream str) {
            in = new BufferedReader(new InputStreamReader(str));
        }

        public String next() {
            if (token == null || !token.hasMoreElements()) {
                try {
                    token = new StringTokenizer(in.readLine());
                } catch (IOException ex) {
                }
                return next();
            }
            return token.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }
    }
}