import java.io.*; import java.util.*; public class Solution { Map> cache; public long minCut(int m, int n){ cache = new HashMap<>(); return minCut_cached(m, n); } public long minCut_cached(int m, int n){ if (m == 1 && n == 1){ return 0; } if (cache.containsKey(m) && cache.get(m).containsKey(n)){ return cache.get(m).get(n); } int min = Math.min(m, n); int max = Math.max(m, n); cache.putIfAbsent(m, new HashMap<>()); cache.get(m).put(n, minCut_cached(max / 2, min) + minCut_cached(max - max / 2, min) + 1); return cache.get(m).get(n); } public static void main(String[] args) { Scanner in = new Scanner(System.in); String[] input = in.nextLine().split("\\s+"); Integer m = Integer.parseInt(input[0]); Integer n = Integer.parseInt(input[1]); Solution soln = new Solution(); System.out.println(soln.minCut(m, n)); } }