# Enter your code here. Read input from STDIN. Print output to STDOUT def num_cuts(n, m, cache): if n == 1 and m == 1: return 0 big_side = max(n, m) small_side = min(n, m) if small_side == 1: return big_side - 1 elif (big_side, small_side) in cache: return cache[(big_side, small_side)] cut_point = big_side / 2 cuts = 1 + num_cuts(cut_point, small_side, cache) + num_cuts(big_side - cut_point, small_side, cache) cache[(big_side, small_side)] = cuts return cuts n, m = map(int, raw_input().strip().split(' ')) c = {} print(num_cuts(n, m, c))