import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int m = sc.nextInt(); Map storage = new HashMap(); System.out.println(calculateCutCount(n, m, storage)); } public static long calculateCutCount(long n, long m, Map storage) { if (storage.containsKey(n + ":" + m)) { return storage.get(n + ":" + m); } if (n == 1) return m - 1; if (m == 1) return n - 1; long result = 0; if (n > m) { if (n % 2 == 0) { result = 1 + (2 * calculateCutCount(n / 2, m, storage)); } else { result = 1 + calculateCutCount(n / 2, m, storage) + calculateCutCount(n / 2 + (n % 2), m, storage); } } else { if (m % 2 == 0) { result = 1 + (2 * calculateCutCount(n, m / 2, storage)); } else { result = 1 + calculateCutCount(n, m / 2, storage) + calculateCutCount(n, m / 2 + (m % 2), storage); } } storage.put(n + ":" + m, result); return result; } }