
def a(a, b)
  return a if a==b
  if a < b
    return largeHandle(a, b, a, b)
  else
    return largeHandle(b, a, b, a)
  end
end
def largeHandle(s, l, ss, ll)
  return s if s==l
  result = s+ss
  return result if result == l
  if result > l
    largeHandle(result, l+ll, ss, ll)
  else
    largeHandle(result, l, ss, ll)
  end
end
a, b = gets.chop.split.map(&:to_i)
print a(a, b)