# Enter your code here. Read input from STDIN. Print output to STDOUT m, n = map(long, raw_input().split()) import sys def divide(m, n, memory): key = str(m) + "_" + str(n) if key in memory: return memory[key] if m == 1 and n == 1: memory[key] = 0 return memory[key] elif (m == 2 and n == 1) or (m == 1 and n == 2): memory[key] = 1 return memory[key] ret = sys.maxint for i in xrange(1, m): ret = min(ret, divide(i, n, memory) + divide(m-i, n, memory) + 1) for i in xrange(1, n): ret = min(ret, divide(m, i, memory) + divide(m, n-i, memory) + 1) memory[key] = ret return ret def divideDp(m, n): dp = [[long(0) for i in xrange(n+1)] for j in xrange(m+1)] for i in xrange(1, n+1): dp[1][i] = i-1 for i in xrange(1, m+1): dp[i][1] = i-1 for i in xrange(2, m+1): for j in xrange(2, n+1): row, col, val = i, j, sys.maxint for k in xrange(1, row): val = min(val, dp[k][col] + dp[row-k][col] + 1) for k in xrange(1, col): val = min(val, dp[row][k] + dp[row][col-k] + 1) dp[i][j] = val return dp[m][n] print min(m-1+(n-1)*m, n-1+(m-1)*n) #print divide(m, n, {})