This morning Tolik has understood that while he was sleeping he had invented an incredible problem which will be a perfect fit for Codeforces! But, as a "Discuss tasks" project hasn't been born yet (in English, well), he decides to test a problem and asks his uncle.

After a long time thinking, Tolik's uncle hasn't any ideas on how to solve it. But, he doesn't want to tell Tolik about his inability to solve it, so he hasn't found anything better than asking you how to solve this task.

In this task you are given a cell field $n \cdot m$, consisting of $n$ rows and $m$ columns, where point's coordinates $(x, y)$ mean it is situated in the $x$-th row and $y$-th column, considering numeration from one ($1 \leq x \leq n, 1 \leq y \leq m$). Initially, you stand in the cell $(1, 1)$. Every move you can jump from cell $(x, y)$, which you stand in, by any non-zero vector $(dx, dy)$, thus you will stand in the $(x+dx, y+dy)$ cell. Obviously, you can't leave the field, but also there is one more important condition — you're not allowed to use one vector twice. Your task is to visit each cell of the field exactly once (the initial cell is considered as already visited).

Tolik's uncle is a very respectful person. Help him to solve this task!


-----Input-----

The first and only line contains two positive integers $n, m$ ($1 \leq n \cdot m \leq 10^{6}$) — the number of rows and columns of the field respectively.


-----Output-----

Print "-1" (without quotes) if it is impossible to visit every cell exactly once.

Else print $n \cdot m$ pairs of integers, $i$-th from them should contain two integers $x_i, y_i$ ($1 \leq x_i \leq n, 1 \leq y_i \leq m$) — cells of the field in order of visiting, so that all of them are distinct and vectors of jumps between them are distinct too.

Notice that the first cell should have $(1, 1)$ coordinates, according to the statement.


-----Examples-----
Input
2 3

Output
1 1
1 3
1 2
2 2
2 3
2 1
Input
1 1

Output
1 1



-----Note-----

The vectors from the first example in the order of making jumps are $(0, 2), (0, -1), (1, 0), (0, 1), (0, -2)$.

Source: codeforces | Difficulty: MEDIUM_HARD
Tags: Constructive algorithms


Solutions:
import sys
IS_LOCAL = False

def readMultiple(f):
	return f(map(int, input().split()))

