import java.util.Scanner; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); long n = sc.nextInt(); long m = sc.nextInt(); sc.close(); if (n == 1) { System.out.println(0); } else if (n % 2 == 0) { System.out.println(n * m); } else { long v1 = (n - 3) * m; long v2 = 0; int cnt = 0; for (int i = 30; i >= 0; i--) { if ((m >> i & 1) == 1) { cnt++; v2 += 1L << i; } else if (cnt >= 2) { v2 += 1L << i; } } System.out.println(v1 + v2 * 2); } } }