[n, m] = map(int, input().split())
if n % m == 0 or m % n == 0:
print(n + m - 2)
else:
print(n + m - 1)
def get_pairs(a, b):
if a > b:
return [(t[1], t[0]) for t in get_pairs(b, a)]
elif a == 1:
return [(1, k) for k in range(1, b + 1)]
elif a == b:
ans = [(k, 1) for k in range(1, a + 1)]
ans += [(k, b) for k in range(2, a)]
return ans
else:
num = b // a
ans = [(k, 1 + a * x) for k in range(1, a + 1) for x in range(num)]
ans += [(t[0], t[1] + a * num) for t in get_pairs(a, b % a)]
return ans
ans = get_pairs(n, m)
for t in ans:
print(t[0], t[1])