def main():
	(n, m) = (2, 3)
	if not IS_LOCAL:
		(n, m) = readMultiple(tuple)
	if n * m == 1:
		print(1, 1)
		return
	res = []
	for row in range((n + 1) // 2):
		rev_row = n - row
		cell_cnt = m if rev_row != row + 1 else (m + 1) // 2
		for i in range(cell_cnt):
			res.append(f'{row + 1} {i + 1}')
			if not (row + 1 == rev_row and i + 1 == m - i):
				res.append(f'{rev_row} {m - i}')
	print('\n'.join(res))
if len(sys.argv) > 1 and sys.argv[1] == 'True':
	IS_LOCAL = True
main()


import sys
(N, M) = map(int, input().split())
Ans = [(0, 0) for _ in range(N * M)]
for i in range(1, N * M + 1):
	if i % 2:
		(a, b) = divmod(i // 2, M)
	else:
		(a, b) = divmod(N * M - i // 2, M)
	Ans[i - 1] = ' '.join((str(a + 1), str(b + 1)))
for a in Ans:
	sys.stdout.write(f'{a}\n')


import sys
input = sys.stdin.readline
(n, m) = list(map(int, input().split()))
ANS = []
for i in range(1, n // 2 + 1):
	for j in range(1, m + 1):
		sys.stdout.write(''.join((str(i), ' ', str(j), '\n')))
		sys.stdout.write(''.join((str(n - i + 1), ' ', str(m - j + 1), '\n')))
if n % 2 == 1:
	for j in range(1, m // 2 + 1):
		sys.stdout.write(''.join((str(n // 2 + 1), ' ', str(j), '\n')))
		sys.stdout.write(''.join((str(n // 2 + 1), ' ', str(m - j + 1), '\n')))
	if m % 2 == 1:
		sys.stdout.write(''.join((str(n // 2 + 1), ' ', str(m // 2 + 1), '\n')))


from sys import stdin, stdout
(n, m) = [int(x) for x in stdin.readline().split()]
if n == 2:
	c = 1
	way = []
	mult = 1
	for x in range(m - 1, -1, -1):
		way.append(c)
		c += x * mult
		mult *= -1
	for x in way:
		print(1, x)
	for x in way[::-1]:
		print(2, x)
elif n == 1:
	c = 1
	way = []
	mult = 1
	for x in range(m - 1, -1, -1):
		way.append(c)
		c += x * mult
		mult *= -1
	for x in way:
		print(1, x)
elif m == 2:
	c = 1
	way = []
	mult = 1
	for x in range(n - 1, -1, -1):
		way.append(c)
		c += x * mult
		mult *= -1
	for x in way:
		print(x, 1)
	for x in way[:-1:-1]:
		print(x, 2)
elif m == 1:
	c = 1
	way = []
	mult = 1
	for x in range(n - 1, -1, -1):
		way.append(c)
		c += x * mult
		mult *= -1
	for x in way:
		print(x, 1)
else:
	outStr = ''
	for x in range(n // 2):
		for y in range(1, m + 1):
			stdout.write(str(x + 1) + ' ' + str(y) + '\n')
			stdout.write(str(n - x) + ' ' + str(m + 1 - y) + '\n')
	if n % 2 == 1:
		c = 1
		way = []
		mult = 1
		for x in range(m - 1, -1, -1):
			way.append(c)
			c += x * mult
			mult *= -1
		for x in way:
			stdout.write(str(n // 2 + 1) + ' ' + str(x) + '\n')


import sys
(m, n) = [int(i) for i in input().split()]
data = [0] * (m + 1)
for i in range((m + 1) // 2):
	data[2 * i] = i + 1
	data[2 * i + 1] = m - i
for x in range(n // 2):
	for i in range(m):
		sys.stdout.write(str(i + 1) + ' ' + str(x + 1) + '\n')
		sys.stdout.write(str(m - i) + ' ' + str(n - x) + '\n')
if n % 2 == 1:
	q = (n + 1) // 2
	s = ' ' + str(q) + '\n'
	for i in range(m):
		sys.stdout.write(str(data[i]) + s)


(n, m) = list(map(int, input().strip().split()))
for row in range(1, n // 2 + 1):
	for col in range(1, m + 1):
		print(str(row) + ' ' + str(col))
		print(str(n + 1 - row) + ' ' + str(m + 1 - col))
if n % 2 == 1:
	row = n // 2 + 1
	for col in range(1, m // 2 + 1):
		print(str(row) + ' ' + str(col))
		print(str(row) + ' ' + str(m + 1 - col))
	if m % 2 == 1:
		print(str(row) + ' ' + str(m // 2 + 1))


def main():
	(n, m) = list(map(int, input().split()))
	r = []
	rappend = r.append
	for i in range(1, (n >> 1) + 1):
		for j in range(1, m + 1):
			rappend(str(i) + ' ' + str(j))
			rappend(str(n + 1 - i) + ' ' + str(m + 1 - j))
	if n & 1:
		for i in range(1, (m >> 1) + 1):
			rappend(str(n + 1 >> 1) + ' ' + str(i))
			rappend(str(n + 1 >> 1) + ' ' + str(m + 1 - i))
		if m & 1:
			rappend(str(n + 1 >> 1) + ' ' + str(m + 1 >> 1))
	print('\n'.join(r))
main()


import sys
(n, m) = map(int, input().split())
for i in range(n // 2):
	for j in range(m):
		sys.stdout.write('{} {}\n'.format(*[i + 1, j + 1]))
		sys.stdout.write('{} {}\n'.format(*[n - i, m - j]))
if n % 2:
	for j in range(m // 2):
		sys.stdout.write('{} {}\n'.format(*[n // 2 + 1, j + 1]))
		sys.stdout.write('{} {}\n'.format(*[n // 2 + 1, m - j]))
	if m % 2:
		sys.stdout.write('{} {}\n'.format(*[n // 2 + 1, m // 2 + 1]))


(n, m) = tuple(map(int, input().split()))
if n == 1 and m == 1:
	print('1 1')
	exit()

def onerow(r, m):
	for i in range(1, (m + 1) // 2 + 1):
		print(str(r) + ' ' + str(i))
		if m % 2 == 0 or i != (m + 1) // 2:
			print(str(r) + ' ' + str(m + 1 - i))

def tworow(r1, r2, m):
	for i in range(1, m + 1):
		print(str(r1) + ' ' + str(i))
		print(str(r2) + ' ' + str(m + 1 - i))
if n % 2 == 0:
	for i in range(1, n // 2 + 1):
		tworow(i, n + 1 - i, m)
if n % 2 == 1:
	for i in range(1, n // 2 + 1):
		tworow(i, n + 1 - i, m)
	onerow(n // 2 + 1, m)


import sys
input = sys.stdin.readline
(n, m) = map(int, input().split())
for i in range(n // 2 + n % 2):
	x1 = i + 1
	x2 = n - i
	if x1 == x2:
		for j in range(m // 2 + m % 2):
			if j + 1 == m - j:
				sys.stdout.write(str(x1) + ' ' + str(j + 1) + '\n')
			else:
				sys.stdout.write(str(x1) + ' ' + str(j + 1) + '\n')
				sys.stdout.write(str(x2) + ' ' + str(m - j) + '\n')
	elif i % 2 == 0:
		for j in range(m):
			sys.stdout.write(str(x1) + ' ' + str(j + 1) + '\n')
			sys.stdout.write(str(x2) + ' ' + str(m - j) + '\n')
	else:
		for j in range(m):
			sys.stdout.write(str(x1) + ' ' + str(m - j) + '\n')
			sys.stdout.write(str(x2) + ' ' + str(j + 1) + '\n')


(n, m) = list(map(int, input().split()))
ans = []
10000 ** 10000
for i in range(n // 2):
	for j in range(m):
		ans.append(str(i + 1) + ' ' + str(j + 1))
		ans.append(str(n - i) + ' ' + str(m - j))
if n % 2:
	i = n // 2 + 1
	for j in range(m // 2):
		ans.append(str(i) + ' ' + str(j + 1))
		ans.append(str(i) + ' ' + str(m - j))
	if m % 2:
		ans.append(str(i) + ' ' + str(m // 2 + 1))
print('\n'.join(ans))


from sys import stdin, stdout
(n, m) = map(int, input().split())
(l, r) = (1, m)
while l < r:
	for i in range(1, n + 1):
		stdout.write('{} {}\n{} {}'.format(i, l, n - i + 1, r) + '\n')
	l += 1
	r -= 1
(lx, rx) = (1, n)
if l == r:
	for i in range(1, n + 1):
		if i & 1:
			stdout.write('{} {}\n'.format(lx, l))
			lx += 1
		else:
			stdout.write('{} {}\n'.format(rx, r))
			rx -= 1


import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
import collections
from itertools import permutations
from collections import defaultdict
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
(n, m) = map(int, input().split())
x = n // 2
y = m // 2
ch = 0
for i in range(x):
	for j in range(m):
		print(i + 1, j + 1)
		print(n - i, m - j)
if n % 2 == 1:
	for i in range(y):
		print(x + 1, i + 1)
		print(x + 1, m - i)
	if m % 2 == 1:
		print(x + 1, y + 1)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
(n, m) = map(int, input().split())
cnt = 0
i1 = 0
j1 = 0
i2 = n - 1
j2 = m - 1
while cnt < n * m:
	if cnt % 2 == 0:
		print(i1 + 1, j1 + 1)
		if j1 == m - 1:
			i1 += 1
			j1 = 0
		else:
			j1 += 1
	else:
		print(i2 + 1, j2 + 1)
		if j2 == 0:
			j2 = m - 1
			i2 -= 1
		else:
			j2 -= 1
	cnt += 1


import math
import sys
(n, m) = [int(x) for x in input().split()]
answer = []
x = math.ceil(n / 2)
y = n % 2
for i in range(1, math.ceil(n / 2) + 1):
	if y == 1 and i == x:
		for j in range(1, m // 2 + 1):
			answer.append(str(i) + ' ' + str(j))
			answer.append(str(n - i + 1) + ' ' + str(m - j + 1))
		answer.append(str(i) + ' ' + str(math.ceil(m / 2)))
	else:
		for j in range(1, m + 1):
			answer.append(str(i) + ' ' + str(j))
			answer.append(str(n - i + 1) + ' ' + str(m - j + 1))
print('\n'.join(answer[:n * m]))


[n, m] = [int(i) for i in input().split()]
ur = 1
lr = n
ctr = 0
arr = []
while ctr < n:
	uc = 1
	lc = m
	if ur == lr:
		fac = m - 1
		for i in range(m):
			arr.append(str(ur) + ' ' + str(uc))
			if i % 2 == 0:
				uc += fac
			else:
				uc -= fac
			fac -= 1
		ctr += 1
	else:
		for i in range(m):
			arr.append(str(ur) + ' ' + str(uc))
			arr.append(str(lr) + ' ' + str(lc))
			uc += 1
			lc -= 1
		ctr += 2
	ur += 1
	lr -= 1
print('\n'.join(arr))


(n, m) = [int(x) for x in input().split()]
answer = []
for i in range((n + 1) // 2):
	for j in range(m):
		if i == n // 2 and j == m // 2:
			if m % 2 == 0:
				break
			answer.append('{} {}'.format(i + 1, j + 1))
			break
		answer.append('{} {}'.format(i + 1, j + 1))
		answer.append('{} {}'.format(n - i, m - j))
print('\n'.join(answer))


import sys
import time
input = sys.stdin.readline
(n, m) = map(int, input().split())
x1 = 1
y1 = 1
x2 = n
y2 = m
arr = []
for i in range(n * m):
	if i % 2 == 0:
		arr.append(str(x1) + ' ' + str(y1))
		if x1 % 2 == 1:
			if y1 < m:
				y1 += 1
			else:
				x1 += 1
		elif y1 > 1:
			y1 -= 1
		else:
			x1 += 1
	else:
		arr.append(str(x2) + ' ' + str(y2))
		if (n - x2) % 2 == 0:
			if y2 > 1:
				y2 -= 1
			else:
				x2 -= 1
		elif y2 < m:
			y2 += 1
		else:
			x2 -= 1
print('\n'.join(arr))


import sys, atexit
from io import BytesIO
inp = BytesIO(sys.stdin.buffer.read())
input = lambda : inp.readline().decode('ascii')
buf = BytesIO()
sys.stdout.write = lambda s: buf.write(s.encode('ascii'))
atexit.register(lambda : sys.__stdout__.buffer.write(buf.getvalue()))
(n, m) = map(int, input().split())
if m % 2 == 0:
	steps = []
	for j in range(m // 2):
		for i in range(n):
			steps.append((j, i))
			steps.append((m - j - 1, n - i - 1))
else:
	steps = []
	for j in range(m // 2):
		for i in range(n):
			steps.append((j, i))
			steps.append((m - j - 1, n - i - 1))
	l = 0
	r = n - 1
	mid = m // 2
	while l <= r:
		steps.append((mid, l))
		if l != r:
			steps.append((mid, r))
		l += 1
		r -= 1
for (x, y) in steps:
	print(y + 1, x + 1)


(n, m) = list(map(int, input().split()))
for i in range(0, n * m):
	if i % 2 == 0:
		c = i // (2 * n)
		r = i % (2 * n) // 2
	else:
		c = m - 1 - i // (2 * n)
		r = n - 1 - i % (2 * n) // 2
	print(str(r + 1) + ' ' + str(c + 1))


def fun():
	(n, m) = map(int, input().split())
	arr = []
	x1 = 1
	y1 = 1
	x2 = n
	y2 = m
	k = n * m
	while k > 0:
		k = k - 2
		arr.append('{} {}'.format(x1, y1))
		if x1 == x2 and y1 == y2:
			break
		arr.append('{} {}'.format(x2, y2))
		if x1 % 2 == 1:
			y1 += 1
			y2 -= 1
		else:
			y1 -= 1
			y2 += 1
		if y2 == 0 or y2 == m + 1:
			x1 += 1
			x2 -= 1
			if y1 == m + 1:
				y1 = m
				y2 = 1
			else:
				y1 = 1
				y2 = m
	print('\n'.join(arr))
	return
fun()


import sys
ii = lambda : int(input())
mi = lambda : map(int, input().split())
li = lambda : list(mi())
(n, m) = list(map(int, sys.stdin.readline().strip().split()))
upr = 1
dwr = n
while upr < dwr:
	upc = 1
	dwc = m
	for i in range(m):
		sys.stdout.write(str(upr) + ' ' + str(upc) + '\n')
		sys.stdout.write(str(dwr) + ' ' + str(dwc) + '\n')
		upc += 1
		dwc -= 1
	upr += 1
	dwr -= 1
if upr == dwr:
	row = upr
	col = 1
	rcol = m
	for i in range(m):
		sys.stdout.write(str(row) + ' ' + str(col) + '\n')
		tcol = col
		col = rcol
		rcol = tcol + 1 if tcol < rcol else tcol - 1


import os, sys
from io import BytesIO, IOBase

def main():
	(n, m) = map(int, input().split())
	for i in range(1, n // 2 + 1):
		(a, b, c, d) = (i, 1, n - i + 1, m)
		for _ in range(m):
			print(a, b)
			print(c, d)
			b += 1
			d -= 1
	if n % 2:
		(a, b, c) = (n // 2 + 1, 1, m)
		while b < c:
			print(a, b)
			print(a, c)
			b += 1
			c -= 1
		if m % 2:
			print(a, b)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


(n, m) = map(int, input().split())
buf = []
for i in range(n // 2):
	for j in range(m):
		buf.append(f'{i + 1} {j + 1}\n')
		buf.append(f'{n - i} {m - j}\n')
if n % 2 == 1:
	for j in range(m // 2):
		buf.append(f'{n // 2 + 1} {j + 1}\n')
		buf.append(f'{n // 2 + 1} {m - j}\n')
	if m % 2 == 1:
		buf.append(f'{n // 2 + 1} {m // 2 + 1}\n')
print(*buf, sep='')


import sys
import math
from collections import defaultdict
(n, m) = list(map(int, sys.stdin.readline().split()))
(up, down) = (1, n)
count = 0
while up <= down:
	(left, right) = (1, m)
	while left <= m and count < n * m:
		if count < n * m:
			sys.stdout.write(str(up) + ' ' + str(left) + '\n')
		count += 1
		left += 1
		if count < n * m:
			sys.stdout.write(str(down) + ' ' + str(right) + '\n')
		count += 1
		right -= 1
	up += 1
	down -= 1


(n, m) = map(int, input().split())
np1 = n + 1
mp1 = m + 1
for i in range(1, 1 + n // 2):
	for j in range(1, mp1):
		print('%d %d\n%d %d' % (i, j, np1 - i, mp1 - j))
if n & 1:
	i = 1 + n // 2
	for j in range(1, 1 + m // 2):
		print('%d %d\n%d %d' % (i, j, i, mp1 - j))
	if m & 1:
		print(i, 1 + m // 2)


import math
inp = input().split(' ')
m = int(inp[0])
n = int(inp[1])
result = []
for column in range(1, math.ceil(m / 2) + 1):
	rowRange = range(1, n + 1)
	if column == math.ceil(m / 2) and m % 2 == 1:
		rowRange = range(1, math.ceil(n / 2) + 1)
	for row in rowRange:
		result.append(str(column) + ' ' + str(row))
		if row == math.ceil(n / 2) and n % 2 == 1 and (column == math.ceil(m / 2)) and (m % 2 == 1):
			continue
		result.append(str(m + 1 - column) + ' ' + str(n + 1 - row))
print('\n'.join(result))


from sys import stdout
print = lambda x, y: stdout.write(str(x) + ' ' + str(y) + '\n')
(n, m) = map(int, input().split())
(i, j) = (1, n)
while i < j:
	for x in range(1, m + 1):
		print(i, x)
		print(j, m - x + 1)
	i += 1
	j -= 1
if i == j:
	for x in range(1, m // 2 + 1):
		print(i, x)
		print(i, m - x + 1)
	if m & 1:
		print(i, m // 2 + 1)


import sys
ints = (int(x) for x in sys.stdin.read().split())

def solve(n, m):
	for j in range(m // 2):
		for i in range(n):
			yield (i, j)
			yield (n - 1 - i, m - 1 - j)
	if m % 2 == 1:
		for i in range(n // 2):
			yield (i, m // 2)
			yield (n - 1 - i, m // 2)
		if n % 2 == 1:
			yield (n // 2, m // 2)
	return

def main(n, m):
	ans = ['{} {}'.format(i + 1, j + 1) for (i, j) in solve(n, m)]
	print('\n'.join(ans))
	return
while 1:
	try:
		(n, m) = (next(ints), next(ints))
	except StopIteration:
		break
	main(n, m)


import sys
(n, m) = list(map(int, sys.stdin.readline().strip().split()))
for i in range(0, n * m):
	if i % 2 == 0:
		c = i // (2 * n)
		r = i % (2 * n) // 2
	else:
		c = m - 1 - i // (2 * n)
		r = n - 1 - i % (2 * n) // 2
	sys.stdout.write(str(r + 1) + ' ' + str(c + 1) + '\n')


from sys import stdout as so
(n, m) = [int(x) for x in input().split()]

def printa(x1, x2):
	so.write(str(x1) + ' ' + str(x2) + '\n')
mn = 1
mx = n
while mn < mx:
	for i in range(1, m + 1):
		printa(mn, i)
		printa(mx, m - i + 1)
	mn += 1
	mx -= 1
if mn == mx:
	for i in range(1, m // 2 + 1):
		printa(mn, i)
		printa(mn, m - i + 1)
	if m % 2 == 1:
		printa(mn, m // 2 + 1)


from sys import stdout
(n, m) = map(int, input().split())
i = 0
while n - i - 1 > i:
	for j in range(m):
		stdout.write(str(i + 1) + ' ' + str(j + 1) + '\n')
		stdout.write(str(n - i) + ' ' + str(m - j) + '\n')
	i += 1
if n % 2 == 1:
	i = n // 2
	j = 0
	while m - j - 1 >= j:
		if j + 1 != m - j:
			stdout.write(str(i + 1) + ' ' + str(j + 1) + '\n')
			stdout.write(str(i + 1) + ' ' + str(m - j) + '\n')
		else:
			stdout.write(str(i + 1) + ' ' + str(j + 1) + '\n')
		j += 1


inp = list(map(int, input().split(' ')))
n = int(inp[0])
m = int(inp[1])
x = 1
y = 1
cells = n * m
up = n
down = 1
upiter = m
downiter = 1
flag = 0
count = 0
Ans = []
while up >= down:
	while upiter >= 1 or downiter <= m:
		if flag == 0:
			Ans.append(str(down) + ' ' + str(downiter))
			downiter += 1
		else:
			Ans.append(str(up) + ' ' + str(upiter))
			upiter -= 1
		count += 1
		if count == cells:
			break
		flag = flag ^ 1
	flag = 0
	up -= 1
	down += 1
	upiter = m
	downiter = 1
if count != cells:
	print(-1)
else:
	for x in Ans:
		print(x)


import os
import sys
from io import BytesIO, IOBase
import math
from collections import defaultdict, deque
import random
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
(n, k) = map(int, input().split(' '))
ans = []
for i in range(1, n * k + 1):
	if i % 2:
		(x, y) = divmod(i // 2, k)
		ans.append([x + 1, y + 1])
	else:
		(x, y) = divmod(n * k - i // 2, k)
		ans.append([x + 1, y + 1])
for i in ans:
	sys.stdout.write('{} {}\n'.format(*i))


(n, m) = map(int, input().split())
l = 1
r = n
x = 1
y = 1
ans = []
while l <= r:
	if l == r:
		y = 1
		for i in range(m):
			ans.append(str(l))
			ans.append(str(y))
			if 2 * y <= m:
				y = m + 1 - y
			else:
				y = m + 2 - y
	else:
		y = 1
		for i in range(m):
			ans.append(str(l))
			ans.append(str(y))
			y = m + 1 - y
			ans.append(str(r))
			ans.append(str(y))
			y = m + 2 - y
	l += 1
	r -= 1
print(' '.join(ans))


from sys import stdout
(N, M) = map(int, input().split())
if M % 2 == 0 and N % 2 == 0:
	for m in range(1, M // 2 + 1):
		for n in range(1, N + 1):
			stdout.write(str(n) + ' ' + str(m) + '\n')
			stdout.write(str(N + 1 - n) + ' ' + str(M + 1 - m) + '\n')
elif M % 2 == 0 and N % 2 == 1:
	for m in range(1, M // 2 + 1):
		for i in range(1, N + 1):
			stdout.write(str(i) + ' ' + str(m) + '\n')
			stdout.write(str(N + 1 - i) + ' ' + str(M + 1 - m) + '\n')
else:
	for m in range(1, (M + 1) // 2):
		for n in range(1, N + 1):
			stdout.write(str(n) + ' ' + str(m) + '\n')
			stdout.write(str(N + 1 - n) + ' ' + str(M + 1 - m) + '\n')
	if N % 2 == 0:
		for i in range(1, N // 2 + 1):
			stdout.write(str(i) + ' ' + str((M + 1) // 2) + '\n')
			stdout.write(str(N + 1 - i) + ' ' + str((M + 1) // 2) + '\n')
	else:
		for i in range(1, (N + 1) // 2):
			stdout.write(str(i) + ' ' + str((M + 1) // 2) + '\n')
			stdout.write(str(N + 1 - i) + ' ' + str((M + 1) // 2) + '\n')
		stdout.write(str((N + 1) // 2) + ' ' + str((M + 1) // 2) + '\n')


(n, m) = [int(x) for x in input().split()]
answer = []
for shift_y in range(m // 2):
	for curx in range(1, n + 1):
		answer.append('{} {}'.format(curx, 1 + shift_y))
		answer.append('{} {}'.format(n - curx + 1, m - shift_y))
if m % 2 == 1:
	for curx in range(1, n // 2 + n % 2 + 1):
		answer.append('{} {}'.format(curx, m // 2 + 1))
		if n % 2 == 1 and curx == n // 2 + n % 2:
			break
		answer.append('{} {}'.format(n - curx + 1, m // 2 + 1))
print('\n'.join(answer))


import sys
(N, M) = map(int, input().split())
Ans = [None] * (N * M)
for i in range(1, N * M + 1):
	if i % 2:
		(a, b) = divmod(i // 2, M)
	else:
		(a, b) = divmod(N * M - i // 2, M)
	Ans[i - 1] = (a + 1, b + 1)
for a in Ans:
	sys.stdout.write('{} {}\n'.format(*a))


(n, m) = map(int, input().split())
(x1, y1, x2, y2) = (1, 1, n, m)
for i in range(n * m):
	if i & 1:
		print(str(x2) + ' ' + str(y2))
		if x2 == 1:
			(x2, y2) = (n, y2 - 1)
		else:
			x2 -= 1
	else:
		print(str(x1) + ' ' + str(y1))
		if x1 == n:
			(x1, y1) = (1, y1 + 1)
		else:
			x1 += 1


(n, m) = map(int, input().split())

def out(x):
	a = x // m + 1
	b = x % m + 1
	return f'{a}  {b}'
(u, v) = (0, m * n - 1)
res = []
while True:
	res.append(out(u))
	u += 1
	if u > v:
		break
	res.append(out(v))
	v -= 1
	if u > v:
		break
print('\n'.join(res))


(n, m) = map(int, input().split())
ans = []
if n % 2 == 0:
	for i in range(int(n / 2)):
		for j in range(m):
			ans.append(f'{i + 1} {j + 1}')
			ans.append(f'{n - i} {m - j}')
else:
	for i in range(int(n / 2)):
		for j in range(m):
			ans.append(f'{i + 1} {j + 1}')
			ans.append(f'{n - i} {m - j}')
	mid = int(n / 2)
	for j in range(m // 2):
		ans.append(f'{mid + 1} {j + 1}')
		ans.append(f'{mid + 1} {m - j}')
	if m % 2 != 0:
		ans.append(f'{n // 2 + 1} {m // 2 + 1}')
print('\n'.join(ans))