def ii(): S = input() return map(int,S.split()) if " " in S else int(S) def ai(N = 0): return [list(map(int,input().split())) for _ in range(N)] if N!= 0 else list(map(int,input().split())) def yn(BOOL): print("Yes" if BOOL==1 else "No") import sys,math,heapq,bisect from collections import defaultdict X,Y = ii() n = X*Y print(n,n) for y in range(Y-1): for x in range(X): print(x+1+y*X,x+1+(y+1)*X) for x in range(X): print(x+1+X*(Y-1),(x+1)%X+1+X*(Y-1))