You are given two matrices $A$ and $B$. Each matrix contains exactly $n$ rows and $m$ columns. Each element of $A$ is either $0$ or $1$; each element of $B$ is initially $0$.

You may perform some operations with matrix $B$. During each operation, you choose any submatrix of $B$ having size $2 \times 2$, and replace every element in the chosen submatrix with $1$. In other words, you choose two integers $x$ and $y$ such that $1 \le x < n$ and $1 \le y < m$, and then set $B_{x, y}$, $B_{x, y + 1}$, $B_{x + 1, y}$ and $B_{x + 1, y + 1}$ to $1$.

Your goal is to make matrix $B$ equal to matrix $A$. Two matrices $A$ and $B$ are equal if and only if every element of matrix $A$ is equal to the corresponding element of matrix $B$.

Is it possible to make these matrices equal? If it is, you have to come up with a sequence of operations that makes $B$ equal to $A$. Note that you don't have to minimize the number of operations.


-----Input-----

The first line contains two integers $n$ and $m$ ($2 \le n, m \le 50$).

Then $n$ lines follow, each containing $m$ integers. The $j$-th integer in the $i$-th line is $A_{i, j}$. Each integer is either $0$ or $1$.


-----Output-----

If it is impossible to make $B$ equal to $A$, print one integer $-1$.

Otherwise, print any sequence of operations that transforms $B$ into $A$ in the following format: the first line should contain one integer $k$ — the number of operations, and then $k$ lines should follow, each line containing two integers $x$ and $y$ for the corresponding operation (set $B_{x, y}$, $B_{x, y + 1}$, $B_{x + 1, y}$ and $B_{x + 1, y + 1}$ to $1$). The condition $0 \le k \le 2500$ should hold.


-----Examples-----
Input
3 3
1 1 1
1 1 1
0 1 1

Output
3
1 1
1 2
2 2

Input
3 3
1 0 1
1 0 1
0 0 0

Output
-1

Input
3 2
0 0
0 0
0 0

Output
0



-----Note-----

The sequence of operations in the first example: $\begin{matrix} 0 & 0 & 0 & & 1 & 1 & 0 & & 1 & 1 & 1 & & 1 & 1 & 1 \\ 0 & 0 & 0 & \rightarrow & 1 & 1 & 0 & \rightarrow & 1 & 1 & 1 & \rightarrow & 1 & 1 & 1 \\ 0 & 0 & 0 & & 0 & 0 & 0 & & 0 & 0 & 0 & & 0 & 1 & 1 \end{matrix}$

Difficulty: EASY

Solutions:
(n, m) = map(int, input().split())
f = []
for k in range(n):
	f.append(list(map(int, input().split())))
u = []
l = 0
for j in range(n - 1):
	for b in range(m - 1):
		g = 0
		if f[j][b] == 1 or f[j][b] == 'g':
			g += 1
		if f[j][b + 1] == 1 or f[j][b + 1] == 'g':
			g += 1
		if f[j + 1][b + 1] == 1 or f[j + 1][b + 1] == 'g':
			g += 1
		if f[j + 1][b] == 1 or f[j + 1][b] == 'g':
			g += 1
		if g == 4:
			u.append([j + 1, b + 1])
			f[j][b] = 'g'
			f[j][b + 1] = 'g'
			f[j + 1][b + 1] = 'g'
			f[j + 1][b] = 'g'
		else:
			pass
for e in f:
	if 1 not in e:
		pass
	else:
		print(-1)
		l += 1
		break
if l == 0:
	if len(u) == 0:
		print(0)
	else:
		print(len(u))
		for h in u:
			print(*h)


(n, m) = map(int, input().split())
a = [None] * n
for i in range(n):
	row = list(map(int, input().split()))
	a[i] = row
ops = []
for i in range(n):
	for j in range(m):
		if i + 1 < n and j + 1 < m and (a[i][j] == 1 or a[i][j + 1] == 1 or a[i + 1][j] == 1 or (a[i + 1][j + 1] == 1)):
			if a[i][j] > 0 and a[i][j + 1] > 0 and (a[i + 1][j] > 0) and (a[i + 1][j + 1] > 0):
				ops[len(ops):] = [(i, j)]
				a[i][j] += 1
				a[i][j + 1] += 1
				a[i + 1][j] += 1
				a[i + 1][j + 1] += 1
possible = True
for i in range(n):
	for j in range(m):
		if a[i][j] == 1:
			possible = False
if not possible:
	print(-1)
else:
	print(len(ops))
	for op in ops:
		print(op[0] + 1, op[1] + 1)


def main():
	import sys
	input = sys.stdin.readline
	(n, m) = map(int, input().split())
	grid = [list(map(int, input().split())) for _ in range(n)]
	grd = [[0] * m for _ in range(n)]
	moves = []
	for i in range(n - 1):
		for j in range(m - 1):
			if grid[i][j] and grid[i][j + 1] and grid[i + 1][j] and grid[i + 1][j + 1]:
				moves.append([i + 1, j + 1])
				for c in range(2):
					for d in range(2):
						grd[i + c][j + d] = 1
	ok = 1
	for i in range(n):
		for j in range(m):
			if grid[i][j] ^ grd[i][j]:
				ok = 0
	if not ok:
		print(-1)
	else:
		print(len(moves))
		for move in moves:
			print(*move)
	return 0
main()


(n, m) = map(int, input().split())
a = []
b = []
for i in range(n):
	a.append(list(map(int, input().split())))
	b.append(list(map(int, ('0 ' * m).split())))
t = 0
x = []
y = []
u = 0
e = 0
for i in range(n - 1):
	for j in range(m - 1):
		if a[i][j] + a[i + 1][j] + a[i][j + 1] + a[i + 1][j + 1] == 4:
			x.append(i)
			y.append(j)
			b[i][j] = 1
			b[i + 1][j] = 1
			b[i][j + 1] = 1
			b[i + 1][j + 1] = 1
			u += 1
for i in range(n):
	for j in range(m):
		if a[i][j] != b[i][j]:
			print('-1')
			exit()
print(u)
for i in range(u):
	print(x[i] + 1, y[i] + 1)


(n, m) = [int(x) for x in input().split()]
b = [[0] * m for i in range(n)]
a = []
arr = []
for i in range(n):
	c = [int(x) for x in input().split()]
	a.append(c)
for i in range(n - 1):
	for j in range(m - 1):
		if a[i][j] == a[i + 1][j] == a[i][j + 1] == a[i + 1][j + 1] == 1:
			b[i][j] = b[i + 1][j] = b[i][j + 1] = b[i + 1][j + 1] = 1
			arr.append((i + 1, j + 1))
for i in range(n):
	for j in range(m):
		if a[i][j] != b[i][j]:
			print(-1)
			return
print(len(arr))
for item in arr:
	print(*item)


(n, m) = map(int, input().split())
a = [list(map(int, input().split())) for i in range(n)]
t = [[0 for x in range(m)] for y in range(n)]
ans = []
for i in range(n - 1):
	for j in range(m - 1):
		if a[i][j] == 1 and a[i + 1][j] == 1 and (a[i][j + 1] == 1) and (a[i + 1][j + 1] == 1):
			ans.append([i + 1, j + 1])
			t[i][j] = 1
			t[i + 1][j] = 1
			t[i][j + 1] = 1
			t[i + 1][j + 1] = 1
flg = 1
for i in range(n):
	for j in range(m):
		if a[i][j] == 1 and t[i][j] == 0:
			flg = 0
if flg:
	print(len(ans))
	for x in ans:
		print(*x)
else:
	print(-1)


import bisect
import decimal
from decimal import Decimal
import os
from collections import Counter
import bisect
from collections import defaultdict
import math
import random
import heapq
from math import sqrt
import sys
from functools import reduce, cmp_to_key
from collections import deque
import threading
from itertools import combinations
from io import BytesIO, IOBase
from itertools import accumulate
decimal.getcontext().prec = 46

def primeFactors(n):
	prime = set()
	while n % 2 == 0:
		prime.add(2)
		n = n // 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			prime.add(i)
			n = n // i
	if n > 2:
		prime.add(n)
	return list(prime)

def getFactors(n):
	factors = []
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if n // i == i:
				factors.append(i)
			else:
				factors.append(i)
				factors.append(n // i)
		i = i + 1
	return factors

def modefiedSieve():
	mx = 10 ** 7 + 1
	sieve = [-1] * mx
	for i in range(2, mx):
		if sieve[i] == -1:
			sieve[i] = i
			for j in range(i * i, mx, i):
				if sieve[j] == -1:
					sieve[j] = i
	return sieve

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	num = []
	for p in range(2, n + 1):
		if prime[p]:
			num.append(p)
	return num

def lcm(a, b):
	return a * b // math.gcd(a, b)

def sort_dict(key_value):
	return sorted(key_value.items(), key=lambda kv: (kv[1], kv[0]), reverse=True)

def list_input():
	return list(map(int, input().split()))

def num_input():
	return map(int, input().split())

def string_list():
	return list(input())

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def binaryToDecimal(n):
	return int(n, 2)

def DFS(n, s, adj):
	visited = [False for i in range(n + 1)]
	stack = []
	stack.append(s)
	while len(stack):
		s = stack[-1]
		stack.pop()
		if not visited[s]:
			visited[s] = True
		for node in adj[s]:
			if not visited[node]:
				stack.append(node)

def maxSubArraySum(a, size):
	maxint = 10 ** 10
	max_so_far = -maxint - 1
	max_ending_here = 0
	for i in range(0, size):
		max_ending_here = max_ending_here + a[i]
		if max_so_far < max_ending_here:
			max_so_far = max_ending_here
		if max_ending_here < 0:
			max_ending_here = 0
	return max_so_far

def lis(arr):
	n = len(arr)
	lis = [1] * n
	for i in range(1, n):
		for j in range(0, i):
			if arr[i] >= arr[j] and lis[i] < lis[j] + 1:
				lis[i] = lis[j] + 1
	maximum = 0
	for i in range(n):
		maximum = max(maximum, lis[i])
	return maximum

def solve():
	(n, m) = num_input()
	a = []
	b = [[0] * m for i in range(n)]
	for _ in range(n):
		a.append(list_input())
	ans = []
	for i in range(n - 1):
		for j in range(m - 1):
			if a[i][j] == 1 and a[i][j + 1] == 1 and (a[i + 1][j] == 1) and (a[i + 1][j + 1] == 1):
				ans.append((i + 1, j + 1))
				b[i][j] = b[i][j + 1] = b[i + 1][j] = b[i + 1][j + 1] = 1
	for i in range(n):
		for j in range(m):
			if a[i][j] != b[i][j]:
				print(-1)
				return
	print(len(ans))
	for (u, v) in ans:
		print(u, v)
t = 1
for _ in range(t):
	solve()


(n, m) = map(int, input().rstrip().split())
A = []
for i in range(n):
	l = list(map(int, input().rstrip().split()))
	A.append(l)
B = []
for i in range(n):
	l = [0] * m
	B.append(l)
ans = []
for i in range(n - 1):
	for j in range(m - 1):
		if A[i][j] + A[i][j + 1] + A[i + 1][j] + A[i + 1][j + 1] == 4:
			B[i][j] = B[i][j + 1] = B[i + 1][j] = B[i + 1][j + 1] = 1
			ans.append([i + 1, j + 1])
for i in range(n):
	for j in range(m):
		if B[i][j] != A[i][j]:
			print('-1')
			exit()
print(len(ans))
for i in ans:
	print(i[0], i[1])


def checksq(l, x, y, r, c):
	if l[x][y] == 0:
		return 0
	elif x == r - 1 and y == c - 1:
		if checksq(l, x - 1, y - 1, r, c) == 1:
			return 0
		else:
			return -1
	elif x == r - 1 and y == 0:
		if checksq(l, x - 1, y, r, c) == 1:
			return 0
		else:
			return -1
	elif x == 0 and y == c - 1:
		if checksq(l, x, y - 1, r, c) == 1:
			return 0
		else:
			return -1
	elif x == r - 1:
		if checksq(l, x - 1, y, r, c) == 1 or checksq(l, x - 1, y - 1, r, c) == 1:
			return 0
		else:
			return -1
	elif y == c - 1:
		if checksq(l, x, y - 1, r, c) == 1 or checksq(l, x - 1, y - 1, r, c) == 1:
			return 0
		else:
			return -1
	elif l[x][y + 1] == 1 and l[x + 1][y] == 1 and (l[x + 1][y + 1] == 1):
		return 1
	elif x == 0 and y == 0:
		return -1
	elif x == 0:
		if checksq(l, x, y - 1, r, c) == 1:
			return 0
		else:
			return -1
	elif y == 0:
		if checksq(l, x - 1, y, r, c) == 1:
			return 0
		else:
			return -1
	elif checksq(l, x - 1, y - 1, r, c) == 1 or checksq(l, x - 1, y, r, c) == 1 or checksq(l, x, y - 1, r, c) == 1:
		return 0
	else:
		return -1
s = input()
n = int(s.split()[0])
m = int(s.split()[1])
lst = []
for i in range(n):
	lst1 = list(map(int, input().split()))
	lst.append(lst1)
steplst = []
for i in range(n):
	for j in range(m):
		x = checksq(lst, i, j, n, m)
		if x == -1:
			print(-1)
			exit(0)
		elif x == 1:
			steplst.append([i + 1, j + 1])
print(len(steplst))
for i in steplst:
	print(i[0], i[1])


import sys, math, queue, collections
MOD = 10 ** 9 + 7
(n, m) = map(int, input().split())
(a, b) = ([], [])
for i in range(n):
	a.append(list(map(int, input().split())))
	b.append([0 for i in range(m)])
ans = []
for i in range(n - 1):
	for j in range(m - 1):
		if a[i][j] == 1 and a[i][j + 1] == 1:
			if a[i + 1][j + 1] == 1 and a[i + 1][j] == 1:
				b[i][j] = 1
				b[i + 1][j] = 1
				b[i][j + 1] = 1
				b[i + 1][j + 1] = 1
				ans.append((i + 1, j + 1))
if a != b:
	print(-1)
	exit()
print(len(ans))
for m in ans:
	print(*m)


(n, m) = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]
b = [[0] * m for _ in range(n)]
o = []
for i in range(n - 1):
	for j in range(m - 1):
		if a[i][j] and a[i][j + 1] and a[i + 1][j] and a[i + 1][j + 1]:
			o.append((i + 1, j + 1))
			b[i][j] = b[i][j + 1] = b[i + 1][j] = b[i + 1][j + 1] = 1
if a == b:
	print(len(o))
	for (x, y) in o:
		print(x, y)
else:
	print(-1)


(n, m) = tuple(map(int, input().split()))
a = []
for i in range(n):
	a.append(list(map(int, input().split())))
b = [[0 for i in range(m)] for j in range(n)]
i = 0
j = 0
c = 0
t = 0
l = []
while i < n:
	j = 0
	while j < m:
		if a[i][j] == 1:
			if i < n - 1 and j < m - 1 and (a[i][j + 1] == 1) and (a[i + 1][j] == 1) and (a[i + 1][j + 1] == 1):
				t += 1
				l.append(i + 1)
				l.append(j + 1)
				j += 1
			elif j < m - 1 and i > 0 and (a[i - 1][j] == 1) and (a[i][j + 1] == 1) and (a[i - 1][j + 1] == 1):
				j += 1
			elif i < n - 1 and j > 0 and (a[i][j - 1] == 1) and (a[i + 1][j] == 1) and (a[i + 1][j - 1] == 1):
				j += 1
			elif i > 0 and j > 0 and (a[i - 1][j] == 1) and (a[i][j - 1] == 1) and (a[i - 1][j - 1] == 1):
				j += 1
			else:
				c = 1
				break
		else:
			j += 1
	i += 1
if c == 1:
	print(-1)
else:
	print(t)
	for i in range(0, len(l), 2):
		print(l[i], l[i + 1])


q = 1
for _ in range(q):
	(n, m) = map(int, input().split())
	A = []
	for i in range(n):
		a = list(map(int, input().split()))
		A.append(a)
	ans = []
	B = [[0] * m for i in range(n)]
	for i in range(n - 1):
		for j in range(m - 1):
			if A[i][j] + A[i][j + 1] + A[i + 1][j] + A[i + 1][j + 1] == 4:
				B[i][j] = 1
				B[i][j + 1] = 1
				B[i + 1][j] = 1
				B[i + 1][j + 1] = 1
				ans.append([i + 1, j + 1])
	if A == B:
		print(len(ans))
		for i in range(len(ans)):
			print(*ans[i])
	else:
		print(-1)


(n, m) = list(map(int, input().split()))
li = [list(map(int, input().split())) for _ in range(n)]
b = [[0 for _ in range(m)] for _ in range(n)]
res = []
for i in range(n - 1):
	for j in range(m - 1):
		if li[i][j] == li[i + 1][j] == li[i][j + 1] == li[i + 1][j + 1] == 1:
			res.append([i + 1, j + 1])
			b[i][j] = 1
			b[i + 1][j] = 1
			b[i + 1][j + 1] = 1
			b[i][j + 1] = 1
if li == b:
	print(len(res))
	for i in res:
		print(*i)
else:
	print(-1)


(n, m) = map(int, input().split())
a = [[] for i in range(n)]
for i in range(n):
	a[i] = list(map(int, input().split()))
ans = []
for i in range(n - 1):
	for j in range(m - 1):
		if a[i][j] * a[i][j + 1] * a[i + 1][j] * a[i + 1][j + 1] > 0:
			a[i][j] = 2
			a[i + 1][j] = 2
			a[i][j + 1] = 2
			a[i + 1][j + 1] = 2
			ans.append([i, j])
cnt1 = 0
for i in range(n):
	for j in range(m):
		if a[i][j] == 1:
			cnt1 += 1
if cnt1 != 0:
	print(-1)
else:
	print(len(ans))
	for x in ans:
		print(x[0] + 1, x[1] + 1)


from sys import stdin
input = stdin.readline
(n, m) = [int(i) for i in input().split()]
A = [[int(i) for i in input().split()] for j in range(n)]
B = [[0 for i in range(m)] for j in range(n)]
op = [[0, 0] for i in range(2500)]
num_op = 0
res = True
for i in range(n - 1):
	for j in range(m - 1):
		if A[i][j] == 1 and A[i][j + 1] == 1 and (A[i + 1][j] == 1) and (A[i + 1][j + 1] == 1):
			(op[num_op][0], op[num_op][1]) = (i, j)
			num_op += 1
			(B[i][j], B[i + 1][j], B[i][j + 1], B[i + 1][j + 1]) = (1, 1, 1, 1)
if A == B:
	print(num_op)
	for i in range(num_op):
		print(op[i][0] + 1, op[i][1] + 1)
else:
	print(-1)


(n, m) = list(map(int, input().strip().split()))
a = []
for l in range(n):
	a.append(input().split())
b = [['0' for i in range(m)] for j in range(n)]
c = 0
d = []
for j in range(n - 1):
	for k in range(m - 1):
		if a[j][k] == '1' and a[j + 1][k] == '1' and (a[j][k + 1] == '1') and (a[j + 1][k + 1] == '1'):
			b[j][k] = '1'
			b[j + 1][k] = '1'
			b[j][k + 1] = '1'
			b[j + 1][k + 1] = '1'
			c = c + 1
			d.append([j + 1, k + 1])
if a == b:
	print(c)
	for i in range(c):
		print(*d[i])
else:
	print(-1)


from sys import stdin, stdout
from itertools import combinations
from collections import defaultdict, Counter
import math
import heapq

def listIn():
	return list(map(int, stdin.readline().strip().split()))

def stringListIn():
	return [x for x in stdin.readline().split()]

def intIn():
	return int(stdin.readline())

def stringIn():
	return stdin.readline().strip()
(n, m) = listIn()
mtx1 = []
mtx2 = []
for i in range(n):
	a = listIn()
	b = [0] * m
	mtx1.append(a)
	mtx2.append(b)
ans = []
for i in range(n - 1):
	for j in range(m - 1):
		if mtx1[i][j] == 1:
			if mtx1[i + 1][j] == 1 and mtx1[i][j + 1] == 1 and (mtx1[i + 1][j + 1] == 1):
				mtx2[i][j] = 1
				mtx2[i + 1][j] = 1
				mtx2[i + 1][j + 1] = 1
				mtx2[i][j + 1] = 1
				ans.append((i + 1, j + 1))
if mtx1 == mtx2:
	print(len(ans))
	for i in range(len(ans)):
		print(*ans[i])
else:
	print(-1)


(n, m) = map(int, input().split())
a = []
for i in range(0, n):
	a.append([int(j) for j in input().split()])
b = [[0 for i in range(m)] for j in range(n)]
if a == b:
	print(0)
else:
	c = 0
	k = 0
	l = []
	for i in range(n - 1):
		for j in range(m - 1):
			if c != -2:
				if b == a:
					print(k)
					for x in range(k):
						print(l[x][0], l[x][1])
						c = -2
				elif a[i + 1][j + 1] == 1 and a[i][j] == 1 and (a[i + 1][j] == 1) and (a[i][j + 1] == 1):
					(b[i + 1][j + 1], b[i][j], b[i + 1][j], b[i][j + 1]) = (1, 1, 1, 1)
					l.append([i + 1, j + 1])
					k += 1
	if c != -2:
		if b == a:
			print(k)
			for x in range(k):
				print(l[x][0], l[x][1])
				c = -2
		else:
			print(-1)


def lis():
	return [int(i) for i in input().split()]

def value():
	return int(input())

def string():
	return input()

def makeb(i, j, b):
	(b[i][j], b[i + 1][j], b[i + 1][j + 1], b[i][j + 1]) = (1, 1, 1, 1)
	return b

def check(a, b):
	for x in range(len(a)):
		for y in range(len(a[0])):
			if a[x][y] != b[x][y]:
				return False
	return True
(n, m) = lis()
arr = []
for i in range(n):
	temp = lis()
	arr.append(temp)
b = [[0 for i in range(m)] for j in range(n)]
tot = 0
d = {}
for i in range(n - 1):
	for j in range(m - 1):
		if arr[i][j] and arr[i][j + 1] and arr[i + 1][j + 1] and arr[i + 1][j]:
			b = makeb(i, j, b)
			d[i, j] = 1
			tot += 1
if check(arr, b):
	print(tot)
	for q in d:
		print(q[0] + 1, q[1] + 1)
else:
	print(-1)


def mi():
	return list(map(int, input().split()))
(n, m) = mi()
a = [0] * n
for i in range(n):
	a[i] = list(mi())
out = []
b = [[0] * m for i in range(n)]
for i in range(n - 1):
	for j in range(m - 1):
		if a[i][j] == 1 and a[i + 1][j] == 1 and (a[i + 1][j + 1] == 1) and (a[i][j + 1] == 1):
			out.append(str(i + 1) + ' ' + str(j + 1) + '\n')
			b[i][j] = b[i + 1][j] = b[i + 1][j + 1] = b[i][j + 1] = 1
		if a[i][j] != b[i][j]:
			print(-1)
			return
for i in range(n):
	for j in range(m):
		if a[i][j] != b[i][j]:
			print(-1)
			return
print(len(out))
print(''.join(out))


(n, m) = list(map(int, input().split()))
MatA = list()
MatB = list()
for j in range(n):
	MatA.append(list(map(int, input().split())))
	MatB.append(list())
	for i in range(m):
		MatB[-1].append(0)
ans = list()
for i in range(n - 1):
	for j in range(m - 1):
		if MatA[i][j] * MatA[i + 1][j] * MatA[i + 1][j + 1] * MatA[i][j + 1] == 1:
			MatB[i][j] = 1
			MatB[i][j + 1] = 1
			MatB[i + 1][j] = 1
			MatB[i + 1][j + 1] = 1
			ans.append([i + 1, j + 1])
if MatB == MatA:
	print(len(ans))
	for i in range(len(ans)):
		print(*ans[i])
else:
	print(-1)


dims = input().split(' ')
n = int(dims[0])
m = int(dims[1])
matr = []
for i in range(n):
	row = []
	line = input().split(' ')
	for j in range(m):
		row.append(int(line[j]))
	matr.append(row)
for index in range(n):
	matr[index] = [0] + matr[index] + [0]
up_down_border = (m + 2) * [0]
matr = [up_down_border] + matr + [up_down_border]
k = 0
indexes = []
for i in range(1, n + 1):
	if k == -1:
		break
	for j in range(1, m + 1):
		if matr[i][j] == 1:
			if matr[i + 1][j] == 1 and matr[i][j + 1] == 1 and (matr[i + 1][j + 1] == 1):
				k += 1
				indexes.append((i, j))
			elif matr[i - 1][j] == 1 and matr[i - 1][j + 1] == 1 and (matr[i][j + 1] == 1):
				continue
			elif matr[i + 1][j] == 1 and matr[i + 1][j - 1] == 1 and (matr[i][j - 1] == 1):
				continue
			elif matr[i - 1][j] == 1 and matr[i - 1][j - 1] == 1 and (matr[i][j - 1] == 1):
				continue
			else:
				k = -1
				break
if k == -1:
	print(-1)
else:
	print(k)
	for i in range(k):
		print(indexes[i][0], indexes[i][1])


(n, m) = list(map(int, input().split()))
A = [list(map(int, input().split())) for i in range(n)]
ans = []
for i in range(n - 1):
	for j in range(m - 1):
		if A[i][j] == 1 and A[i + 1][j] == 1 and (A[i][j + 1] == 1) and (A[i + 1][j + 1] == 1):
			ans.append([i, j])
B = [[0] * m for i in range(n)]
for x in ans:
	B[x[0]][x[1]] = 1
	B[x[0] + 1][x[1]] = 1
	B[x[0]][x[1] + 1] = 1
	B[x[0] + 1][x[1] + 1] = 1
if A != B:
	print(-1)
else:
	print(len(ans))
	for x in ans:
		print(x[0] + 1, x[1] + 1)


def change_b_array(n, m, A):
	B = [[0 for j in range(m)] for i in range(n)]
	values = list()
	for i in range(n - 1):
		for j in range(m - 1):
			summa = A[i][j] + A[i][j + 1] + A[i + 1][j] + A[i + 1][j + 1]
			if summa == 4:
				B[i][j] = 1
				B[i + 1][j] = 1
				B[i][j + 1] = 1
				B[i + 1][j + 1] = 1
				values.append((i, j))
	for i in range(n):
		for j in range(m):
			if B[i][j] != A[i][j]:
				print(-1)
				return
	print(len(values))
	if len(values) == 0:
		return
	for (i, j) in values:
		print(i + 1, j + 1)
(n, m) = map(int, input().rstrip().split())
array_a = []
for i in range(n):
	string = [*map(int, input().rstrip().split())]
	array_a.append(string)
change_b_array(n, m, array_a)


(n, m) = map(int, input().split())
aa = []
bb = [[0 for _ in range(0, m)] for _ in range(0, n)]
for _ in range(0, n):
	lst = [int(i) for i in input().split()]
	aa.append(lst)
ss = []
for i in range(0, n - 1):
	for j in range(0, m - 1):
		if aa[i][j] == aa[i + 1][j] == aa[i][j + 1] == aa[i + 1][j + 1] == 1:
			(bb[i][j], bb[i + 1][j], bb[i][j + 1], bb[i + 1][j + 1]) = (1, 1, 1, 1)
			ss.append((i + 1, j + 1))
if aa == bb:
	print(len(ss))
	for i in ss:
		print(i[0], i[1])
else:
	print(-1)


(n, m) = map(int, input().split())
A = []
for _ in range(n):
	p = [int(x) for x in input().split()]
	A.append(p)
B = [[0 for i in range(m)] for j in range(n)]
C = []
for i in range(n - 1):
	for j in range(m - 1):
		if A[i][j] == 1:
			if A[i + 1][j] == 1 and A[i][j + 1] == 1 and (A[i + 1][j + 1] == 1):
				C.append([i, j])
				B[i][j] = 1
				B[i + 1][j] = 1
				B[i][j + 1] = 1
				B[i + 1][j + 1] = 1
			elif B[i][j] == 1:
				pass
			else:
				print(-1)
				exit()
for j in range(m):
	if A[n - 1][j] == 1:
		if B[n - 1][j] == 1:
			pass
		else:
			print(-1)
			exit()
for i in range(n):
	if A[i][m - 1] == 1:
		if B[i][m - 1] == 1:
			pass
		else:
			print(-1)
			exit()
print(len(C))
for i in C:
	print(i[0] + 1, i[1] + 1)


(n, m) = list(map(int, input().split()))
a = []
b = [[0 for i in range(m)] for j in range(n)]
ans = []
for i in range(n):
	a.append(list(map(int, input().split())))
for x in range(n - 1):
	for y in range(m - 1):
		if a[x][y] == a[x][y + 1] == a[x + 1][y] == a[x + 1][y + 1] == 1:
			b[x][y] = 1
			b[x][y + 1] = 1
			b[x + 1][y] = 1
			b[x + 1][y + 1] = 1
			ans.append(str(x + 1) + ' ' + str(y + 1))
if a == b:
	print(len(ans))
	for i in ans:
		print(i)
else:
	print(-1)


(n, m) = map(int, input().split())
a = [list(map(int, input().split())) for i in range(n)]
b = [[0] * m for i in range(n)]
ans = []
for i in range(n - 1):
	for j in range(m - 1):
		if a[i][j] == 1 and a[i + 1][j] == 1 and (a[i][j + 1] == 1) and (a[i + 1][j + 1] == 1):
			b[i][j] = 1
			b[i + 1][j] = 1
			b[i][j + 1] = 1
			b[i + 1][j + 1] = 1
			ans.append([i + 1, j + 1])
if a == b:
	print(len(ans))
	for i in ans:
		print(*i)
else:
	print(-1)


def main():
	(n, m1) = [int(j) for j in input().split()]
	l = []
	for i in range(n):
		l.append([int(j) for j in input().split()])
	ans = []
	ct = 0
	m = [[0 for i in range(m1)] for j in range(n)]
	for i in range(n - 1):
		for j in range(m1 - 1):
			if l[i][j] == 1 and l[i + 1][j] == 1 and (l[i][j + 1] == 1) and (l[i + 1][j + 1] == 1):
				ct += 1
				m[i][j] = 1
				m[i + 1][j] = 1
				m[i][j + 1] = 1
				m[i + 1][j + 1] = 1
				ans.append([i + 1, j + 1])
	for i in range(n):
		for j in range(m1):
			if l[i][j] == m[i][j]:
				continue
			else:
				print(-1)
				return
	print(ct)
	for i in range(ct):
		print(ans[i][0], ans[i][1])
main()


(n, m) = map(int, input().split())
mat = []
cnt = 0
for i in range(n):
	l = [int(i) for i in input().split()]
	cnt += l.count(1)
	mat.append(l)
ans = {}
for i in range(n - 1):
	for j in range(m - 1):
		ans[i, j] = 1
for i in range(n):
	for j in range(m):
		if mat[i][j] == 0:
			ans[i, j] = 0
			if (i - 1, j - 1) in ans:
				ans[i - 1, j - 1] = 0
			if (i - 1, j) in ans:
				ans[i - 1, j] = 0
			if (i, j - 1) in ans:
				ans[i, j - 1] = 0
mat1 = [[0 for j in range(m)] for i in range(n)]
for x in ans:
	if ans[x] == 1:
		a = x[0]
		b = x[1]
		mat1[a][b] = 1
		if a + 1 <= n - 1:
			mat1[a + 1][b] = 1
		if a + 1 <= n - 1 and b + 1 <= m - 1:
			mat1[a + 1][b + 1] = 1
		if b + 1 < m:
			mat1[a][b + 1] = 1
if mat != mat1:
	print(-1)
	exit()
cnt = 0
res = []
for x in ans:
	if ans[x] == 1:
		cnt += 1
		res.append([x[0], x[1]])
res.sort(key=lambda x: [x[0], x[1]])
print(cnt)
for x in res:
	print(x[0] + 1, x[1] + 1)


import pdb
(n, m) = map(int, input().split(' '))
matrix = []
for i in range(n):
	matrix.append(list(map(int, input().split(' '))))

def check_pos(matrix, x, y):
	if x + 1 >= len(matrix):
		return False
	if y + 1 >= len(matrix[0]):
		return False
	if matrix[x][y] == 0 or matrix[x + 1][y] == 0 or matrix[x][y + 1] == 0 or (matrix[x + 1][y + 1] == 0):
		return False
	matrix[x][y] = 2
	matrix[x + 1][y + 1] = 2
	matrix[x + 1][y] = 2
	matrix[x][y + 1] = 2
	return True
one_exists = False
result = []
for i in range(n):
	for j in range(m):
		if matrix[i][j] == 1:
			one_exists = True
		if check_pos(matrix, i, j):
			result.append((i + 1, j + 1))
if not one_exists:
	print('0')
	exit()
for i in range(n):
	for j in range(m):
		if matrix[i][j] == 1:
			print('-1')
			exit()
print(len(result))
for (x, y) in result:
	print('%d %d' % (x, y))


(n, m) = map(int, input().split())
arr = []
for _ in range(n):
	arr.append(list(map(int, input().split())))
arrb = [[0] * m for _ in range(n)]
arr1 = []
count = 0
for i in range(n - 1):
	for j in range(m - 1):
		if arr[i][j] == 1 and arr[i + 1][j] == 1 and (arr[i][j + 1] == 1) and (arr[i + 1][j + 1] == 1):
			arrb[i][j] = arrb[i + 1][j] = arrb[i][j + 1] = arrb[i + 1][j + 1] = 1
			arr1.append([i + 1, j + 1])
			count += 1
flag = True
for i in range(n):
	for j in range(m):
		if arr[i][j] != arrb[i][j]:
			flag = False
			break
	if flag != True:
		break
if flag and count != 0:
	print(count)
	for ar in arr1:
		print(*ar)
elif count == 0 and flag:
	print(0)
else:
	print(-1)


I = input
(n, m) = map(int, I().split())
matrix = [[] for i in range(n)]
for i in range(n):
	matrix[i] = list(map(int, I().split()))
ans = []
for i in range(n - 1):
	for j in range(m - 1):
		if matrix[i][j] * matrix[i + 1][j] * matrix[i][j + 1] * matrix[i + 1][j + 1] > 0:
			matrix[i][j] = 2
			matrix[i][j + 1] = 2
			matrix[i + 1][j] = 2
			matrix[i + 1][j + 1] = 2
			ans.append([i + 1, j + 1])
count = 0
for i in range(n):
	for j in range(m):
		if matrix[i][j] == 1:
			count += 1
if count > 0:
	print(-1)
else:
	print(len(ans))
	for i in range(len(ans)):
		print(ans[i][0], ans[i][1])


import sys
input = sys.stdin.readline
(n, m) = map(int, input().split())
mat = []
for _ in range(n):
	mat.append([int(i) for i in input().split()])
b = [[0 for _ in range(m)] for _ in range(n)]
ans = []
for i in range(n - 1):
	for j in range(m - 1):
		if mat[i][j] == mat[i + 1][j] == mat[i][j + 1] == mat[i + 1][j + 1] == 1:
			b[i][j] = b[i + 1][j] = b[i][j + 1] = b[i + 1][j + 1] = 1
			ans.append((i, j))
if mat == b:
	print(len(ans))
	for (i, j) in ans:
		print(i + 1, j + 1)
else:
	print(-1)


n_m = list(map(int, input().split(' ')))
matrix = []
line = []

def convert(i, j, mat):
	for p in range(i, i + 2):
		for q in range(j, j + 2):
			mat[p][q] = 1
	return mat

def check(i, j, mat):
	for p in range(i, i + 2):
		for q in range(j, j + 2):
			if mat[p][q] == 0:
				return False
	return True
for i in range(n_m[0]):
	line = list(map(int, input().split(' ')))
	matrix.append(line)
prop_matrix = []
for i in range(n_m[0]):
	prop_matrix.append(matrix[i][:])
for i in range(n_m[0]):
	for j in range(n_m[1]):
		prop_matrix[i][j] = 0
steps = []
for i in range(n_m[0] - 1):
	for j in range(n_m[1] - 1):
		if check(i, j, matrix):
			prop_matrix = convert(i, j, prop_matrix)
			steps.append([i, j])

def final_check(mat1, mat2, size):
	for i in range(size[0]):
		for j in range(size[1]):
			if mat1[i][j] != mat2[i][j]:
				return False
	return True
if final_check(prop_matrix, matrix, n_m):
	print(len(steps))
	for i in steps:
		print(str(i[0] + 1) + ' ' + str(i[1] + 1))
else:
	print(-1)


(n, m) = map(int, input().split())
a = []
c = []
for _ in range(n):
	a.append(list(map(int, input().split())))
	c.append([0] * m)
b = []
flag = True
for i in range(n):
	for j in range(m):
		if i + 1 < n and j + 1 < m:
			if a[i][j] == 1 and a[i + 1][j] == 1 and (a[i][j + 1] == 1) and (a[i + 1][j + 1] == 1):
				c[i][j] = 1
				c[i + 1][j] = 1
				c[i][j + 1] = 1
				c[i + 1][j + 1] = 1
				b.append([i + 1, j + 1])
		if a[i][j] == 1:
			flag = False
if flag == True:
	print(0)
elif b == []:
	print(-1)
else:
	flag = True
	for i in range(n):
		for j in range(m):
			if a[i][j] != c[i][j]:
				flag = False
				break
	if flag == True:
		print(len(b))
		for i in b:
			print(*i)
	else:
		print(-1)


from heapq import heappush, heappop
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations
import sys
import bisect
import string
sys.setrecursionlimit(10 ** 6)

def SI():
	return input().split()

def MI():
	return map(int, input().split())

def I():
	return int(input())

def LI():
	return [int(i) for i in input().split()]
YN = ['Yes', 'No']
mo = 10 ** 9 + 7
a = []
(n, m) = MI()
for i in range(n):
	h = LI()
	a.append(h)
b = [[0] * m for i in range(n)]
ans = []
for r in range(n - 1):
	for c in range(m - 1):
		if a[r][c] + a[r + 1][c] + a[r][c + 1] + a[r + 1][c + 1] == 4:
			ans += [(r + 1, c + 1)]
			b[r][c] = 1
			b[r][c + 1] = 1
			b[r + 1][c] = 1
			b[r + 1][c + 1] = 1
if a == b:
	print(len(ans))
	for j in ans:
		print(*j)
else:
	print(-1)


from collections import Counter as C, defaultdict as D, deque as Q
from operator import itemgetter as I
from itertools import product as P
from bisect import bisect_left as BL, bisect_right as BR
from heapq import heappush as HPUSH, heappop as HPOP
from math import floor as MF, ceil as MC, gcd as MG, factorial as F, sqrt as SQRT, inf as INFINITY, log as LOG
from sys import stdin, stdout
INPUT = stdin.readline
PRINT = stdout.write

def player1():
	print('')

def player2():
	print('')

def isPrime(n):
	for i in range(2, MC(SQRT(n)) + 1):
		if n % i == 0:
			return False
	return True

def factors(x):
	ans = []
	for i in range(1, MC(SQRT(x)) + 1):
		if x % i == 0:
			ans.append(i)
			if x % (x // i) == 0:
				ans.append(x // i)
	return ans

def checkPath(source, destination, g):
	visited = [0] * 101
	q = Q()
	q.append(source)
	visited[source] = 1
	while q:
		node = q.popleft()
		if node == destination:
			return 1
		for v in g[node]:
			if not visited[v]:
				q.append(v)
				visited[v] = 1
	return 0

def main():
	(n, m) = map(int, INPUT().split())
	a = []
	for i in range(n):
		a.append([*map(int, INPUT().split())])
	b = [[0 for i in range(m)] for j in range(n)]
	ans = []
	for (i, j) in P(range(n - 1), range(m - 1)):
		if a[i][j] == 1 and a[i][j + 1] == 1 and (a[i + 1][j] == 1) and (a[i + 1][j + 1] == 1):
			b[i][j] = 1
			b[i][j + 1] = 1
			b[i + 1][j] = 1
			b[i + 1][j + 1] = 1
			ans.append((i + 1, j + 1))
	for (i, j) in P(range(n), range(m)):
		if a[i][j] != b[i][j]:
			break
	else:
		PRINT('%d\n' % len(ans))
		for (x, y) in ans:
			PRINT('%d %d\n' % (x, y))
		return
	PRINT('%d\n' % -1)
main()


from sys import stdin
(n, m) = (int(i) for i in stdin.readline().split())
a = list()
for i in range(0, n):
	a.append(list((int(i) for i in stdin.readline().split())))
c = list()
for i in range(0, n - 1):
	for j in range(0, m - 1):
		if a[i][j] >= 1 and a[i + 1][j] >= 1 and (a[i][j + 1] >= 1) and (a[i + 1][j + 1] >= 1):
			a[i][j] += 1
			a[i + 1][j] += 1
			a[i][j + 1] += 1
			a[i + 1][j + 1] += 1
			c.append((i, j))
possible = True
for i in a:
	if (1 in i) == True:
		possible = False
		break
if possible == False:
	print(-1)
else:
	print(len(c))
	for i in c:
		print(i[0] + 1, i[1] + 1)


(n, m) = map(int, input().split(' '))
y = []
for i in range(n):
	c = list(map(int, input().split()))
	y.append(c)
count = []
y1 = [[0 for i in range(m)] for j in range(n)]
for i in range(1, n):
	for j in range(1, m):
		if y[i][j] == 1:
			if y[i - 1][j - 1] == y[i - 1][j] == y[i][j - 1] == 1:
				y1[i - 1][j - 1] = y1[i - 1][j] = y1[i][j - 1] = y1[i][j] = 1
				count.append([i, j])
if y == y1:
	print(len(count))
	for i in count:
		print(i[0], i[1])
else:
	print(-1)


(n, m) = map(int, input().split())
a = [[0] * m for i in range(n)]
for i in range(n):
	a[i] = [int(i) for i in input().split()]
ans = []
for i in range(n - 1):
	for j in range(m - 1):
		if a[i][j] * a[i][j + 1] * a[i + 1][j] * a[i + 1][j + 1] > 0:
			a[i][j] = a[i + 1][j] = a[i][j + 1] = a[i + 1][j + 1] = 2
			ans.append([i, j])
fl = False
for i in range(n):
	for j in range(m):
		if a[i][j] == 1:
			fl = True
			break
	if fl:
		break
if fl:
	print(-1)
else:
	print(len(ans))
	for k in ans:
		print(k[0] + 1, k[1] + 1)


(n, m) = map(int, input().split())
a = []
for _ in range(n):
	row = [int(x) for x in input().split()]
	a.append(row)
ans = []
b = [[0 for _ in range(m)] for _ in range(n)]
for i in range(n - 1):
	for j in range(m - 1):
		if a[i][j] == 1 and a[i + 1][j] == 1 and (a[i][j + 1] == 1) and (a[i + 1][j + 1] == 1):
			ans.append((i + 1, j + 1))
			b[i][j] = 1
			b[i + 1][j] = 1
			b[i][j + 1] = 1
			b[i + 1][j + 1] = 1
f = True
for i in range(n):
	for j in range(m):
		if a[i][j] != b[i][j]:
			f = False
			break
if f:
	print(len(ans))
	for p in ans:
		print(*p)
else:
	print(-1)


(n, m) = list(map(int, input().split()))
mas = [None] * n
masmas = [[None for i in range(m - 1)] for j in range(n - 1)]
for i in range(n):
	mas[i] = list(map(int, input().split()))
for i in range(n - 1):
	for j in range(m - 1):
		if mas[i][j] == 1 and mas[i + 1][j] == 1 and (mas[i][j + 1] == 1) and (mas[i + 1][j + 1] == 1):
			masmas[i][j] = 1
		else:
			masmas[i][j] = 0
mascheck = [[0 for i in range(m)] for j in range(n)]
for i in range(n - 1):
	for j in range(m - 1):
		if masmas[i][j] == 1:
			mascheck[i][j] = 1
			mascheck[i + 1][j] = 1
			mascheck[i][j + 1] = 1
			mascheck[i + 1][j + 1] = 1
if mascheck == mas:
	flag = True
	a = 0
	qw = []
	for i in range(n - 1):
		for j in range(m - 1):
			if masmas[i][j] == 1:
				qw += [i, j]
				flag = False
				a += 1
	if flag:
		print(0)
	else:
		print(a)
		for b in range(a):
			print(qw[2 * b] + 1, qw[2 * b + 1] + 1)
else:
	print(-1)


def find(n, m, A, B):
	step = []
	for i in range(1, n):
		for j in range(1, m):
			if A[i][j] == 1 and A[i - 1][j] == 1 and (A[i][j - 1] == 1) and (A[i - 1][j - 1] == 1):
				B[i][j] = 1
				B[i - 1][j - 1] = 1
				B[i][j - 1] = 1
				B[i - 1][j] = 1
				step.append([i, j])
	for i in range(n):
		for j in range(m):
			if A[i][j] != B[i][j]:
				return -1
	return step
(n, m) = map(int, input().split())
matrix = []
for i in range(n):
	matrix.append(list(map(int, input().split())))
B = [[0 for i in range(m)] for i in range(n)]
step = find(n, m, matrix, B)
if step == -1:
	print(-1)
else:
	print(len(step))
	for i in step:
		print(i[0], i[1])


(n, m) = map(int, input().split())
a = []
for i in range(n):
	a += [list(map(int, input().split()))]
b = [[0 for i in range(m)] for i in range(n)]
k = 0
f = []
for i in range(n - 1):
	for j in range(m - 1):
		if a[i][j] == 1 and a[i][j + 1] == 1 and (a[i + 1][j] == 1) and (a[i + 1][j + 1] == 1):
			b[i][j] = 1
			b[i + 1][j] = 1
			b[i][j + 1] = 1
			b[i + 1][j + 1] = 1
			k += 1
			f.append([i + 1, j + 1])
cor = 1
for i in range(n):
	for j in range(m):
		if a[i][j] != b[i][j]:
			cor = 0
			break
if cor:
	print(k)
	for i in range(k):
		print(' '.join(map(str, f[i])))
else:
	print(-1)


def equal(matrix1, matrix2, n, m):
	for i in range(n):
		for j in range(m):
			if matrix1[i][j] != matrix2[i][j]:
				return False
	return True
(n, m) = map(int, input().split())
matrix = [[] for j in range(n)]
for i in range(n):
	matrix[i] = list(map(int, input().split()))
matrix2 = [[0 for i in range(m)] for j in range(n)]
ans = []
for i in range(n - 1):
	for j in range(m - 1):
		if matrix[i][j] == 1:
			if matrix[i + 1][j] == 1:
				if matrix[i][j + 1] == 1:
					if matrix[i + 1][j + 1] == 1:
						ans.append([i, j])
						matrix2[i][j] = 1
						matrix2[i + 1][j] = 1
						matrix2[i + 1][j + 1] = 1
						matrix2[i][j + 1] = 1
if equal(matrix, matrix2, n, m):
	print(len(ans))
	for i in ans:
		print(i[0] + 1, i[1] + 1)
else:
	print(-1)


(n, m) = map(int, input().split())
a = []
for i in range(n):
	a.append(list(map(int, input().split())))
b = [[0] * m for i in range(n)]
l = []
for i in range(n):
	for j in range(m):
		if a[i][j] == 1:
			if i + 1 < n and j + 1 < m:
				if a[i][j] == 1 and a[i + 1][j] == 1 and (a[i][j + 1] == 1) and (a[i + 1][j + 1] == 1):
					l.append((i + 1, j + 1))
					b[i][j] = 1
					b[i + 1][j] = 1
					b[i][j + 1] = 1
					b[i + 1][j + 1] = 1
lol = 0
for i in range(n):
	for j in range(m):
		if a[i][j] != b[i][j]:
			lol = 1
			break
	if lol == 1:
		break
if lol == 1:
	print(-1)
else:
	print(len(l))
	for i in l:
		print(*i)


import sys
mod = 1000000007

def get_array():
	return list(map(int, sys.stdin.readline().split()))

def get_ints():
	return map(int, sys.stdin.readline().split())

def input():
	return sys.stdin.readline()

def print_array(a):
	print(' '.join(map(str, a)))

def main():
	(n, m) = get_ints()
	A = [get_array() for _ in range(n)]
	ans = []
	counted = [[False for _ in range(m)] for _ in range(n)]
	for i in range(n - 1):
		for j in range(m - 1):
			if A[i][j] == A[i][j + 1] == A[i + 1][j] == A[i + 1][j + 1] == 1:
				ans.append([i, j])
				counted[i][j] = counted[i][j + 1] = counted[i + 1][j] = counted[i + 1][j + 1] = True
	flag = True
	for i in range(n):
		for j in range(m):
			if A[i][j] == 1 and (not counted[i][j]):
				print('-1')
				flag = False
				break
		if not flag:
			break
	if flag:
		print(len(ans))
		for line in ans:
			print(line[0] + 1, line[1] + 1)
main()


p = input().split()
n = int(p[0])
m = int(p[1])
a = [[0] * m] * n
b = [[0 for i in range(m)] for j in range(n)]
b1 = []
b2 = []
for i in range(n):
	p = input().split()
	a[i] = p
ans = []
for i in range(n):
	a[i] = [int(jol) for jol in a[i]]
for i in range(n - 1):
	for j in range(m - 1):
		if a[i][j] & a[i + 1][j] & a[i + 1][j + 1] & a[i][j + 1] == 1:
			b1 = b[i]
			b2 = b[i + 1]
			b1[j] = 1
			b1[j + 1] = 1
			b2[j] = 1
			b2[j + 1] = 1
			ans.append(i + 1)
			ans.append(j + 1)
if a != b:
	print(-1)
	quit()
print(int(len(ans) / 2))
i = 0
while i < len(ans):
	print(ans[i], ans[i + 1])
	i += 2


(n, m) = map(int, input().split())
matr = [list(map(int, input().split())) for _ in range(n)]
new_matr = [[0] * m for _ in range(n)]
ans = ''
for i in range(n - 1):
	for j in range(m - 1):
		if matr[i][j] == matr[i + 1][j] == matr[i][j + 1] == matr[i + 1][j + 1] == 1:
			ans += f'{i + 1} {j + 1}\n'
			(new_matr[i][j], new_matr[i + 1][j], new_matr[i][j + 1], new_matr[i + 1][j + 1]) = (1, 1, 1, 1)
if new_matr == matr:
	print(ans.count('\n'), ans, sep='\n')
else:
	print(-1)


(n, m) = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]
b = [[0] * m for _ in range(n)]
ans = []
for i in range(n - 1):
	for j in range(m - 1):
		if a[i][j] == a[i][j + 1] == a[i + 1][j] == a[i + 1][j + 1] == 1:
			b[i][j] = b[i][j + 1] = b[i + 1][j] = b[i + 1][j + 1] = 1
			ans.append([i + 1, j + 1])
if any((a[i][j] != b[i][j] for i in range(n) for j in range(m))):
	print(-1)
else:
	print(len(ans))
	print(*('{} {}'.format(i, j) for (i, j) in ans), sep='\n')


(n, m) = (int(x) for x in input().split())
mat = [[int(x) for x in input().split()] for _ in range(n)]
delta = [(0, 0), (1, 0), (0, 1), (1, 1)]
ans = list()
for i in range(n - 1):
	for j in range(m - 1):
		flag = 0
		for val in delta:
			x = i + val[0]
			y = j + val[1]
			if mat[x][y] == 0:
				flag = 1
				break
		if not flag:
			for val in delta:
				x = i + val[0]
				y = j + val[1]
				mat[x][y] = -1
			ans.append((i, j))
flag = 0
for i in range(n):
	for j in range(m):
		if mat[i][j] == 1:
			flag = 1
			break
if not flag:
	print(len(ans))
	for i in ans:
		print(i[0] + 1, i[1] + 1)
else:
	print(-1)


import sys
I = sys.stdin.readline
(n, m) = map(int, I().split())
a = []
for i in range(n):
	a.append(list(map(int, I().split())))
b = [[0 for i in range(m)] for i in range(n)]
cnt = 0
steps = []

def is_zero(i, j):
	if a[i][j] == 0 or a[i + 1][j] == 0 or a[i][j + 1] == 0 or (a[i + 1][j + 1] == 0):
		return True
	else:
		return False

def makeone(i, j):
	b[i][j] = 1
	b[i + 1][j] = 1
	b[i][j + 1] = 1
	b[i + 1][j + 1] = 1
for i in range(n - 1):
	for j in range(m - 1):
		if not is_zero(i, j):
			makeone(i, j)
			cnt += 1
			steps.append((i + 1, j + 1))
if a == b:
	print(cnt)
	for i in steps:
		print(*i)
else:
	print(-1)


(m, n) = map(int, input().split())
(l, b) = ([], [])
for i in range(m):
	l.append(list(map(int, input().split())))
for i in range(m):
	b.append([0] * n)
if l.count(0) == m * n:
	print(0)
else:
	ans = []
	flag = 0
	for i in range(m - 1):
		for j in range(n - 1):
			if l[i][j] == 1 and l[i][j + 1] == 1 and (l[i + 1][j + 1] == 1) and (l[i + 1][j] == 1):
				b[i][j] = 1
				b[i][j + 1] = 1
				b[i + 1][j + 1] = 1
				b[i + 1][j] = 1
				ans.append([i + 1, j + 1])
			if b == l:
				flag = 1
				break
	if flag == 0:
		print(-1)
	else:
		print(len(ans))
		for i in ans:
			print(i[0], i[-1])


(m, n) = map(int, input().split())
a = [[int(j) for j in input().split()] for i in range(m)]
b = [[0 for j in range(n)] for i in range(m)]
k = 0
c = []
for i in range(m - 1):
	for j in range(n - 1):
		if a[i][j] == 1 and a[i + 1][j] == 1 and (a[i][j + 1] == 1) and (a[i + 1][j + 1] == 1):
			c.append(str(i + 1) + ' ' + str(j + 1))
			b[i][j] = 1
			b[i][j + 1] = 1
			b[i + 1][j] = 1
			b[i + 1][j + 1] = 1
			k += 1
		if a == b:
			break
	if a == b:
		break
if a != b:
	print(-1)
else:
	print(k)
	for i in c:
		print(i)


(n, m) = map(int, input().split())
(lst, ans, f) = ([], [], 0)
for i in range(n):
	lst.append(list(map(int, input().split())))
for i in range(n):
	for j in range(m):
		if lst[i][j] == 1:
			if not (i - 1 >= 0 and j - 1 >= 0 and (lst[i - 1][j - 1] == lst[i - 1][j] == lst[i][j - 1] == 1) or (i + 1 <= n - 1 and j + 1 <= m - 1 and (lst[i + 1][j + 1] == lst[i + 1][j] == lst[i][j + 1] == 1)) or (i + 1 <= n - 1 and j - 1 >= 0 and (lst[i][j - 1] == lst[i + 1][j - 1] == lst[i + 1][j] == 1)) or (i - 1 >= 0 and j + 1 <= m - 1 and (lst[i - 1][j + 1] == lst[i][j + 1] == lst[i - 1][j] == 1))):
				f = 1
				break
			if i + 1 <= n - 1 and j + 1 <= m - 1 and (lst[i + 1][j + 1] == lst[i + 1][j] == lst[i][j + 1] == 1):
				ans.append([i + 1, j + 1])
	if f == 1:
		break
if f == 1:
	print(-1)
else:
	print(len(ans))
	for i in ans:
		print(*i)


(n, m) = map(int, input().split())
b = [[0 for i in range(m)] for j in range(n)]
a = []
for i in range(n):
	s = list(map(int, input().split()))
	a.append(s)
v = []
for i in range(n - 1):
	for j in range(m - 1):
		if a[i][j] == 1 and a[i + 1][j + 1] == 1 and (a[i + 1][j] == 1) and (a[i][j + 1] == 1):
			v.append((i, j))
			b[i][j] = 1
			b[i + 1][j + 1] = 1
			b[i + 1][j] = 1
			b[i][j + 1] = 1
check = True
for i in range(n):
	for j in range(m):
		if b[i][j] is not a[i][j]:
			check = False
if check == False:
	print(-1)
else:
	print(len(v))
	for x in v:
		print(x[0] + 1, x[1] + 1)


(n, m) = map(int, input().split())
a = []
for i in range(n):
	t = list(map(int, input().split()))
	a.append(t)
l = []
b = [[0 for i in range(m)] for j in range(n)]
for i in range(n - 1):
	for j in range(m - 1):
		if a[i][j] == 1:
			if a[i + 1][j] == 1:
				if a[i][j + 1] == 1:
					if a[i + 1][j + 1] == 1:
						l.append((i, j))
						b[i][j] = 1
						b[i + 1][j] = 1
						b[i][j + 1] = 1
						b[i + 1][j + 1] = 1
if a == b:
	print(len(l))
	for i in l:
		print(i[0] + 1, i[1] + 1)
else:
	print(-1)


def solve(matrix):
	answer = ''
	other = [[0] * m for i in range(n)]
	cnt = 0
	for i in range(n - 1):
		for j in range(m - 1):
			if matrix[i][j] != 1 or matrix[i + 1][j + 1] != 1 or matrix[i + 1][j] != 1 or (matrix[i][j + 1] != 1):
				continue
			other[i][j] = 1
			other[i][j + 1] = 1
			other[i + 1][j] = 1
			other[i + 1][j + 1] = 1
			cnt += 1
			answer += str(i + 1) + ' ' + str(j + 1) + '\n'
	for i in range(n):
		for j in range(m):
			if matrix[i][j] != other[i][j]:
				return '-1'
	return str(cnt) + '\n' + answer
(n, m) = map(int, input().split())
a = []
for i in range(n):
	a.append(list(map(int, input().split())))
print(solve(a))


import io, sys, atexit, os
import math as ma
from decimal import Decimal as dec
from itertools import permutations
from itertools import combinations

def li():
	return list(map(int, input().split()))

def num():
	return map(int, input().split())

def nu():
	return int(input())

def find_gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def lcm(x, y):
	gg = find_gcd(x, y)
	return x * y // gg
mm = 1000000007
yp = 0

def solve():
	t = 1
	for tt in range(t):
		(n, m) = num()
		a = [0] * n
		xx = []
		fl = True
		b = [0] * n
		for i in range(n):
			a[i] = li()
			b[i] = [0] * m
		for i in range(n - 1):
			for j in range(m - 1):
				if a[i][j] == 1 and a[i][j + 1] == 1 and (a[i + 1][j] == 1) and (a[i + 1][j + 1] == 1):
					xx.append((i, j))
					b[i][j] = 1
					b[i][j + 1] = 1
					b[i + 1][j] = 1
					b[i + 1][j + 1] = 1
		for i in range(n):
			for j in range(m):
				if a[i][j] != b[i][j]:
					fl = False
		if fl:
			print(len(xx))
			for i in range(len(xx)):
				print(xx[i][0] + 1, xx[i][1] + 1)
		else:
			print(-1)

def __starting_point():
	solve()
__starting_point()


(n, m) = input().split(' ')
(n, m) = (int(n), int(m))
A = []
checked = [[0 for j in range(m)] for i in range(n)]
for i in range(n):
	A.append(list(input().split(' ')))
ok = True
n_operations = 0
coords = []
for i in range(n):
	if not ok:
		break
	for j in range(m):
		if not ok:
			break
		if A[i][j] == '1':
			if i < n - 1 and j < m - 1:
				if checked[i][j] == 0:
					if A[i][j + 1] == '1' and A[i + 1][j] == '1' and (A[i + 1][j + 1] == '1'):
						n_operations += 1
						coords.append((i, j))
						checked[i][j] = 1
						checked[i][j + 1] = 1
						checked[i + 1][j] = 1
						checked[i + 1][j + 1] = 1
					else:
						ok = False
				elif A[i][j + 1] == '1' and A[i + 1][j] == '1' and (A[i + 1][j + 1] == '1'):
					n_operations += 1
					coords.append((i, j))
					checked[i][j] = 1
					checked[i][j + 1] = 1
					checked[i + 1][j] = 1
					checked[i + 1][j + 1] = 1
			elif checked[i][j] == 0:
				ok = False
if ok:
	print(n_operations)
	for (x, y) in coords:
		print(x + 1, y + 1)
else:
	print(-1)


(n, m) = map(int, input().split())
l = []
for i in range(n):
	l.append(list(map(int, input().split())))
b = [[0] * m for _ in range(n)]
ops = []
for i in range(n - 1):
	for j in range(m - 1):
		if l[i][j] == 1 and l[i + 1][j] == 1 and (l[i][j + 1] == 1) and (l[i + 1][j + 1] == 1):
			ops.append([i + 1, j + 1])
			for x in range(2):
				for y in range(2):
					b[i + x][j + y] = 1
if l == b:
	print(len(ops))
	for i in ops:
		print(i[0], i[1])
else:
	print(-1)


(n, m) = list(map(int, input().split()))
A = [list(map(int, input().split())) for i in range(n)]
B = [[0 for i in range(m)] for j in range(n)]
ops = []
for i in range(n - 1):
	for j in range(m - 1):
		if all([A[i][j], A[i + 1][j], A[i][j + 1], A[i + 1][j + 1]]):
			ops.append((i + 1, j + 1))
			B[i][j] = 1
			B[i + 1][j] = 1
			B[i][j + 1] = 1
			B[i + 1][j + 1] = 1
flag = True
for i in range(n):
	for j in range(m):
		flag &= A[i][j] == B[i][j]
if flag:
	print(len(ops))
	for o in ops:
		print(*o)
else:
	print(-1)


import sys

def solve(A, n, m):
	oper = []
	B = [[0 for i in a] for a in A]
	for i in range(n):
		for j in range(m):
			if A[i][j] == 1 and A[i + 1][j] == 1 and (A[i][j + 1] == 1) and (A[i + 1][j + 1] == 1):
				oper.append((i + 1, j + 1))
				B[i][j] = 1
				B[i + 1][j] = 1
				B[i][j + 1] = 1
				B[i + 1][j + 1] = 1
	for i in range(n):
		for j in range(m):
			if B[i][j] != A[i][j]:
				return (False, [])
	return (True, oper)
in_file = sys.stdin
(n, m) = map(int, in_file.readline().strip().split())
A = []
for _ in range(n):
	A.append(list(map(int, in_file.readline().strip().split())))
	A[-1].append(0)
A.append([0 for i in range(m + 1)])
(good, oper) = solve(A, n, m)
if not good:
	sys.stdout.write('-1')
else:
	sys.stdout.write(str(len(oper)) + '\n')
	for (x, y) in oper:
		sys.stdout.write(str(x) + ' ' + str(y) + '\n')
sys.stdout.flush()


(n, m) = map(int, input().split())
a = [[0 for i2 in range(m)] for i in range(n)]
b = []
sb = 0
out = []
for i in range(n):
	b.append([int(i2) for i2 in input().split()])
	sb += sum(b[-1])
for i in range(n - 1):
	for i2 in range(m - 1):
		if b[i][i2] == b[i][i2 + 1] and b[i + 1][i2 + 1] == b[i + 1][i2] and (b[i][i2] == b[i + 1][i2]) and (b[i][i2] == 1):
			a[i][i2] = 1
			a[i][i2 + 1] = 1
			a[i + 1][i2] = 1
			a[i + 1][i2 + 1] = 1
			out.append([i, i2])
sa = 0
for i in a:
	sa += sum(i)
if sa == sb:
	print(len(out))
	for i in out:
		print(i[0] + 1, i[1] + 1)
else:
	print(-1)


(n, m) = [int(x) for x in input().strip().split()]
A = []
for i in range(n):
	A.append([int(x) for x in input().strip().split()])
sqs = []

def msq(i, j):
	res = True
	for ip in range(2):
		for jp in range(2):
			if i + ip >= n or i + ip < 0 or j + jp >= m or (j + jp < 0):
				return False
			if A[i + ip][j + jp] == 0:
				res = False
				break
	if res:
		sqs.append((i, j))
		return True
	else:
		return False

def pos(i, j):
	if (i, j) in sqs:
		return True
	if (i - 1, j) in sqs:
		return True
	if (i - 1, j - 1) in sqs:
		return True
	if (i, j - 1) in sqs:
		return True
	return False
ist = True
for i in range(n):
	for j in range(m):
		if A[i][j] == 1:
			if msq(i, j) or pos(i, j):
				continue
			else:
				ist = False
				break
if ist:
	print(len(sqs))
	for s in sqs:
		print(s[0] + 1, s[1] + 1)
else:
	print(-1)


(n, m) = map(int, input().split())
goal = [list(map(int, input().split())) for i in range(n)]
start = [[0] * m for i in range(n)]
cnt = 0
operation = []
for i in range(n - 1):
	for j in range(m - 1):
		if goal[i][j] == goal[i][j + 1] and goal[i][j + 1] == goal[i + 1][j] and (goal[i + 1][j + 1] == goal[i + 1][j]) and (goal[i][j] == 1):
			cnt += 1
			start[i][j] = 1
			start[i][j + 1] = 1
			start[i + 1][j + 1] = 1
			start[i + 1][j] = 1
			operation.append([i + 1, j + 1])
if start == goal:
	print(cnt)
	for i in operation:
		print(i[0], i[1])
else:
	print(-1)


import math
size = []
matrix = []
for t in input().split(' '):
	size.append(int(t))
B = [['0' for col in range(size[1])] for row in range(size[0])]
for ite in range(0, size[0]):
	matrix.append(input().split(' '))
count = 0
points = []
for x in range(0, size[0] - 1):
	for y in range(0, size[1] - 1):
		if int(matrix[x][y]) == 1 and int(matrix[x][y + 1]) == 1 and (int(matrix[x + 1][y]) == 1) and (int(matrix[x + 1][y + 1]) == 1):
			points.append([x + 1, y + 1])
			B[x][y] = '1'
			B[x][y + 1] = '1'
			B[x + 1][y] = '1'
			B[x + 1][y + 1] = '1'
			count = count + 1
if B != matrix:
	print(-1)
else:
	print(count)
	for point in points:
		print(*point)


import sys
from collections import defaultdict as dc
from collections import Counter
from bisect import bisect_right
import math
(n, m) = map(int, input().split())
l = []
for _ in range(n):
	l.append(list(map(int, input().split())))
x = [[0 for j in range(m)] for i in range(n)]
c = 0
p = []
f = 0
for i in range(n - 1):
	for j in range(m - 1):
		if l[i][j] == 1:
			if l[i + 1][j] == 1 and l[i][j + 1] == 1 and (l[i + 1][j + 1] == 1):
				c += 1
				p.append([i + 1, j + 1])
				x[i][j] = 1
				x[i + 1][j] = 1
				x[i + 1][j + 1] = 1
				x[i][j + 1] = 1
			elif x[i][j] == 1 and (not (l[i + 1][j] and l[i][j + 1] and l[i + 1][j + 1])):
				continue
			else:
				f = 1
				break
		if f:
			break
	if f:
		break
if f:
	print(-1)
else:
	f = 0
	for i in range(n):
		for j in range(m):
			if l[i][j] != x[i][j]:
				f = 1
				break
		if f:
			break
	if f:
		print(-1)
	else:
		print(c)
		for t in p:
			print(*t)


import sys

def input():
	return sys.stdin.readline()[:-1]
(n, m) = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]
b = [[0 for _ in range(m)] for _ in range(n)]
cnt = 0
ans = []
for i in range(n):
	cnt += a[i].count(1)
while cnt > 0:
	for k in range((n - 1) * m):
		(i, j) = (k // m, k % m)
		if j == m - 1:
			continue
		if a[i][j] * a[i][j + 1] * a[i + 1][j] * a[i + 1][j + 1] == 1 and b[i][j] * b[i][j + 1] * b[i + 1][j] * b[i + 1][j + 1] == 0:
			ans.append([i + 1, j + 1])
			cnt -= 4 - (b[i][j] + b[i][j + 1] + b[i + 1][j] + b[i + 1][j + 1])
			b[i][j] = 1
			b[i][j + 1] = 1
			b[i + 1][j] = 1
			b[i + 1][j + 1] = 1
			break
	else:
		print(-1)
		sys.exit()
print(len(ans))
for x in ans:
	print(*x)


false = False
true = True
null = None
TEST = false
try:
	import sys
	for arg in sys.argv:
		if arg == 'test':
			print('test mode')
			TEST = True
	pass
except:
	pass

def AddImports(libraryNames):
	for libname in libraryNames:
		if type(libname) == type(tuple()):
			short = libname[1]
			libname = libname[0]
		else:
			short = None
		try:
			lib = __import__(libname)
		except ImportError:
			pass
		else:
			if short:
				globals()[short] = lib
			else:
				globals()[libname] = lib
	return True
libnames = ['functools', 'math', 'collections']
AddImports(libnames)
IntellisenseHint = False
if IntellisenseHint:
	import functools
	import math
	import collections

def it(args, *arg):
	if TEST:
		print(args, *arg)

def floatEqual(a, b):
	diff = math.fabs(a - b)
	if diff < 1e-10:
		return True
	else:
		return diff <= 1e-08 * max(math.fabs(a), math.fabs(b))

def ria():
	return list(map(int, input().strip(' ').split(' ')))

def rsa():
	return list(map(str, input().strip('\n').split(' ')))

def create2DArray(rows, cols, val=False):
	return [[val for c in range(cols)] for r in range(rows)]

def create3DArray(zs, ys, xs, val=False):
	return [[[val for x in range(xs)] for y in range(ys)] for z in range(zs)]

def print2DArray(array):
	for r in range(len(array)):
		it(*array[r])
from sys import stdin
input = stdin.readline
import copy
from collections import deque
sys.setrecursionlimit(10000)

def solve():
	(n, m) = ria()
	mat = create2DArray(n, m, 0)
	for r in range(n):
		mat[r] = ria()
	seq = []
	dx = [0, 0, +1, +1]
	dy = [0, +1, 0, +1]
	for r in range(n - 1):
		for c in range(m - 1):
			AllOne = True
			for i in range(4):
				(nr, nc) = (r + dy[i], c + dx[i])
				if nr < 0 or nr >= n or nc < 0 or (nc >= m):
					AllOne = False
					break
				if mat[nr][nc] != 1:
					AllOne = False
			if AllOne:
				seq.append([r + 1, c + 1])
	b = create2DArray(n, m, 0)
	for s in seq:
		(r, c) = s
		(r, c) = (r - 1, c - 1)
		for i in range(4):
			(nr, nc) = (r + dy[i], c + dx[i])
			b[nr][nc] = 1
	Same = True
	for r in range(n):
		for c in range(m):
			if mat[r][c] != b[r][c]:
				Same = False
	if Same:
		print(len(seq))
		for s in seq:
			print(*s)
	else:
		print(-1)
	pass
solve()


import sys
from collections import defaultdict
input = lambda : sys.stdin.readline().rstrip()
(n, m) = map(int, input().split())
a = [list(map(int, input().split())) for i in range(n)]
b = [[0] * m for i in range(n)]
ans = []
for i in range(n - 1):
	for j in range(m - 1):
		if a[i][j] == a[i + 1][j] == a[i][j + 1] == a[i + 1][j + 1] == 1:
			ans.append((i + 1, j + 1))
			b[i][j] = b[i + 1][j] = b[i][j + 1] = b[i + 1][j + 1] = 1
for i in range(n):
	for j in range(m):
		if a[i][j] != b[i][j]:
			print(-1)
			exit()
print(len(ans))
for i in ans:
	print(*i)


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')
for t in range(1):
	(n, m) = list(map(int, input().split()))
	a = []
	b = []
	ans = []
	for i in range(n):
		a.append(list(map(int, input().split())))
		b.append([0] * m)
	for i in range(n):
		for j in range(m):
			if a[i][j] == 0:
				chk0 = 1
			else:
				chk0 = 0
				break
		if chk0 == 0:
			break
	if chk0 == 1:
		print(0)
		continue
	flag = 1
	for i in range(n - 1):
		for j in range(m - 1):
			if a[i][j] == a[i][j + 1] == a[i + 1][j] == a[i + 1][j + 1] == 1:
				ans.append([i + 1, j + 1])
				(b[i][j], b[i][j + 1], b[i + 1][j], b[i + 1][j + 1]) = (1, 1, 1, 1)
	for i in range(n):
		for j in range(m):
			if a[i][j] != b[i][j]:
				flag = 0
				break
	if flag == 0:
		print(-1)
	else:
		print(len(ans))
		for i in ans:
			print(i[0], i[1])


(a, b) = [int(j) for j in input().split()]
m = [[int(j) for j in input().split()] for i in range(a)]
n = [[0 for j in range(b)] for i in range(a)]
flag = 0
flag1 = sum([sum(i) for i in m])
l = []
for i in range(a - 1):
	for j in range(b - 1):
		if m[i][j] == 1 and m[i + 1][j] == 1 and (m[i][j + 1] == 1) and (m[i + 1][j + 1] == 1):
			flag += 1
			n[i][j] = 1
			n[i + 1][j] = 1
			n[i][j + 1] = 1
			n[i + 1][j + 1] = 1
			l.append([i + 1, j + 1])
		elif m[i][j] == 1 and n[i][j] == 0:
			flag = 0
			break
if flag1 == 0:
	print(0)
elif flag == 0 or m != n:
	print(-1)
else:
	print(flag)
	for i in l:
		print(*i)


import sys
input = sys.stdin.readline
(n, m) = map(int, input().split())
s = [list(map(int, input().split())) for i in range(n)]
s2 = [[0] * m for j in range(n)]
res = []
flag = True
for i in range(n - 1):
	for j in range(m - 1):
		if s[i][j] == 1:
			if s[i + 1][j] == s[i][j + 1] == s[i + 1][j + 1] == 1:
				res.append((i + 1, j + 1))
				s2[i][j] = 1
				s2[i + 1][j + 1] = 1
				s2[i][j + 1] = 1
				s2[i + 1][j] = 1
for a in range(len(s2)):
	if s2[a] != s[a]:
		flag = False
		break
if flag:
	print(len(res))
	for r in res:
		print(*r)
else:
	print(-1)


(n, m) = input().split()
n = int(n)
m = int(m)
a = []
b = []
for i in range(n):
	row = input().split()
	for j in range(len(row)):
		row[j] = int(row[j])
	a += [row]
	b += [[0] * m]
opers = []
for i in range(n - 1):
	for j in range(m - 1):
		ok = True
		for i1 in range(2):
			for j1 in range(2):
				if a[i + i1][j + j1] == 0:
					ok = False
					break
		if ok:
			opers += [[i, j]]
			for i1 in range(2):
				for j1 in range(2):
					b[i + i1][j + j1] = 1
ok = True
for i in range(n):
	for j in range(m):
		if a[i][j] != b[i][j]:
			ok = False
			break
if not ok:
	print(-1)
else:
	print(len(opers))
	for oper in opers:
		print(oper[0] + 1, oper[1] + 1)


(n, m) = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]
b = [[0] * m for _ in range(n)]
s = []
for i in range(n):
	for j in range(m):
		if i + 1 >= n or j + 1 >= m:
			continue
		if a[i][j] == a[i + 1][j] == a[i][j + 1] == a[i + 1][j + 1] == 1:
			b[i][j] = 1
			b[i][j + 1] = 1
			b[i + 1][j] = 1
			b[i + 1][j + 1] = 1
			s.append([i + 1, j + 1])
if a == b:
	print(len(s))
	for p in s:
		print(*p)
else:
	print(-1)


(n, m) = map(int, input().split())
matrix = []
for i in range(n):
	row = list(map(int, input().split()))
	matrix.append([])
	for i in row:
		if i == 1:
			matrix[-1].append([1, 0])
		else:
			matrix[-1].append([0, 1])
sequence = []
for i in range(n - 1):
	for j in range(m - 1):
		if matrix[i][j][0] == 1 and matrix[i + 1][j][0] == 1 and (matrix[i][j + 1][0] == 1) and (matrix[i + 1][j + 1][0] == 1):
			sequence.append([i + 1, j + 1])
			matrix[i][j][1] = 1
			matrix[i + 1][j][1] = 1
			matrix[i][j + 1][1] = 1
			matrix[i + 1][j + 1][1] = 1
flag = False
for i in range(n):
	if flag:
		break
	for j in range(m):
		if matrix[i][j][1] == 0:
			flag = True
			break
if flag:
	print(-1)
else:
	print(len(sequence))
	for i in sequence:
		print(*i)


(n, m) = map(int, input().split())
arr = [list(map(int, input().split())) for _ in range(n)]
ar2 = [[0] * m for _ in range(n)]
res = []
for i in range(n - 1):
	for j in range(m - 1):
		if arr[i][j] + arr[i + 1][j] + arr[i][j + 1] + arr[i + 1][j + 1] == 4:
			res.append((i + 1, j + 1))
			ar2[i][j] = 1
			ar2[i + 1][j] = 1
			ar2[i][j + 1] = 1
			ar2[i + 1][j + 1] = 1
bad = False
for i in range(n):
	for j in range(m):
		if arr[i][j] != ar2[i][j]:
			bad = True
			break
	if bad:
		break
if bad:
	print(-1)
else:
	print(len(res))
	for e in res:
		print(*e)


def func():
	(n, m) = [int(x) for x in input().split()]
	A = []
	for i in range(n):
		c = [int(x) for x in input().split()]
		A.append(c)
	if m == 1:
		print(-1)
		return
	B = [[0 for x in range(m)] for y in range(n)]
	ans = []
	for i in range(n):
		for j in range(m):
			if A[i][j] == 1:
				if i < n - 1 and j < m - 1:
					if A[i + 1][j] == 1 and A[i][j + 1] == 1 and (A[i + 1][j + 1] == 1):
						B[i][j] = B[i + 1][j] = B[i][j + 1] = B[i + 1][j + 1] = 1
						if (i + 1, j + 1) not in ans:
							ans.append((i + 1, j + 1))
				elif i > 0 and j < m - 1:
					if A[i - 1][j] == 1 and A[i - 1][j + 1] == 1 and (A[i][j + 1] == 1):
						B[i][j] = B[i - 1][j] = B[i - 1][j + 1] = B[i][j + 1] = 1
						if (i, j + 1) not in ans:
							ans.append((i, j + 1))
				elif i > 0 and j > 0:
					if A[i - 1][j] == 1 and A[i - 1][j - 1] == 1 and (A[i][j - 1] == 1):
						B[i][j] = B[i - 1][j] = B[i - 1][j - 1] = B[i][j - 1] = 1
						if (i, j) not in ans:
							ans.append((i, j))
				elif i < n - 1 and j > 0:
					if A[i][j - 1] == 1 and A[i + 1][j - 1] == 1 and (A[i + 1][j] == 1):
						B[i][j] = B[i][j - 1] = B[i + 1][j - 1] = B[i + 1][j] = 1
						if (i + 1, j) not in ans:
							ans.append((i + 1, j))
	if A == B:
		print(len(ans))
		for x in ans:
			print(x[0], x[1])
	else:
		print(-1)
		return
func()


(n, m) = map(int, input().split())
li = []
for i in range(n):
	a = list(map(int, input().split()))
	li.append(a)
li1 = [[0 for i in range(m)] for _ in range(n)]
ans = []
ans1 = 0
for i in range(n - 1):
	for j in range(m - 1):
		if li[i][j] + li[i][j + 1] + li[i + 1][j] + li[i + 1][j + 1] == 4:
			li1[i][j] = 1
			li1[i][j + 1] = 1
			li1[i + 1][j] = 1
			li1[i + 1][j + 1] = 1
			ans.append([i + 1, j + 1])
			ans1 += 1
if li1 == li:
	print(ans1)
	for i in ans:
		print(*i)
else:
	print(-1)


def fill(x, y):
	if a[x][y] == 1 and a[x + 1][y] == 1 and (a[x][y + 1] == 1) and (a[x + 1][y + 1] == 1):
		b[x][y] = b[x + 1][y] = b[x][y + 1] = b[x + 1][y + 1] = 1
		ans.append([x, y])
(n, m) = map(int, input().split())
a = []
b = []
ans = []
for i in range(n):
	a.append(list(map(int, input().split())))
	b.append([0] * m)
for i in range(n - 1):
	for j in range(m - 1):
		fill(i, j)
for i in range(n):
	for j in range(m):
		if a[i][j] != b[i][j]:
			print(-1)
			exit()
print(len(ans))
for i in range(len(ans)):
	print(ans[i][0] + 1, ans[i][1] + 1)


(n, m) = map(int, input().split())
a = []
b = [[0 for i in range(m)] for j in range(n)]
s = []
for i in range(n):
	a.append(list(map(int, input().split())))
for i in range(n - 1):
	for j in range(m - 1):
		if a[i][j] + a[i + 1][j] + a[i][j + 1] + a[i + 1][j + 1] == 4:
			s.append((i, j))
for k in s:
	(i, j) = k
	(b[i][j], b[i + 1][j], b[i][j + 1], b[i + 1][j + 1]) = (1, 1, 1, 1)
if a == b:
	print(len(s))
	for i in s:
		print(i[0] + 1, i[1] + 1)
else:
	print(-1)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
mod2 = 998244353
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def JA(a, sep):
	return sep.join(map(str, a))

def JAA(a, s, t):
	return s.join((t.join(map(str, b)) for b in a))

def IF(c, t, f):
	return t if c else f

def YES(c):
	return IF(c, 'YES', 'NO')

def Yes(c):
	return IF(c, 'Yes', 'No')

def main():
	t = 1
	rr = []
	for _ in range(t):
		(n, m) = LI()
		a = [LI() for _ in range(n)]
		b = [[0] * m for _ in range(n)]
		r = []
		for i in range(n - 1):
			for j in range(m - 1):
				t = a[i][j] + a[i + 1][j] + a[i][j + 1] + a[i + 1][j + 1]
				if t == 4:
					b[i][j] = b[i + 1][j] = b[i][j + 1] = b[i + 1][j + 1] = 1
					r.append((i + 1, j + 1))
		if a == b:
			rr.append(len(r))
			rr.append(JAA(r, '\n', ' '))
		else:
			rr.append(-1)
	return JA(rr, '\n')
print(main())


(a, b) = map(int, input().split())
z = []
c = []
k = []
for _ in ' ' * a:
	c += [list(map(int, input().split()))]
p = [0] * b
t = [0] * b
for i in range(a - 1):
	t = [0] * b
	for j in range(b - 1):
		if c[i][j] == c[i][j + 1] == c[i + 1][j] == c[i + 1][j + 1] == 1:
			t[j] = t[j + 1] = p[j + 1] = p[j] = 1
			k += [[i + 1, j + 1]]
	z += [p]
	p = t
z += [t]
ans = 0
for i in range(a):
	if z[i] != c[i]:
		ans = 1
		break
if ans:
	print(-1)
else:
	print(len(k))
	for i in k:
		print(*i)


(n, m) = map(int, input().split())
A = []
B = [[0 for i in range(m)] for i in range(n)]
k = 0
P = []
for i in range(n):
	X = list(map(int, input().split()))
	A.append(X)
for i in range(n):
	for j in range(m):
		if A[i][j] == 1:
			if i + 1 < n and j + 1 < m:
				if A[i + 1][j] == 1 and A[i][j + 1] == 1 and (A[i + 1][j + 1] == 1):
					if B[i + 1][j] == 0 or B[i][j + 1] == 0 or B[i + 1][j + 1] == 0 or (B[i][j] == 0):
						k = k + 1
						P.append([i, j])
						B[i][j] = 1
						B[i + 1][j] = 1
						B[i][j + 1] = 1
						B[i + 1][j + 1] = 1
			if i - 1 > -1 and j + 1 < m:
				if A[i - 1][j] == 1 and A[i][j + 1] == 1 and (A[i - 1][j + 1] == 1):
					if B[i - 1][j] == 0 or B[i][j + 1] == 0 or B[i - 1][j + 1] == 0 or (B[i][j] == 0):
						k = k + 1
						P.append([i - 1, j])
						B[i][j] = 1
						B[i - 1][j] = 1
						B[i][j + 1] = 1
						B[i - 1][j + 1] = 1
			if i + 1 < n and j - 1 > -1:
				if A[i][j - 1] == 1 and A[i + 1][j] == 1 and (A[i + 1][j - 1] == 1):
					if B[i][j - 1] == 0 or B[i + 1][j] == 0 or B[i + 1][j - 1] == 0 or (B[i][j] == 0):
						k = k + 1
						P.append([i, j - 1])
						B[i][j] = 1
						B[i][j - 1] = 1
						B[i + 1][j] = 1
						B[i + 1][j - 1] = 1
			if i - 1 > -1 and j - 1 > -1:
				if A[i - 1][j - 1] == 1 and A[i][j - 1] == 1 and (A[i - 1][j] == 1):
					if B[i - 1][j - 1] == 0 or B[i][j - 1] == 0 or B[i - 1][j] == 0 or (B[i][j] == 0):
						k = k + 1
						P.append([i - 1, j - 1])
						B[i][j] = 1
						B[i - 1][j - 1] = 1
						B[i][j - 1] = 1
						B[i - 1][j] = 1
for i in range(n):
	for j in range(m):
		if A[i][j] != B[i][j]:
			k = -1
print(k)
if k != -1:
	for x in P:
		print(x[0] + 1, x[1] + 1)


(N, M) = list(map(int, input().split()))
A = []
for n in range(N):
	row_vec = list(map(int, input().split()))
	A.append(row_vec)
B = [[0 for m in range(M)] for n in range(N)]
corners = []
for n in range(N - 1):
	for m in range(M - 1):
		if A[n][m] == 1 and A[n][m + 1] == 1 and (A[n + 1][m] == 1) and (A[n + 1][m + 1] == 1):
			corners.append((n, m))
			B[n][m] = B[n][m + 1] = B[n + 1][m] = B[n + 1][m + 1] = 1
for n in range(N):
	for m in range(M):
		if A[n][m] != B[n][m]:
			corners = None
			break
if corners is None:
	print(-1)
else:
	print(len(corners))
	for c in corners:
		print(c[0] + 1, c[1] + 1)


(n, m) = map(int, input().split())
l = []
ans = []
b = [[0 for i in range(m)] for n in range(n)]
for i in range(n):
	l.append(list(map(int, input().split())))
for i in range(n - 1):
	for j in range(m - 1):
		if l[i][j] * l[i][j + 1] * l[i + 1][j] * l[i + 1][j + 1] == 1:
			ans.append(str(i + 1) + ' ' + str(j + 1))
			b[i][j] = 1
			b[i][j + 1] = 1
			b[i + 1][j] = 1
			b[i + 1][j + 1] = 1
if l == b:
	print(len(ans))
	for i in ans:
		print(i)
else:
	print(-1)


import sys
readline = sys.stdin.readline
readlines = sys.stdin.readlines
ns = lambda : readline().rstrip()
ni = lambda : int(readline().rstrip())
nm = lambda : map(int, readline().split())
nl = lambda : list(map(int, readline().split()))
prn = lambda x: print(*x, sep='\n')

def solve():
	(h, w) = nm()
	g = [nl() + [0] for _ in range(h)] + [[0] * (w + 1)]
	f = [[0] * (w + 1) for i in range(h + 1)]
	l = list()
	for i in range(h):
		for j in range(w):
			if g[i][j]:
				if g[i + 1][j] and g[i][j + 1] and g[i + 1][j + 1]:
					l.append((i + 1, j + 1))
					f[i][j] = f[i + 1][j] = f[i][j + 1] = f[i + 1][j + 1] = 1
	if f != g:
		print(-1)
	else:
		print(len(l))
		for x in l:
			print(*x)
	return
solve()


def checks(A, B, i, j):
	if A[i][j] == 1 and A[i + 1][j] == 1 and (A[i][j + 1] == 1) and (A[i + 1][j + 1] == 1):
		return True
	return False
(n, m) = [int(i) for i in input().split()]
A = []
B = [[0 for _ in range(m)] for _ in range(n)]
for _ in range(n):
	A.append([int(i) for i in input().split()])
if A == B:
	print(0)
else:
	res = []
	for i in range(n - 1):
		for j in range(m - 1):
			temp = checks(A, B, i, j)
			if temp:
				B[i][j] = 1
				B[i + 1][j] = 1
				B[i][j + 1] = 1
				B[i + 1][j + 1] = 1
				res.append((i + 1, j + 1))
	if A == B:
		print(len(res))
		for (i, j) in res:
			print(i, j)
	else:
		print(-1)


cords = [[0, 1], [1, 0], [1, 1]]

def calc(a, i, j):
	is_ok = True
	for v in cords:
		if i + v[0] >= len(a):
			return None
		if j + v[1] >= len(a[0]):
			return None
		if a[i + v[0]][j + v[1]] != 1:
			is_ok = False
	if is_ok:
		return (i + 1, j + 1)
	return None
(m, n) = [int(v) for v in input().split()]
a = []
b = []
for i in range(0, m):
	row = input().split()
	a.append([int(v) for v in row])
	b.append([0 for _ in row])
res = []
for i in range(0, m):
	for j in range(0, n):
		val = calc(a, i, j)
		if a[i][j] == 1 and val:
			res.append(val)
			for v in cords:
				b[i + v[0]][j + v[1]] = 1
				b[i][j] = 1
if a == b:
	print(len(res))
	for k in res:
		print(k[0], k[1])
else:
	print(-1)


from sys import stdin, stdout
from collections import defaultdict
import math
import copy
(N, M) = [int(x) for x in stdin.readline().split()]
data = [[0] * M for _ in range(N)]
B = [[0] * M for _ in range(N)]
for i in range(N):
	arr = [int(x) for x in stdin.readline().split()]
	for j in range(M):
		data[i][j] = arr[j]
ans = []
for i in range(N - 1):
	for j in range(M - 1):
		A = data[i][j]
		b = data[i][j + 1]
		c = data[i + 1][j]
		d = data[i + 1][j + 1]
		if A == 1 and b == 1 and (c == 1) and (d == 1):
			ans.append((i + 1, j + 1))
			B[i][j] = 1
			B[i + 1][j] = 1
			B[i][j + 1] = 1
			B[i + 1][j + 1] = 1
for i in range(N):
	for j in range(M):
		if data[i][j] != B[i][j]:
			print(-1)
			quit()
print(len(ans))
for i in range(len(ans)):
	print(*ans[i])


(r, c) = map(int, input().split())
x = []
ans = []
s = 0
ct = 0
f = 0
pq = []
for _ in range(r):
	x.append([int(n) for n in input().split()])
	pq.append([0 for i in range(c)])
	s += sum(x[_])
for i in range(r):
	for j in range(c):
		if x[i][j] == 1 and i < r - 1 and (j < c - 1):
			if x[i + 1][j] == 1:
				if x[i + 1][j + 1] == 1:
					if x[i][j + 1] == 1:
						ans.append([i + 1, j + 1])
						pq[i][j] = 1
						pq[i + 1][j] = 1
						pq[i][j + 1] = 1
						pq[i + 1][j + 1] = 1
						ct += 1
for i in range(r):
	if str(x[i]) != str(pq[i]):
		f = 1
if s == 0:
	print('0')
elif ct == 0 or f == 1:
	print('-1')
else:
	print(ct)
	for i in ans:
		print(*i)


(n, m) = [int(x) for x in input().split()]
a = []
b = []
for i in range(n):
	l = list(map(int, input().split()))
	a.append(l)
	tem = []
	for i in range(m):
		tem.append(0)
	b.append(tem)
ans = []
count = 0
for i in range(0, n - 1):
	for j in range(0, m - 1):
		if a[i][j] == a[i][j + 1] == a[i + 1][j] == a[i + 1][j + 1] == 1:
			count += 1
			ans.append([i + 1, j + 1])
			b[i][j] = 1
			b[i][j + 1] = 1
			b[i + 1][j] = 1
			b[i + 1][j + 1] = 1
if b != a:
	print(-1)
else:
	print(count)
	for i in ans:
		print(*i)


def rint():
	return int(input())

def rints():
	return list(map(int, input().split()))
(n, m) = rints()
a = [rints() for _ in range(n)]
b = [[0] * m for _ in range(n)]
op = []

def pos(x, y):
	return 0 <= x < m - 1 and 0 <= y < n - 1 and a[y][x] and a[y][x + 1] and a[y + 1][x] and a[y + 1][x + 1]
for y in range(n):
	for x in range(m):
		if pos(x, y):
			op.append((x, y))
			for (dx, dy) in [(0, 0), (1, 0), (1, 1), (0, 1)]:
				b[y + dy][x + dx] = 1
for y in range(n):
	for x in range(m):
		if a[y][x] != b[y][x]:
			print(-1)
			exit(0)
print(len(op))
for (x, y) in op:
	print(f'{y + 1} {x + 1}')


(n, m) = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]
s = [[0] * m for _ in range(n)]
ans = []
for q in range(n - 1):
	for q1 in range(m - 1):
		if a[q][q1] == a[q][q1 + 1] == a[q + 1][q1] == a[q + 1][q1 + 1] == 1:
			s[q][q1] = s[q][q1 + 1] = s[q + 1][q1] = s[q + 1][q1 + 1] = 1
			ans.append([q + 1, q1 + 1])
if a != s:
	print(-1)
else:
	print(len(ans))
	for q in ans:
		print(*q)


(n, m) = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]
b = [[0 for _ in range(m)] for _ in range(n)]
actions = []
for x in range(n - 1):
	for y in range(m - 1):
		if a[x][y] == 1 and a[x + 1][y] == 1 and (a[x][y + 1] == 1) and (a[x + 1][y + 1] == 1):
			b[x][y] = 1
			b[x + 1][y] = 1
			b[x][y + 1] = 1
			b[x + 1][y + 1] = 1
			actions.append((x + 1, y + 1))
diff = 0
for x in range(n):
	for y in range(m):
		diff += abs(a[x][y] - b[x][y])
if diff > 0:
	print(-1)
else:
	print(len(actions))
	for (x, y) in actions:
		print(x, y)


(n, m) = map(int, input().split())
a = [list(map(int, input().split())) for i in range(n)]
used = [[False] * m for i in range(n)]
ans = []
for i in range(n - 1):
	for j in range(m - 1):
		if a[i][j] and a[i + 1][j] and a[i + 1][j + 1] and a[i][j + 1]:
			ans.append([i + 1, j + 1])
			used[i][j] = True
			used[i][j + 1] = True
			used[i + 1][j + 1] = True
			used[i + 1][j] = True
for i in range(n):
	for j in range(m):
		if a[i][j] and (not used[i][j]):
			print(-1)
			exit(0)
if len(ans) > 2500:
	print(-1)
	exit()
print(len(ans))
for i in ans:
	print(*i)


from __future__ import division, print_function
from sys import stdin, stdout
import itertools, os, sys, threading
from collections import deque, Counter, OrderedDict, defaultdict
import heapq
from math import ceil, floor, log, sqrt, factorial, pow, pi, gcd
from fractions import Fraction

def ii():
	return int(input())

def si():
	return str(input())

def mi():
	return map(int, input().split())

def li():
	return list(mi())

def fii():
	return int(stdin.readline())

def fsi():
	return str(stdin.readline())

def fmi():
	return map(int, stdin.readline().split())

def fli():
	return list(fmi())
abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod = 1000000007
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def getKey(item):
	return item[0]

def sort2(l):
	return sorted(l, key=getKey)

def d2(n, m, num):
	return [[num for x in range(m)] for y in range(n)]

def isPowerOfTwo(x):
	return x and (not x & x - 1)

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def ntl(n):
	return [int(i) for i in str(n)]

def powerMod(x, y, p):
	res = 1
	x %= p
	while y > 0:
		if y & 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x
graph = defaultdict(list)
visited = [0] * 1000000
col = [-1] * 1000000

def dfs(v, c):
	if visited[v]:
		if col[v] != c:
			print('-1')
			exit()
		return
	col[v] = c
	visited[v] = 1
	for i in graph[v]:
		dfs(i, c ^ 1)

def bfs(d, v):
	q = []
	q.append(v)
	visited[v] = 1
	while len(q) != 0:
		x = q[0]
		q.pop(0)
		for i in d[x]:
			if visited[i] != 1:
				visited[i] = 1
				q.append(i)
		print(x)

def make_graph(e):
	d = {}
	for i in range(e):
		(x, y) = mi()
		if x not in d.keys():
			d[x] = [y]
		else:
			d[x].append(y)
		if y not in d.keys():
			d[y] = [x]
		else:
			d[y].append(x)
	return d

def gr2(n):
	d = {}
	for i in range(n):
		(x, y) = mi()
		if x not in d.keys():
			d[x] = [y]
		else:
			d[x].append(y)
	return d

def connected_components(graph):
	seen = set()

	def dfs(v):
		vs = set([v])
		component = []
		while vs:
			v = vs.pop()
			seen.add(v)
			vs |= set(graph[v]) - seen
			component.append(v)
		return component
	ans = []
	for v in graph:
		if v not in seen:
			d = dfs(v)
			ans.append(d)
	return ans

def primeFactors(n):
	s = set()
	while n % 2 == 0:
		s.add(2)
		n = n // 2
	for i in range(3, int(sqrt(n)) + 1, 2):
		while n % i == 0:
			s.add(i)
			n = n // i
	if n > 2:
		s.add(n)
	return s

def find_all(a_str, sub):
	start = 0
	while True:
		start = a_str.find(sub, start)
		if start == -1:
			return
		yield start
		start += len(sub)
(n, m) = mi()
l = []
b = []
for i in range(n):
	x = li()
	a = [0] * m
	b.append(a)
	l.append(x)
out = []
for i in range(n - 1):
	for j in range(m - 1):
		if l[i][j] == 1 and l[min(n - 1, i + 1)][j] == 1 and (l[i][min(m - 1, j + 1)] == 1) and (l[min(n - 1, i + 1)][min(m - 1, j + 1)] == 1):
			b[i][j] = 1
			b[min(n - 1, i + 1)][j] = 1
			b[i][min(m - 1, j + 1)] = 1
			b[min(n - 1, i + 1)][min(m - 1, j + 1)] = 1
			out.append(str(i + 1) + ' ' + str(j + 1))
for i in range(n):
	for j in range(m):
		if l[i][j] != b[i][j]:
			print(-1)
			exit()
print(len(out))
for i in range(len(out)):
	print(out[i])


(n, m) = map(int, input().split())
a = []
for _ in range(n):
	b = input().split()
	a.append(b)
c = 0
d = []
e = set()
for i in range(n):
	for j in range(m):
		c += 1 if a[i][j] == '1' else 0
		if i < n - 1 and j < m - 1:
			if a[i][j] == a[i][j + 1] == a[i + 1][j] == a[i + 1][j + 1] == '1':
				d.append([i + 1, j + 1])
				e.update([str(i) + '-' + str(j), str(i) + '-' + str(j + 1), str(i + 1) + '-' + str(j), str(i + 1) + '-' + str(j + 1)])
if c == len(e):
	print(len(d))
	for _ in d:
		print(_[0], _[1])
else:
	print(-1)


(n, m) = map(int, input().split())
a = [list(map(int, input().split())) for i in range(n)]
ans = []
for i in range(n - 1):
	for j in range(m - 1):
		if a[i][j] * a[i][j + 1] * a[i + 1][j] * a[i + 1][j + 1] > 0:
			a[i][j] += 1
			a[i][j + 1] += 1
			a[i + 1][j] += 1
			a[i + 1][j + 1] += 1
			ans.append([i, j])
count = 0
for i in range(n):
	for j in range(m):
		if a[i][j] == 1:
			count += 1
if count != 0:
	print('-1')
else:
	print(len(ans))
	for g in ans:
		print(g[0] + 1, g[1] + 1)


def fill_square(r, c, l):
	m = [[0] * c for _ in range(r)]
	k = []
	for i in range(r - 1):
		for j in range(c - 1):
			if l[i][j] and l[i + 1][j] and l[i][j + 1] and l[i + 1][j + 1]:
				m[i][j] = m[i + 1][j] = m[i][j + 1] = m[i + 1][j + 1] = 1
				k.append([i + 1, j + 1])
	if l == m:
		print(len(k))
		for i in k:
			print(*i)
	else:
		print(-1)
(r, c) = map(int, input().split())
l = [list(map(int, input().split())) for _ in range(r)]
fill_square(r, c, l)


from sys import stdin

def arr_inp(n):
	if n == 1:
		return [int(x) for x in stdin.readline().split()]
	elif n == 2:
		return [float(x) for x in stdin.readline().split()]
	else:
		return [str(x) for x in stdin.readline().split()]
(n, m) = arr_inp(1)
(mat, mat2, ans) = ([arr_inp(1) for i in range(n)], [[0] * m for j in range(n)], [])
for i in range(n - 1):
	for j in range(m - 1):
		if sum(mat[i][j:j + 2]) + sum(mat[i + 1][j:j + 2]) == 4:
			ans.append([i + 1, j + 1])
			mat2[i][j] = mat2[i][j + 1] = mat2[i + 1][j] = mat2[i + 1][j + 1] = 1
if mat2 == mat:
	print(len(ans))
	for i in range(len(ans)):
		print(*ans[i])
else:
	print(-1)


(n, m) = [int(x) for x in input().split()]
A = [[int(x) for x in input().split()] for _ in range(n)]
B = [[0] * m for _ in range(n)]
ops = []
for x in range(n):
	for y in range(m):
		if not all([i >= 0 and j >= 0 and (i < n) and (j < m) and (A[i][j] == 1) for i in [x, x + 1] for j in [y, y + 1]]):
			continue
		ops.append((x, y))
		for (i, j) in [(i, j) for i in [x, x + 1] for j in [y, y + 1]]:
			B[i][j] = 1
if all((A[i][j] == B[i][j] for i in range(n) for j in range(m))):
	print(len(ops))
	for (x, y) in ops:
		print(x + 1, y + 1)
else:
	print(-1)


from sys import stdin
(n, m) = list(map(int, stdin.readline().strip().split()))
s = []
for i in range(n):
	s.append(list(map(int, stdin.readline().strip().split())))
b = [[0 for i in range(m)] for j in range(n)]
ans = []
for i in range(n - 1):
	for j in range(m - 1):
		if s[i][j] == 1 and s[i + 1][j] == 1 and (s[i + 1][j + 1] == 1) and (s[i][j + 1] == 1):
			ans.append([i + 1, j + 1])
			b[i][j] = 1
			b[i][j + 1] = 1
			b[i + 1][j] = 1
			b[i + 1][j + 1] = 1
flag = True
for i in range(n):
	for j in range(m):
		if s[i][j] != b[i][j]:
			flag = False
			break
if flag:
	print(len(ans))
	for i in ans:
		print(*i)
else:
	print(-1)


(height, width) = map(int, input().split(' '))
a = [0] * height
b = [0] * height
for i in range(height):
	a[i] = list(map(int, input().split(' ')))
	b[i] = [0] * width
isValid = True
for i in range(height - 1):
	for j in range(width - 1):
		if a[i][j] and a[i + 1][j] and a[i][j + 1] and a[i + 1][j + 1]:
			b[i][j] = 1
			b[i + 1][j] = 1
			b[i][j + 1] = 1
			b[i + 1][j + 1] = 1
for i in range(height):
	for j in range(width):
		if a[i][j] != b[i][j]:
			isValid = False
if isValid == False:
	print(-1)
else:
	moves = []
	for i in range(height - 1):
		for j in range(width - 1):
			if a[i][j] and a[i + 1][j] and a[i][j + 1] and a[i + 1][j + 1]:
				moves.append([i, j])
	print(len(moves))
	for pair in moves:
		(x, y) = pair
		print(x + 1, y + 1)


(n, m) = map(int, input().split())
a = []
for i in range(n):
	b = []
	b = list(map(int, input().split()))
	a.append(b)
ans = []
for i in range(n - 1):
	for j in range(m - 1):
		if a[i][j] * a[i + 1][j] * a[i][j + 1] * a[i + 1][j + 1] > 0:
			a[i][j] = 2
			a[i][j + 1] = 2
			a[i + 1][j] = 2
			a[i + 1][j + 1] = 2
			ans.append((i + 1, j + 1))
ok = True
for i in range(n):
	for j in range(m):
		if a[i][j] == 1:
			ok = False
			break
if ok:
	print(len(ans))
	for (i, j) in ans:
		print(i, j)
else:
	print('-1')


(m, n) = map(int, input().split())
arr = []
for i in range(m):
	arr.append(list(map(int, input().split())))
count = 0
ans_arr = []
i = 0
flag = 0
while i < m - 1:
	j = 0
	while j < n - 1:
		if arr[i][j] > 0 and arr[i + 1][j] > 0 and (arr[i][j + 1] > 0) and (arr[i + 1][j + 1] > 0):
			count += 1
			ans_arr.append(' '.join(map(str, [i + 1, j + 1])))
			arr[i][j] = 2
			arr[i + 1][j] = 2
			arr[i][j + 1] = 2
			arr[i + 1][j + 1] = 2
		j += 1
	i += 1
flag = 0
i = 0
while i < m and flag == 0:
	j = 0
	while j < n:
		if arr[i][j] == 1:
			flag = 1
			break
		j += 1
	i += 1
if flag == 1:
	print(-1)
else:
	print(count)
	print('\n'.join(ans_arr))


import sys
input = sys.stdin.readline
(n, m) = map(int, input().split())
arr = []
for i in range(n):
	arr.append(list(map(int, input().split())))
cnt = 0
ans = []
test = [[0] * m for i in range(n)]
for i in range(n - 1):
	for j in range(m - 1):
		if arr[i][j] and arr[i + 1][j] and arr[i][j + 1] and arr[i + 1][j + 1]:
			cnt += 1
			test[i][j] = test[i + 1][j] = test[i][j + 1] = test[i + 1][j + 1] = 1
			ans.append([i + 1, j + 1])
if arr == test:
	print(cnt)
	for i in ans:
		print(*i)
else:
	print(-1)


(q, w) = map(int, input().split())
e = [0] * q
r = [0] * q
ans = []
for i in range(q):
	e[i] = list(map(int, input().split()))
	r[i] = [0] * w
for i in range(q - 1):
	for j in range(w - 1):
		if e[i][j] and e[i + 1][j] and e[i][j + 1] and e[i + 1][j + 1]:
			ans.append((i + 1, j + 1))
			r[i][j] = 1
			r[i + 1][j] = 1
			r[i][j + 1] = 1
			r[i + 1][j + 1] = 1
if e == r:
	print(len(ans))
	for i in ans:
		print(*i)
else:
	print(-1)


s = lambda : list(map(int, input().split()))
(n, m) = s()
matrixA = []
for x in range(n):
	matrixA.append(list(map(bool, s())))
matrixB = [[False] * m for x in range(n)]
seq = []
for x in range(n - 1):
	for y in range(m - 1):
		if matrixA[x][y] and matrixA[x + 1][y] and matrixA[x + 1][y + 1] and matrixA[x][y + 1]:
			matrixB[x][y] = True
			matrixB[x + 1][y] = True
			matrixB[x][y + 1] = True
			matrixB[x + 1][y + 1] = True
			seq.append((x + 1, y + 1))
flag = True
for x in range(n):
	for y in range(m):
		if matrixA[x][y] and (not matrixB[x][y]):
			flag = False
			break
	if not flag:
		break
if flag:
	print(len(seq))
	for op in seq:
		print(str(op[0]) + ' ' + str(op[1]))
else:
	print(-1)


(m, n) = map(int, input().split())
lines_list = []
for i in range(m):
	lines_list.append(list(map(int, input().split())))
mod_list = []
nummods = 0
for j in range(m - 1):
	for k in range(n - 1):
		if lines_list[j][k] > 0 and lines_list[j][k + 1] > 0 and (lines_list[j + 1][k] > 0) and (lines_list[j + 1][k + 1] > 0):
			(lines_list[j][k], lines_list[j + 1][k], lines_list[j][k + 1], lines_list[j + 1][k + 1]) = (2, 2, 2, 2)
			nummods += 1
			mod_list.append(str(j + 1) + ' ' + str(k + 1))
for i in range(m):
	for j in range(n):
		if lines_list[i][j] == 1:
			print('-1')
			quit()
print(str(nummods))
for item in mod_list:
	print(item)


(n, m) = map(int, input().split())
a = [list(map(int, input().split())) for i in range(n)]
b = [[0] * m for j in range(n)]
answer = []
for i in range(n - 1):
	for j in range(m - 1):
		if a[i][j] == 1 and a[i + 1][j] == 1 and (a[i][j + 1] == 1) and (a[i + 1][j + 1] == 1):
			answer.append(str(i + 1) + ' ' + str(j + 1))
			b[i][j] = 1
			b[i + 1][j] = 1
			b[i][j + 1] = 1
			b[i + 1][j + 1] = 1
if a == b:
	print(len(answer))
	print('\n'.join(answer))
else:
	print(-1)


def check(x, y):
	if x + 1 == n or y + 1 == m:
		return False
	else:
		return A[x][y] == 1 and A[x][y + 1] == 1 and (A[x + 1][y] == 1) and (A[x + 1][y + 1] == 1)
actions = []
(n, m) = [int(x) for x in input().split()]
B = [[0 for _ in range(m)] for i in range(n)]
A = [[]] * n
for i in range(n):
	A[i] = [int(x) for x in input().split()]
for i in range(n):
	for j in range(m):
		if check(i, j):
			B[i][j] = B[i][j + 1] = B[i + 1][j] = B[i + 1][j + 1] = 1
			actions.append([i + 1, j + 1])
answer = A == B
if answer:
	print(len(actions))
	for i in actions:
		print(*i)
else:
	print(-1)


(n, m) = list(map(int, input().split()))
u = []
k = 0
o = []
p = []
for i in range(0, n):
	u.append(list(map(int, input().split())))
	o.append([0] * m)
for i in range(0, n - 1):
	for j in range(0, m - 1):
		l = [u[i][j], u[i + 1][j], u[i][j + 1], u[i + 1][j + 1]]
		if 0 not in l:
			o[i][j] = 1
			o[i + 1][j] = 1
			o[i + 1][j + 1] = 1
			o[i][j + 1] = 1
			k = k + 1
			p.append([i + 1, j + 1])
if o == u:
	print(k)
	for i in p:
		print(*i)
else:
	print(-1)


(n, m) = list(map(int, input().split()))
c = [[0 for i in range(m)] for j in range(n)]
d = [[0 for i in range(m)] for j in range(n)]
s = []
for i in range(n):
	l = list(map(int, input().split()))
	for j in range(m):
		d[i][j] = l[j]
for i in range(n - 1):
	for j in range(m - 1):
		if d[i][j] == 1 and d[i + 1][j] == 1 and (d[i][j + 1] == 1) and (d[i + 1][j + 1] == 1):
			c[i][j] = 1
			c[i + 1][j] = 1
			c[i][j + 1] = 1
			c[i + 1][j + 1] = 1
			s.append(str(i + 1) + ' ' + str(j + 1))
if d != c:
	print(-1)
else:
	print(len(s))
	for i in range(len(s)):
		print(s[i])


from itertools import product
(n, m) = map(int, input().split())
A = [[int(x) for x in input().split()] for _ in range(n)]
B = [[0 for x in range(m)] for _ in range(n)]
C = []
for i in range(n - 1):
	for j in range(m - 1):
		if all([A[i + x][j + y] == 1 for (x, y) in product([0, 1], repeat=2)]):
			C += [(i, j)]
			for (x, y) in product([0, 1], repeat=2):
				B[i + x][j + y] = 1
f = True
for i in range(n):
	for j in range(m):
		f &= A[i][j] == B[i][j]
if not f:
	print(-1)
else:
	print(len(C))
	for (i, j) in C:
		print('%d %d' % (i + 1, j + 1))


(n, m) = map(int, input().split())
a = [[int(x) for x in input().split()] for i in range(n)]
op = []
for i in range(n - 1):
	for j in range(m - 1):
		f = 1
		for k in range(2):
			for g in range(2):
				if a[i + k][j + g] == 0:
					f = 0
		if f == 1:
			op.append([i, j])
b = [[0 for x in range(m)] for i in range(n)]
for x in op:
	for k in range(2):
		for g in range(2):
			b[x[0] + k][x[1] + g] = 1
f = 1
for i in range(n):
	for j in range(m):
		if a[i][j] != b[i][j]:
			f = 0
if f == 1:
	print(len(op))
	for x in op:
		print(str(x[0] + 1) + ' ' + str(x[1] + 1))
else:
	print(-1)


(n, m) = map(int, input().split())
a = [[j for j in map(int, input().split())] for i in range(n)]
b = [[0] * m for i in range(n)]
r = list()
c = list()
count = 0
for i in range(n - 1):
	for j in range(m - 1):
		if a[i][j] == 1 and a[i + 1][j] == 1 and (a[i][j + 1] == 1) and (a[i + 1][j + 1] == 1):
			b[i][j] = 1
			b[i + 1][j] = 1
			b[i][j + 1] = 1
			b[i + 1][j + 1] = 1
			count += 1
			r.append(i + 1)
			c.append(j + 1)
if a == b:
	print(count)
	for i in range(count):
		print(r[i], c[i])
else:
	print(-1)


(n, m) = map(int, input().split())
arr = [list(map(int, input().split())) for _ in range(n)]
one_cnt = 0
for i in range(n):
	for j in range(m):
		if arr[i][j] == 1:
			one_cnt += 1
cnt = 0
act = []
s = set()
for i in range(n - 1):
	for j in range(m - 1):
		if arr[i][j] == 1 and arr[i + 1][j] == 1 and (arr[i][j + 1] == 1) and (arr[i + 1][j + 1] == 1):
			cnt += 1
			act.append((i + 1, j + 1))
			s.add((i, j))
			s.add((i + 1, j))
			s.add((i, j + 1))
			s.add((i + 1, j + 1))
if one_cnt == len(s):
	print(cnt)
	for (a, b) in act:
		print(a, b)
else:
	print(-1)


(n, m) = map(int, input().split(' '))
a = [[] for i in range(n)]
ans = []
c = int
c = int
for i in range(n):
	a[i] = list(map(int, input().split(' ')))
for i in range(n - 1):
	for j in range(m - 1):
		if a[i][j] * a[i + 1][j] * a[i][j + 1] * a[i + 1][j + 1] > 0:
			a[i][j] = 2
			a[i + 1][j] = 2
			a[i][j + 1] = 2
			a[i + 1][j + 1] = 2
			ans.append([i + 1, j + 1])
c = 0
for i in range(n):
	for j in range(m):
		if a[i][j] == 1:
			c += 1
if c != 0:
	print(-1)
else:
	print(len(ans))
	for i in range(len(ans)):
		print(' '.join(map(str, ans[i])))


import sys
input = sys.stdin.readline
(n, m) = map(int, input().split())
A = [list(map(int, input().split())) for i in range(n)]
B = [[0] * m for i in range(n)]
ANS = []
for i in range(n - 1):
	for j in range(m - 1):
		if A[i][j] == A[i + 1][j] == A[i][j + 1] == A[i + 1][j + 1] == 1:
			ANS.append((i + 1, j + 1))
			B[i][j] = B[i + 1][j] = B[i][j + 1] = B[i + 1][j + 1] = 1
if A != B:
	print(-1)
else:
	print(len(ANS))
	for ans in ANS:
		print(*ans)


(n, m) = map(int, input().split())
A = list()
B = list()
for i in range(n):
	row = list(map(int, input().split()))
	A.append(row)
	B.append([0 for _ in range(m)])
ops = list()
for i in range(n - 1):
	for j in range(m - 1):
		if A[i][j] == 1 and A[i + 1][j] == 1 and (A[i][j + 1] == 1) and (A[i + 1][j + 1] == 1):
			B[i][j] = 1
			B[i + 1][j] = 1
			B[i][j + 1] = 1
			B[i + 1][j + 1] = 1
			ops.append((i, j))
if A == B:
	print(len(ops))
	for p in ops:
		print(p[0] + 1, p[1] + 1)
else:
	print(-1)


(rows, cols) = map(int, input().split(' '))
grid = []
for i in range(rows):
	line = map(int, input().split(' '))
	line = list(line)
	grid.append(line)
ans = []
r = []
for i in range(cols):
	r.append(0)
G = []
for i in range(rows):
	G.append(list(r))
for i in range(rows - 1):
	for j in range(cols - 1):
		cnt = grid[i][j] + grid[i + 1][j] + grid[i][j + 1] + grid[i + 1][j + 1]
		if cnt == 4:
			ans.append([i + 1, j + 1])
			G[i][j] = 1
			G[i + 1][j] = 1
			G[i][j + 1] = 1
			G[i + 1][j + 1] = 1
if G == grid:
	print(len(ans))
	for x in ans:
		print(x[0], x[1])
else:
	print(-1)


def read_int():
	return int(input())

def read_ints():
	return map(int, input().split())
(n, m) = read_ints()
A = [list(read_ints()) for _ in range(n)]
res = []
for i in range(n - 1):
	for j in range(m - 1):
		if A[i][j] and A[i + 1][j] and A[i][j + 1] and A[i + 1][j + 1]:
			res.append((i, j))
B = [[0] * m for _ in range(n)]
for (a, b) in res:
	B[a][b] = 1
	B[a + 1][b] = 1
	B[a][b + 1] = 1
	B[a + 1][b + 1] = 1
if A == B:
	print(len(res))
	for (a, b) in res:
		print(a + 1, b + 1)
else:
	print('-1')


(n, m) = map(int, input().strip().split(' '))
a = []
for i in range(n):
	x = [int(x) for x in input().split()]
	a.append(x)
count = 0
res = []
for i in range(n - 1):
	for j in range(m - 1):
		if (a[i][j] == 1 or a[i][j] == 2) and (a[i][j + 1] == 1 or a[i][j + 1] == 2) and (a[i + 1][j] == 1 or a[i + 1][j] == 2) and (a[i + 1][j + 1] == 1 or a[i + 1][j + 1] == 2):
			count += 1
			res.append([i + 1, j + 1])
			a[i][j] = 2
			a[i + 1][j] = 2
			a[i][j + 1] = 2
			a[i + 1][j + 1] = 2
flag = 0
for i in range(n):
	for j in range(m):
		if a[i][j] == 1:
			flag = 1
			break
if flag == 0:
	print(count)
	for i in range(len(res)):
		print(res[i][0], res[i][1])
else:
	print(-1)


R = lambda : map(int, input().split())
(n, m) = R()
L = []
for i in range(n):
	L.append(list(R()))
res = []
for i in range(n - 1):
	for j in range(m - 1):
		if L[i][j] + L[i][j + 1] + L[i + 1][j] + L[i + 1][j + 1] == 4:
			res.append([i + 1, j + 1])
temp = [[0 for i in range(m)] for j in range(n)]
for k in range(len(res)):
	(i, j) = res[k]
	i -= 1
	j -= 1
	temp[i][j] = 1
	temp[i + 1][j] = 1
	temp[i][j + 1] = 1
	temp[i + 1][j + 1] = 1
for i in range(n):
	for j in range(m):
		if L[i][j] != temp[i][j]:
			print(-1)
			quit()
print(len(res))
for i in range(len(res)):
	print(*res[i])


(n, m) = map(int, input().split())
l = []
for _ in range(n):
	l.append(list(map(int, input().split())))
a = []
for i in range(n - 1):
	for y in range(m - 1):
		if l[i][y] * l[i][y + 1] * l[i + 1][y] * l[i + 1][y + 1] > 0:
			(l[i][y], l[i][y + 1], l[i + 1][y], l[i + 1][y + 1]) = (2, 2, 2, 2)
			a.append([i + 1, y + 1])
c = 0
for i in range(n):
	for y in range(m):
		if l[i][y] == 1:
			c += 1
if c != 0:
	print(-1)
else:
	print(len(a))
	for i in a:
		print(*i)


ln = [int(i) for i in input().split(' ')]
n = ln[0]
m = ln[1]
mat = []
good = []
for i in range(0, n):
	mat.append([int(j) for j in input().split(' ')])
	good.append([0] * m)
seq = []
for i in range(0, n - 1):
	for j in range(0, m - 1):
		if mat[i][j] == 1 and mat[i + 1][j] == 1 and (mat[i][j + 1] == 1) and (mat[i + 1][j + 1] == 1):
			good[i][j] = True
			good[i + 1][j] = True
			good[i][j + 1] = True
			good[i + 1][j + 1] = True
			seq.append([i + 1, j + 1])
f = True
for i in range(0, n):
	for j in range(0, m):
		if mat[i][j] == 1 and (not good[i][j]):
			f = False
if not f:
	print(-1)
elif len(seq) == 0:
	print(0)
else:
	print(len(seq))
	for i in seq:
		print(' '.join([str(j) for j in i]))


(n, m) = map(int, input().split())
arr = [list(map(int, input().split())) for j in range(n)]
arr1 = [[0 for i in range(m)] for j in range(n)]
c = 0
l = []
for i in range(n - 1):
	for j in range(m - 1):
		if arr[i][j] + arr[i + 1][j] + arr[i][j + 1] + arr[i + 1][j + 1] == 4:
			arr1[i][j] = 1
			arr1[i + 1][j] = 1
			arr1[i][j + 1] = 1
			arr1[i + 1][j + 1] = 1
			c += 1
			l.append((i + 1, j + 1))
if arr == arr1:
	print(c)
	for i in l:
		print(*i)
else:
	print(-1)


(h, w) = [int(item) for item in input().split()]
field = []
for i in range(h):
	field.append([int(item) for item in input().split()])
dt = [[0, 0], [-1, 0], [0, -1], [-1, -1]]
forbidden = [[0] * w for _ in range(h)]
for i in range(h):
	for j in range(w):
		if field[i][j] == 1:
			continue
		for (k, (dx, dy)) in enumerate(dt):
			if i + dx >= 0 and j + dy >= 0:
				forbidden[i + dx][j + dy] = 1
for i in range(h):
	forbidden[i][-1] = 1
for i in range(w):
	forbidden[-1][i] = 1
dt = [[0, 0], [1, 0], [0, 1], [1, 1]]
fill = [[0] * w for _ in range(h)]
ans = []
for i in range(h):
	for j in range(w):
		if forbidden[i][j] == 1:
			continue
		ans.append([i, j])
		for (k, (dx, dy)) in enumerate(dt):
			if i + dx < h and j + dy < w:
				fill[i + dx][j + dy] = 1
if fill == field:
	print(len(ans))
	for (x, y) in ans:
		print(x + 1, y + 1)
else:
	print(-1)


(n, m) = map(int, input().split())
a = []
for i in range(n):
	temp = [int(x) for x in input().split()]
	a.append(temp)
x = []
y = []
b = [[0 for i in range(m)] for j in range(n)]
count = 0
for i in range(n - 1):
	for j in range(m - 1):
		if a[i][j] == 1 and a[i][j + 1] == 1 and (a[i + 1][j] == 1) and (a[i + 1][j + 1] == 1):
			b[i][j] = 1
			b[i][j + 1] = 1
			b[i + 1][j] = 1
			b[i + 1][j + 1] = 1
			count += 1
			x.append(i + 1)
			y.append(j + 1)
if a != b:
	print('-1')
else:
	print(count)
	for i in range(count):
		print(x[i], y[i])


import sys
(n, m) = map(int, input().split())
a = [[] for x in range(n)]
for i in range(n):
	a[i] = list(map(int, input().split()))
b = [[0 for j in range(m)] for i in range(n)]
ans = []
for i in range(n - 1):
	for j in range(m - 1):
		if a[i][j] == 1 and a[i][j + 1] == 1 and (a[i + 1][j] == 1) and (a[i + 1][j + 1] == 1):
			ans.append((i, j))
			b[i][j] = 1
			b[i][j + 1] = 1
			b[i + 1][j] = 1
			b[i + 1][j + 1] = 1
for i in range(n):
	for j in range(m):
		if a[i][j] != b[i][j]:
			print(-1)
			sys.exit()
print(len(ans))
for p in ans:
	(x, y) = p
	print(x + 1, y + 1)


for t in range(1):
	(n, m) = list(map(int, input().split()))
	arr = []
	sets = set()
	for i in range(n):
		arr.append(list(map(int, input().split())))
	max_elem = max([max(i) for i in arr])
	ones = sum([sum(i) for i in arr])
	if max_elem == 0:
		print(0)
		continue
	ops = []
	for i in range(n):
		for j in range(m):
			if i + 1 < n and j + 1 < m:
				elems = (arr[i][j], arr[i + 1][j], arr[i][j + 1], arr[i + 1][j + 1])
				if elems == (1, 1, 1, 1):
					ops.append((i + 1, j + 1))
					sets.add((i, j))
					sets.add((i + 1, j))
					sets.add((i, j + 1))
					sets.add((i + 1, j + 1))
	if ops == [] or len(sets) != ones:
		print(-1)
	else:
		print(len(ops))
		for (i, j) in ops:
			print(i, j)


(n, m) = map(int, input().split())
matrix = []
we = 0
for i in range(n):
	l = list(map(int, input().split()))
	matrix.append(l)
i = 0
l = []
while i < n:
	j = 0
	while j < m:
		if j + 1 < m and i + 1 < n and (matrix[i][j] * matrix[i + 1][j] * matrix[i][j + 1] * matrix[i + 1][j + 1] > 0):
			l.append((i + 1, j + 1))
			matrix[i][j] = 2
			matrix[i + 1][j] = 2
			matrix[i][j + 1] = 2
			matrix[i + 1][j + 1] = 2
		j += 1
	i += 1
for i in range(n):
	for j in range(m):
		if matrix[i][j] == 1:
			we += 1
a = len(l)
if we != 0:
	print(-1)
else:
	print(a)
	for i in l:
		print(*i)


def I():
	return map(int, input().split())
(N, M) = I()
A = [list(I()) for _ in range(N)]
B = [[0 for _ in range(M)] for _ in range(N)]
S = []
if B == A:
	print(0)
else:
	for n in range(N - 1):
		for m in range(M - 1):
			if A[n][m] == 1 and A[n + 1][m] == 1 and (A[n][m + 1] == 1) and (A[n + 1][m + 1] == 1):
				(B[n][m], B[n + 1][m], B[n][m + 1], B[n + 1][m + 1]) = (1, 1, 1, 1)
				S.append([n, m])
	if B == A:
		print(len(S))
		for (X, Y) in S:
			print(X + 1, Y + 1)
	else:
		print(-1)


(n, m) = map(int, input().split())
A = []
for i in range(n):
	A.append(list(map(int, input().split())))
	x = A[-1].count(1)
res = []
marked = [[0] * m for _ in range(n)]
for i in range(n - 1):
	for j in range(m - 1):
		if A[i][j] == 1:
			if A[i + 1][j] == 1 and A[i][j + 1] == 1 and (A[i + 1][j + 1] == 1):
				marked[i][j] = 1
				marked[i + 1][j] = 1
				marked[i + 1][j + 1] = 1
				marked[i][j + 1] = 1
				res.append((i + 1, j + 1))
if marked == A:
	print(len(res))
	for item in res:
		print(item[0], item[1])
else:
	print(-1)


import math
import sys

def main():
	(n, m) = map(int, input().split())
	arr = []
	for _ in range(n):
		arr.append(list(map(int, input().split())))
	dp = [[0 for _ in range(m)] for _ in range(n)]
	ans = []
	for i in range(n - 1):
		for j in range(m - 1):
			if arr[i][j] * arr[i + 1][j] * arr[i][j + 1] * arr[i + 1][j + 1] > 0:
				ans.append([i, j])
				dp[i][j] = 1
	for x in ans:
		dp[x[0]][x[1]] = 1
		dp[x[0] + 1][x[1]] = 1
		dp[x[0]][x[1] + 1] = 1
		dp[x[0] + 1][x[1] + 1] = 1
	for i in range(n):
		for j in range(m):
			if arr[i][j] != dp[i][j]:
				print(-1)
				return
	print(len(ans))
	for x in ans:
		print(x[0] + 1, x[1] + 1)
	return
main()


(n, m) = map(int, input().split())
seq = []
matrix = []
for i in range(n):
	matrix.append(list(map(int, input().split())))
new_m = [[0] * m for i in range(n)]
for i in range(n - 1):
	for j in range(m - 1):
		if all(matrix[i][j:j + 2] + matrix[i + 1][j:j + 2]):
			for (k, l) in [[i, j], [i, j + 1], [i + 1, j], [i + 1, j + 1]]:
				new_m[k][l] = 1
			seq.append([i + 1, j + 1])
if new_m != matrix:
	print(-1)
else:
	print(len(seq))
	for operation in seq:
		print(*operation)


(n, m) = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]
b = [[0] * m for _ in range(n)]
op = []
for i in range(n - 1):
	for j in range(m - 1):
		if a[i][j] == a[i + 1][j] == a[i][j + 1] == a[i + 1][j + 1] == 1:
			op.append((i, j))
			b[i][j] = b[i + 1][j] = b[i][j + 1] = b[i + 1][j + 1] = 1
ok = True
for i in range(n):
	for j in range(m):
		if a[i][j] != b[i][j]:
			ok = False
if not ok:
	print(-1)
else:
	print(len(op))
	for x in op:
		print(x[0] + 1, x[1] + 1)


import sys
(n, m) = map(int, input().split())
a = []
b = [[0 for j in range(m)] for i in range(n)]
count = 0
res = []
for i in range(n):
	a.append(list(map(int, input().split())))
for i in range(n - 1):
	for j in range(m - 1):
		if sum(a[i][j:j + 2]) + sum(a[i + 1][j:j + 2]) == 4:
			(b[i][j], b[i][j + 1], b[i + 1][j], b[i + 1][j + 1]) = (1, 1, 1, 1)
			count += 1
			res.append(str(str(i + 1) + ' ' + str(j + 1)))
for i in range(n):
	for j in range(m):
		if a[i][j] != b[i][j]:
			print(-1)
			sys.exit()
print(count)
if res:
	print('\n'.join(res))


import sys

def chek(i, j):
	s = 0
	if a[i + 1][j] == 1:
		s += 1
	if a[i + 1][j + 1] == 1:
		s += 1
	if a[i][j + 1] == 1:
		s += 1
	if s == 3:
		return 1
	else:
		return 0

def cc(i, j):
	b1[i][j] = 1
	b1[i + 1][j] = 1
	b1[i + 1][j + 1] = 1
	b1[i][j + 1] = 1
(n, m) = map(int, input().split())
a = []
b = []
b1 = [[0] * m for _ in range(n)]
for i in range(n):
	r = list(map(int, input().split()))
	a.append(r)
for i in range(n - 1):
	for j in range(m - 1):
		if a[i][j] == 1:
			e = chek(i, j)
			if e == 1:
				b.append([i, j])
				cc(i, j)
if a == b1:
	r = len(b)
	print(r)
	for i in range(r):
		print(b[i][0] + 1, b[i][1] + 1)
else:
	print(-1)


(n, m) = map(int, input().split())
mat = []
for i in range(n):
	mat.append(list(map(int, input().split())))
ans = [[0 for i in range(m)] for j in range(n)]
anslist = []
for i in range(n - 1):
	for j in range(m - 1):
		if mat[i][j] == 1 and mat[i][j + 1] == 1 and (mat[i + 1][j] == 1) and mat[i + 1][j + 1]:
			for k in range(2):
				for l in range(2):
					ans[i + k][j + l] = 1
			anslist.append([i + 1, j + 1])
if mat == ans:
	print(len(anslist))
	for (i, j) in anslist:
		print(i, j)
else:
	print(-1)


(n, m) = map(int, input().split())
l = [[*map(int, input().split())] for _ in range(n)]
b = [[0] * m for _ in range(n)]
res = []
for i in range(n - 1):
	for j in range(m - 1):
		if all((l[i][j], l[i + 1][j], l[i][j + 1], l[i + 1][j + 1])):
			res.append(f'{i + 1} {j + 1}')
			b[i][j] = b[i + 1][j] = b[i][j + 1] = b[i + 1][j + 1] = 1
if b == l:
	print(len(res))
	print(*res, sep='\n')
else:
	print(-1)


(n, m) = [int(i) for i in input().split()]
a = []
b = []
for i in range(n):
	a.append([int(i) for i in input().split()])
	b.append([0 for i in range(m)])
steps = []
for i in range(n - 1):
	for j in range(m - 1):
		if a[i][j] == a[i + 1][j] == a[i][j + 1] == a[i + 1][j + 1] == 1:
			steps.append([i + 1, j + 1])
			b[i][j] = 1
			b[i + 1][j] = 1
			b[i][j + 1] = 1
			b[i + 1][j + 1] = 1
if a != b:
	print(-1)
else:
	print(len(steps))
	for st in steps:
		print(' '.join(map(str, st)))


def check_elements(i2, j2):
	all_zero = True
	all_ones = True
	for i in range(i2, i2 + 2):
		for j in range(j2, j2 + 2):
			if A[i][j] == 1:
				all_zero = False
			else:
				all_ones = False
	return (all_zero, all_ones)

def set_ones(i2, j2):
	for i in range(i2, i2 + 2):
		for j in range(j2, j2 + 2):
			B[i][j] = 1

def compare_matrix():
	for i in range(n):
		for j in range(m):
			if A[i][j] != B[i][j]:
				return False
	return True

def make_matrix():
	amount = 0
	operations = []
	for i in range(n - 1):
		for j in range(m - 1):
			(all_zero, all_ones) = check_elements(i, j)
			if all_ones is True and all_zero is False:
				amount += 1
				operations.append(str(i + 1) + ' ' + str(j + 1))
				set_ones(i, j)
	return (amount, operations)
(n, m) = map(int, input().split())
A = list()
B = [[0 for j in range(m)] for i in range(n)]
for _ in range(n):
	row = list(map(int, input().split()))
	A.append(row)
(ans, operations) = make_matrix()
if compare_matrix():
	print(ans)
	for elem in operations:
		print(elem)
else:
	print(-1)


def bo(x, y):
	if a[x][y] == 1 and a[x + 1][y] == 1 and (a[x][y + 1] == 1) and a[x + 1][y + 1]:
		return True
rw = 1
for wewq in range(rw):
	(n, m) = map(int, input().split())
	a = [0] * n
	b = [[0] * m for i in range(n)]
	t = True
	cx = []
	cy = []
	for i in range(n):
		a[i] = list(map(int, input().split()))
	for i in range(n - 1):
		for j in range(m - 1):
			if a[i][j] == 1 and bo(i, j):
				b[i][j] = 1
				b[i + 1][j] = 1
				b[i][j + 1] = 1
				b[i + 1][j + 1] = 1
				cx.append(i)
				cy.append(j)
			elif a[i][j] == 1 and b[i][j] == 1 or a[i][j] == 0:
				continue
			else:
				t = False
	if t and a == b:
		print(len(cx))
		for i in range(len(cx)):
			print(cx[i] + 1, cy[i] + 1)
	else:
		print(-1)


A1 = [[1, 1, 1], [1, 1, 1], [0, 1, 1]]
A2 = [[1, 0, 1], [1, 0, 1], [0, 0, 0]]
A3 = [[0, 0], [0, 0], [0, 0]]

def get_steps(a):
	n = len(a)
	m = len(a[0])
	steps = []
	for i in range(n):
		for j in range(m):
			if a[i][j] == 1:
				bottom_right = get_bottom_right(a, i, j)
				if bottom_right:
					steps.append((i, j))
				elif not get_bottom_left(a, i, j) | get_top_right(a, i, j) | get_top_left(a, i, j):
					return -1
	return steps

def get_top_left(a, i, j):
	if i - 1 < 0 or j - 1 < 0:
		return False
	return a[i][j - 1] & a[i - 1][j - 1] & a[i - 1][j]

def get_top_right(a, i, j):
	if i - 1 < 0 or j + 1 >= len(a[0]):
		return False
	return a[i][j + 1] & a[i - 1][j + 1] & a[i - 1][j]

def get_bottom_left(a, i, j):
	if j - 1 < 0 or i + 1 >= len(a):
		return False
	return a[i][j - 1] & a[i + 1][j - 1] & a[i + 1][j]

def get_bottom_right(a, i, j):
	if i + 1 >= len(a) or j + 1 >= len(a[0]):
		return False
	return a[i][j + 1] & a[i + 1][j + 1] & a[i + 1][j]
(n, m) = map(int, input().split())
A = []
for i in range(n):
	A.append(list(map(int, input().split())))
x = get_steps(A)
if x == -1:
	print(x)
else:
	print(len(x))
	for (i, j) in x:
		print(i + 1, j + 1)


(n, m) = [int(x) for x in input().split()]
A = []
for i in range(n):
	A.append([int(x) for x in input().split()])
B = [[0 for i in range(m)] for j in range(n)]
flag = 0
zflag = 0
for i in range(n):
	for j in range(m):
		if A[i][j] == 1:
			zflag = 1
			break
if zflag == 0:
	print(0)
	exit()
ans = []
count = 0
for i in range(n - 1):
	for j in range(m - 1):
		if A[i][j] == 1 and A[i][j + 1] == 1 and (A[i + 1][j] == 1) and (A[i + 1][j + 1] == 1):
			flag = 1
			B[i][j] = 1
			B[i][j + 1] = 1
			B[i + 1][j] = 1
			B[i + 1][j + 1] = 1
			count += 1
			ans.append((i + 1, j + 1))
if flag == 0:
	print(-1)
elif A == B:
	print(count)
	[print(i, j) for (i, j) in ans]
else:
	print(-1)


import sys
(n, m) = [int(s) for s in input().split(' ')]
mat = [[s == '1' for s in input().split(' ')] for r in range(n)]
new_mat = [[mat[r][c] for c in range(m)] for r in range(n)]
output = []
for (i, row) in enumerate(mat):
	for (j, val) in enumerate(row):
		if i < n - 1 and j < m - 1 and val:
			if mat[i][j + 1] and mat[i + 1][j] and mat[i + 1][j + 1]:
				output.append((str(i + 1), str(j + 1)))
				new_mat[i][j + 1] = new_mat[i + 1][j] = new_mat[i + 1][j + 1] = new_mat[i][j] = 0
		if new_mat[i][j]:
			print(-1)
			sys.exit()
print(len(output))
for coord in output:
	print(' '.join(coord))


import sys, heapq
(n, m) = map(int, sys.stdin.readline().split())
a = [list(map(int, sys.stdin.readline().split())) for _ in range(n)]
b = [[0] * m for _ in range(n)]
ans = []
for i in range(n):
	for j in range(m):
		if 0 <= i + 1 < n and 0 <= j + 1 < m:
			if a[i][j] == 1 and a[i + 1][j] == 1 and (a[i][j + 1] == 1) and (a[i + 1][j + 1] == 1):
				b[i][j] = 1
				b[i + 1][j] = 1
				b[i][j + 1] = 1
				b[i + 1][j + 1] = 1
				ans.append((i + 1, j + 1))
if a == b:
	print(len(ans))
	for i in ans:
		print(i[0], i[1])
else:
	print(-1)


(n, m) = map(int, input().split())
a = [[] for _ in range(n)]
for i in range(n):
	a[i] = [int(x) for x in input().split()]
ans = []
for i in range(n - 1):
	for j in range(m - 1):
		if a[i][j] * a[i][j + 1] * a[i + 1][j] * a[i + 1][j + 1] > 0:
			a[i][j] = 2
			a[i][j + 1] = 2
			a[i + 1][j] = 2
			a[i + 1][j + 1] = 2
			ans.append([i + 1, j + 1])
cnt = 0
for i in range(n):
	for j in range(m):
		if a[i][j] == 1:
			cnt = 1
			break
if cnt != 0:
	print(-1)
else:
	print(len(ans))
	for i in ans:
		print(i[0], i[1])


(n, m) = map(int, input().split())
a = []
b = []
for i in range(n):
	t = list(map(int, input().split()))
	a.append(t)
	b.append([0] * m)
kq = 0
for i in range(m):
	if a[1][i] == 0 and a[0][i] == 1:
		kq = -1
		break
	if a[n - 1][i] == 1 and a[n - 2][i] == 0:
		kq = -1
		break
for i in range(n):
	if a[i][0] == 1 and a[i][1] == 0:
		kq = -1
		break
	if a[i][m - 1] == 1 and a[i][m - 2] == 0:
		kq = -1
		break
c = []
if kq == -1:
	print(kq)
else:
	for i in range(n - 1):
		for j in range(m - 1):
			if a[i][j] == 1:
				if a[i][j + 1] == 1 and a[i + 1][j] == 1 and (a[i + 1][j + 1] == 1):
					b[i][j] = 1
					b[i][j + 1] = 1
					b[i + 1][j] = 1
					b[i + 1][j + 1] = 1
					c.append([i + 1, j + 1])
			if i > 0:
				if a[i - 1][j] != b[i - 1][j] or a[i - 1][j + 1] != b[i - 1][j + 1]:
					kq = -1
					break
		if kq == -1:
			break
	for i in range(n - 2, n):
		for j in range(m):
			if a[i][j] != b[i][j]:
				kq = -1
				break
	if kq == -1:
		print(kq)
	else:
		kq = len(c)
		print(kq)
		for i in range(kq):
			print(*c[i])


class Solve:

	def __init__(self, mat, tmp):
		self.mat = mat
		self.tmp = tmp
		self.ans = []
		self.flag = True
		self.solve()

	def solve(self):
		for r in range(n - 1):
			for c in range(m - 1):
				if self.mat[r][c] == self.mat[r][c + 1] == self.mat[r + 1][c] == self.mat[r + 1][c + 1] == 1:
					self.tmp[r][c] = 5
					self.tmp[r][c + 1] = 5
					self.tmp[r + 1][c] = 5
					self.tmp[r + 1][c + 1] = 5
					self.ans.append([r + 1, c + 1])
		for r in range(n):
			for c in range(m):
				if self.tmp[r][c] == 0:
					self.flag = False
					break
		if self.flag:
			print(len(self.ans))
			for r in self.ans:
				print(*r)
		else:
			print(-1)
(n, m) = map(int, input().split())
(mat, tmp) = ([], [])
for _ in range(n):
	row = list(map(int, input().split()))
	r = []
	for i in row:
		if i == 0:
			r.append(1)
		else:
			r.append(0)
	mat.append(row)
	tmp.append(r)
Solve(mat, tmp)


from itertools import product

def main():
	(n, m) = map(int, input().split())
	aa = []
	for _ in range(n):
		aa.append(list(map(int, input().split())))
	bb = [[0] * m for _ in range(n)]
	ops = []
	for (i, j) in product(range(n - 1), range(m - 1)):
		for (k, l) in product(range(2), range(2)):
			if aa[i + k][j + l] == 0:
				break
		else:
			for (k, l) in product(range(2), range(2)):
				bb[i + k][j + l] = 1
			ops.append((i + 1, j + 1))
	if aa == bb:
		print(len(ops))
		for o in ops:
			print(*o)
	else:
		print(-1)
main()


rowcol = list(map(int, input().split(' ')))
rows = rowcol[0]
cols = rowcol[1]
matrix = [0] * rows
rowsum = 0
for y in range(rows):
	row = list(map(int, input().split(' ')))
	matrix[y] = row
	rowsum += sum(row)
pairs = []
for a in range(rows - 1):
	for b in range(cols - 1):
		if matrix[a][b] == 1:
			if matrix[a][b + 1] == 1:
				if matrix[a + 1][b] == 1:
					if matrix[a + 1][b + 1] == 1:
						tup = [a, b]
						pairs.append(tup)
if rowsum == 0:
	print(0)
elif len(pairs) == 0:
	print(-1)
else:
	matrixb = [0] * rows
	for d in range(rows):
		col1 = [0] * cols
		matrixb[d] = col1
	for e in range(len(pairs)):
		matrixb[pairs[e][0]][pairs[e][1]] = 1
		matrixb[pairs[e][0] + 1][pairs[e][1]] = 1
		matrixb[pairs[e][0] + 1][pairs[e][1] + 1] = 1
		matrixb[pairs[e][0]][pairs[e][1] + 1] = 1
	if matrixb == matrix:
		print(len(pairs))
		for c in range(len(pairs)):
			print('{} {}'.format(pairs[c][0] + 1, pairs[c][1] + 1))
	else:
		print(-1)


import sys

def main():
	A = []
	B = []
	(n, m) = [int(x) for x in sys.stdin.readline().strip().split()]
	for _ in range(n):
		A.append([int(x) for x in sys.stdin.readline().strip().split()])
		B.append([0 for _ in range(m)])
	res = []
	for i in range(n - 1):
		for j in range(m - 1):
			if A[i][j] == 1 and A[i + 1][j] == 1 and (A[i][j + 1] == 1) and (A[i + 1][j + 1] == 1):
				B[i][j] = 1
				B[i + 1][j] = 1
				B[i][j + 1] = 1
				B[i + 1][j + 1] = 1
				res.append((i + 1, j + 1))
	for i in range(n):
		for j in range(m):
			if A[i][j] != B[i][j]:
				print(-1)
				return
	print(len(res))
	for (i, j) in res:
		print(i, j)
main()


def gns():
	return list(map(int, input().split()))
(n, m) = gns()
a = []
for i in range(n):
	a.append(gns())
b = [[0] * m for i in range(n)]

def one():
	ans = []
	for i in range(n - 1):
		for j in range(m - 1):
			if a[i][j] == 1 and a[i + 1][j] == 1 and (a[i][j + 1] == 1) and (a[i + 1][j + 1] == 1):
				ans.append([i, j])
				b[i][j] = 1
				b[i][j + 1] = 1
				b[i + 1][j] = 1
				b[i + 1][j + 1] = 1
	for i in range(n):
		for j in range(m):
			if b[i][j] != a[i][j]:
				return False
	return ans
ans = one()
if ans == False:
	print(-1)
	quit()
if len(ans) == 0:
	print(0)
	quit()
print(len(ans))
for x in ans:
	print(x[0] + 1, x[1] + 1)


gi = lambda : list(map(int, input().split()))
(n, m) = gi()
a = [gi() for _ in range(n)]
b = [[0] * m for _ in range(n)]
ans = []
for k in range(n - 1):
	for j in range(m - 1):
		if a[k][j] == a[k][j + 1] == a[k + 1][j] == a[k + 1][j + 1] == 1:
			b[k][j] = b[k][j + 1] = b[k + 1][j] = b[k + 1][j + 1] = 1
			ans.append((k + 1, j + 1))
for k in range(n):
	for j in range(m):
		if a[k][j] != b[k][j]:
			print(-1)
			exit()
print(len(ans))
for e in ans:
	print(*e)


(n, m) = map(int, input().split())
a = [list(map(int, input().split())) for i in range(n)]
ones = 0
for i in range(n):
	for j in range(m):
		if a[i][j] == 1:
			ones += 1
if ones == 0:
	print(0)
	exit(0)

def is_square(i, j):
	if i - 1 > -1 and j - 1 > -1:
		if a[i][j - 1] == 1 and a[i - 1][j] == 1 and (a[i - 1][j - 1] == 1):
			return True
	if i - 1 > -1 and j + 1 < m:
		if a[i - 1][j] == 1 and a[i][j + 1] == 1 and (a[i - 1][j + 1] == 1):
			return True
	if i + 1 < n and j - 1 > -1:
		if a[i + 1][j] == 1 and a[i][j - 1] == 1 and (a[i + 1][j - 1] == 1):
			return True
	if i + 1 < n and j + 1 < m:
		if a[i + 1][j] == 1 and a[i][j + 1] == 1 and (a[i + 1][j + 1] == 1):
			return True
	return False

def fill_square(i, j):
	if i + 1 < n and j + 1 < m:
		if a[i + 1][j] == 1 and a[i][j + 1] == 1 and (a[i + 1][j + 1] == 1):
			return [i + 1, j + 1]

def counter(i, j):
	if i + 1 < n and j + 1 < m:
		if a[i + 1][j] == 1 and a[i][j + 1] == 1 and (a[i + 1][j + 1] == 1):
			return 1
		else:
			return False
	else:
		return False
for i in range(n):
	for j in range(m):
		if a[i][j] == 1:
			if is_square(i, j):
				pass
			else:
				print(-1)
				exit(0)
k = 0
for i in range(n):
	for j in range(m):
		if a[i][j] == 1:
			if counter(i, j):
				k += int(counter(i, j))
to_do = []
for i in range(n):
	for j in range(m):
		if a[i][j] == 1:
			if fill_square(i, j):
				to_do.append(fill_square(i, j))
print(k)
for i in range(k):
	print(*to_do[i])


def main():
	(n, m) = [int(s) for s in input().split()]
	A = []
	B = [[0] * m for _ in range(n)]
	for _ in range(n):
		A.append([int(s) for s in input().split()])
	ops = []
	for i in range(n - 1):
		for j in range(m - 1):
			if A[i][j] == A[i][j + 1] == A[i + 1][j] == A[i + 1][j + 1] == 1:
				ops.append((i, j))
				B[i][j] = 1
				B[i][j + 1] = 1
				B[i + 1][j] = 1
				B[i + 1][j + 1] = 1
	for i in range(n):
		for j in range(m):
			if A[i][j] != B[i][j]:
				print(-1)
				return
	print(len(ops))
	for (x, y) in ops:
		print('{} {}'.format(x + 1, y + 1))
main()


import math
from collections import deque, defaultdict
from sys import stdin, stdout
input = stdin.readline
listin = lambda : list(map(int, input().split()))
mapin = lambda : map(int, input().split())
(n, m) = mapin()
a = []
c = 0
for i in range(n):
	a.append(listin())
	c += a[i].count(1)
b = [[0 for i in range(m)] for i in range(n)]
ans = []
for i in range(n - 1):
	for j in range(m - 1):
		if a[i][j] == 1 and a[i + 1][j] == 1 and (a[i][j + 1] == 1) and (a[i + 1][j + 1] == 1):
			b[i][j] = b[i + 1][j] = b[i][j + 1] = b[i + 1][j + 1] = 1
			ans.append([i + 1, j + 1])
if a == b:
	print(len(ans))
	for i in ans:
		print(*i)
else:
	print(-1)


(n, m) = map(int, input().split())
a = [list(map(int, input().split())) for j in range(n)]
b = [[0 for i in range(m)] for j in range(n)]
c = 0
l = []
s = 0
for i in a:
	s += sum(i)
if s == 0:
	print(0)
else:
	for i in range(n - 1):
		for j in range(m - 1):
			if a[i][j] == a[i + 1][j + 1] == a[i + 1][j] == a[i][j + 1] == 1:
				l.append([i + 1, j + 1])
				b[i][j] = b[i + 1][j + 1] = b[i + 1][j] = b[i][j + 1] = 1
	if len(l) and b == a:
		print(len(l))
		for i in l:
			print(i[0], i[1])
	else:
		print(-1)


(n, m) = map(int, input().split())
matrix = [list(map(int, input().split())) for _ in range(n)]
ans = []
for i in range(n):
	for j in range(m):
		if i + 1 < n and j + 1 < m:
			if matrix[i][j + 1] != 0 and matrix[i + 1][j] != 0 and (matrix[i + 1][j + 1] != 0) and (matrix[i][j] != 0):
				ans += [(i + 1, j + 1)]
				matrix[i][j + 1] = 2
				matrix[i + 1][j] = 2
				matrix[i + 1][j + 1] = 2
				matrix[i][j] = 2
check = True
for i in range(n):
	for j in range(m):
		if matrix[i][j] == 1:
			check = False
if check:
	print(len(ans))
	for (a, b) in ans:
		print(a, b)
else:
	print(-1)


from math import *
from sys import *
(n, k) = map(int, stdin.readline().split())
m = []
for i in range(n):
	a = list(map(int, stdin.readline().split()))
	m.append(a)
mark = []
for i in range(n):
	a = [0] * k
	mark.append(a)
a = 0
ans = []
for i in range(n - 1):
	for j in range(k - 1):
		if m[i][j] == 1 and m[i + 1][j] == 1 and (m[i][j + 1] == 1) and (m[i + 1][j + 1] == 1):
			a += 1
			ans.append([i + 1, j + 1])
			mark[i][j] = 1
			mark[i + 1][j] = 1
			mark[i][j + 1] = 1
			mark[i + 1][j + 1] = 1
f = 0
for i in range(n):
	for j in range(k):
		if m[i][j] == 1 and mark[i][j] == 0:
			f = 1
			break
if f == 1:
	print(-1)
else:
	print(a)
	for i in range(a):
		print(*ans[i])


from sys import stdin
input = stdin.readline
a = []
ans = []
cnt = 0
(n, m) = map(int, input().split())
for i in range(n):
	b = list(map(int, input().split()))
	a.append(b)
	cnt += b.count(1)
if cnt == 0:
	print('0')
	exit()
c = [[0 for x in range(m)] for y in range(n)]
for i in range(n - 1):
	for j in range(m - 1):
		if a[i][j] == 1 and a[i + 1][j] == 1 and (a[i][j + 1] == 1) and (a[i + 1][j + 1] == 1):
			c[i][j] = 1
			c[i + 1][j] = 1
			c[i][j + 1] = 1
			c[i + 1][j + 1] = 1
			ans.append([i + 1, j + 1])
if a == c:
	print(len(ans))
	for i in range(len(ans)):
		print(ans[i][0], ans[i][1])
else:
	print('-1')


(n, m) = map(int, input().split())
li = []
b = []
c = 0
d = []
for i in range(n):
	a = list(map(int, input().split()))
	li.append(a)
	bb = [0] * m
	b.append(bb)
for i in range(n - 1):
	for j in range(m - 1):
		if (li[i][j] and li[i][j + 1] and li[i + 1][j] and li[i + 1][j + 1]) and (b[i][j] and b[i][j + 1] and b[i + 1][j] and b[i + 1][j + 1]) != 1:
			b[i][j] = 1
			b[i][j + 1] = 1
			b[i + 1][j] = 1
			b[i + 1][j + 1] = 1
			c += 1
			d.append(i + 1)
			d.append(j + 1)
if li != b:
	print(-1)
else:
	print(c)
	for i in range(0, len(d), 2):
		print(d[i], d[i + 1])


(n1, m1) = map(int, input().split())
a = []
c = []
b = [[0 for _ in range(m1)] for _ in range(n1)]
for j in range(n1):
	a.append(list(map(int, input().split())))
d = 0
for n in range(n1 - 1):
	for m in range(m1 - 1):
		if a[n][m] == 1 and a[n + 1][m] == 1 and (a[n][m + 1] == 1) and (a[n + 1][m + 1] == 1):
			(b[n][m], b[n + 1][m], b[n][m + 1], b[n + 1][m + 1]) = (1, 1, 1, 1)
			c.append([n + 1, m + 1])
if a == b:
	print(len(c))
	for j in range(len(c)):
		print(*c[j])
else:
	print(-1)


import sys
(n, m) = map(int, sys.stdin.readline().split())
arr = []
b = []
ans = []
for _ in range(n):
	arr.append(list(map(int, sys.stdin.readline().split())))
	b.append([0] * m)
for i in range(n - 1):
	for j in range(m - 1):
		a = [arr[i][j], arr[i][j + 1], arr[i + 1][j], arr[i + 1][j + 1]]
		if 0 in a:
			continue
		else:
			b[i][j] = a[0]
			b[i][j + 1] = a[1]
			b[i + 1][j] = a[2]
			b[i + 1][j + 1] = a[3]
			ans.append((i + 1, j + 1))
if b == arr:
	print(len(ans))
	for (x, y) in ans:
		print(x, y)
else:
	print(-1)


from math import log
from collections import defaultdict, deque
from sys import stdin, stdout
from bisect import bisect_left, bisect_right
from copy import deepcopy
inp = lambda : int(stdin.readline())
sip = lambda : stdin.readline()
mulip = lambda : map(int, stdin.readline().split())
lst = lambda : list(map(int, stdin.readline().split()))
slst = lambda : list(sip())
M = pow(10, 9) + 7
(n, m) = mulip()
A = []
B = [[0] * m for i in range(n)]
for i in range(n):
	l = lst()
	A.append(l)
k = []
for i in range(1, n):
	for j in range(1, m):
		if A != B:
			if A[i][j] == 1 and A[i - 1][j] == 1 and (A[i - 1][j - 1] == 1) and (A[i][j - 1] == 1):
				B[i - 1][j - 1] = 1
				B[i - 1][j] = 1
				B[i][j - 1] = 1
				B[i][j] = 1
				k.append([i, j])
if A == B:
	if len(k) == 0:
		print(0)
	else:
		print(len(k))
		for l in k:
			print(*l)
else:
	print(-1)


(n, m) = map(int, input().split())
mat = []
b = []
x = []
for i in range(n):
	mat.append(list(map(int, input().split())))
	b.append([0] * m)
for i in range(n - 1):
	for j in range(m - 1):
		if mat[i][j] == 1 and mat[i + 1][j] == 1 and (mat[i][j + 1] == 1) and (mat[i + 1][j + 1] == 1):
			b[i][j] = 1
			b[i + 1][j] = 1
			b[i][j + 1] = 1
			b[i + 1][j + 1] = 1
			x.append([i + 1, j + 1])
if mat == b:
	print(len(x))
	for i in range(len(x)):
		print(*x[i])
else:
	print(-1)


import sys
input = sys.stdin.readline
(N, M) = map(int, input().split())
B = [[0] * M for _ in range(N)]
A = [list(map(int, input().split())) for _ in range(N)]

def bOne(r, c):
	global B
	B[r][c] = 1
	B[r + 1][c] = 1
	B[r][c + 1] = 1
	B[r + 1][c + 1] = 1

def isAllOne(r, c):
	global A
	x = [0, 0, 1, 1]
	y = [0, 1, 0, 1]
	for j in range(4):
		nr = r + y[j]
		nc = c + x[j]
		if A[nr][nc] != 1:
			return False
	return True
q = []
for i in range(N - 1):
	for j in range(M - 1):
		if isAllOne(i, j):
			q.append((i, j))
for (r, c) in q:
	bOne(r, c)
if A == B:
	print(len(q))
	for (r, c) in q:
		print(r + 1, c + 1)
else:
	print(-1)


from copy import copy, deepcopy

def operation(B, i, j):
	B[i][j] = 1
	B[i + 1][j] = 1
	B[i][j + 1] = 1
	B[i + 1][j + 1] = 1

def compare(A, i, j):
	if A[i][j] == 1 and A[i + 1][j] == 1 and (A[i][j + 1] == 1) and (A[i + 1][j + 1] == 1):
		return True
	else:
		return False
(n, m) = input().split(' ')
(n, m) = (int(n), int(m))
A = []
B = [[0 for _ in range(m)] for _ in range(n)]
n2 = n
while n2:
	A.append([int(x) for x in input().split(' ')])
	n2 -= 1
op = 0
res = []
i = 0
j = 0
while i < n - 1:
	j = 0
	while j < m - 1:
		if compare(A, i, j):
			operation(B, i, j)
			op += 1
			res.append([i + 1, j + 1])
		j += 1
	i += 1
if A == B:
	print(op)
	for i in res:
		print(*i)
else:
	print(-1)


(n, m) = map(int, input().split())
a = []
for i in range(n):
	li = list(map(int, input().split()))
	a.append(li)
ans = []
b = []
for i in range(n):
	li = [0 for j in range(m)]
	b.append(li)
for i in range(n - 1):
	for j in range(m - 1):
		if [a[i][j], a[i + 1][j], a[i][j + 1], a[i + 1][j + 1]] == [1, 1, 1, 1]:
			b[i][j] = 1
			b[i + 1][j] = 1
			b[i][j + 1] = 1
			b[i + 1][j + 1] = 1
			ans.append([i + 1, j + 1])
for i in range(n):
	for j in range(m):
		if a[i][j] != b[i][j]:
			print(-1)
			exit()
print(len(ans))
for t in ans:
	print(t[0], t[1])


from sys import stdin, stdout
input = stdin.readline
(n, m) = map(int, input().split())
mat = []
for i in range(n):
	mat.append([*map(int, input().split())])
com = [[0 for t in range(m)] for p in range(n)]
ans = []
for i in range(n - 1):
	for j in range(m - 1):
		if mat[i][j] and mat[i + 1][j] and mat[i + 1][j + 1] and mat[i][j + 1]:
			ans.append([i + 1, j + 1])
			com[i][j] = 1
			com[i + 1][j] = 1
			com[i][j + 1] = 1
			com[i + 1][j + 1] = 1
if com == mat:
	print(len(ans))
	for i in ans:
		print(*i)
else:
	print(-1)


n = lambda : map(int, input().split())
(x, y) = n()
l = []
b = []
w = []
for __ in range(x):
	l.append(list(n()))
	b.append([0] * y)
for i in range(x - 1):
	for j in range(y - 1):
		if l[i][j] and l[i + 1][j] == 1 and (l[i][j + 1] == 1) and (l[i + 1][j + 1] == 1):
			b[i][j] = 1
			b[i + 1][j] = 1
			b[i][j + 1] = 1
			b[i + 1][j + 1] = 1
			w.append([i + 1, j + 1])
if l == b:
	print(len(w))
	for i in range(len(w)):
		print(*w[i])
else:
	print('-1')


(n, m) = list(map(int, input().split()))
A = [list(map(int, input().split())) for _ in range(n)]
B = [[0 for j in range(m)] for i in range(n)]
nos_zero = 0
res = []
for i in range(n - 1):
	for j in range(m - 1):
		if A[i][j] and A[i + 1][j] and A[i][j + 1] and A[i + 1][j + 1]:
			res.append((i + 1, j + 1))
			B[i][j] = B[i + 1][j] = B[i][j + 1] = B[i + 1][j + 1] = 1
for row in A:
	for i in row:
		if not i:
			nos_zero += 1
if not res:
	if nos_zero == m * n:
		print(0)
	else:
		print(-1)
elif A != B:
	print(-1)
else:
	print(len(res))
	[print(i, j) for (i, j) in res]


(n, m) = map(int, input().split())
l = []
r = [[0 for _ in range(m)] for p in range(n)]
a = []
f = 0
for _ in range(n):
	l.append(list(map(int, input().split())))
for i in range(n - 1):
	for j in range(m - 1):
		if l[i][j] == 1 and l[i][j + 1] == 1 and (l[i + 1][j] == 1) and (l[i + 1][j + 1] == 1):
			r[i][j] = 1
			r[i][j + 1] = 1
			r[i + 1][j] = 1
			r[i + 1][j + 1] = 1
			a.append([i, j])
for i in range(n):
	for j in range(m):
		if l[i][j] != r[i][j]:
			f = 1
			break
if f:
	print(-1)
else:
	print(len(a))
	for (i, j) in a:
		print(i + 1, j + 1)


(n, m) = map(int, input().split())
c = []
count = 0
a = [[j for j in map(int, input().split())] for i in range(n)]
b = [[0 for j in range(m)] for i in range(n)]
for i in range(n - 1):
	for j in range(m - 1):
		if a[i][j] == 1 and a[i][j + 1] == 1 and (a[i + 1][j] == 1) and (a[i + 1][j + 1] == 1):
			b[i][j] = 1
			b[i][j + 1] = 1
			b[i + 1][j] = 1
			b[i + 1][j + 1] = 1
			count += 1
			c.append(i + 1)
			c.append(j + 1)
if a != b:
	print(-1)
else:
	print(count)
	i = 0
	while i < len(c) - 1:
		print(c[i], c[i + 1])
		i += 2


def itPos(i, j, n, m, a):
	if i >= 0 and j >= 0 and (i < n) and (j < m) and (a[i][j] == 1):
		return True
	return False

def getPainting(a, b, i, j):
	global ans
	if itPos(i + 1, j, len(a), len(a[0]), a) and itPos(i, j + 1, len(a), len(a[0]), a) and itPos(i + 1, j + 1, len(a), len(a[0]), a) and itPos(i, j, len(a), len(a[0]), a):
		b[i][j] = 1
		b[i + 1][j + 1] = 1
		b[i + 1][j] = 1
		b[i][j + 1] = 1
		ans.append([i + 1, j + 1])
(n, m) = map(int, input().split())
a = []
for i in range(n):
	a.append(list(map(int, input().split())))
b = []
for i in range(n):
	b.append([0] * m)
ans = []
for i in range(len(a)):
	for j in range(len(a[i])):
		getPainting(a, b, i, j)
for i in range(len(a)):
	for j in range(len(a[i])):
		if a[i][j] != b[i][j]:
			print(-1)
			exit()
print(len(ans))
for i in range(len(ans)):
	print(' '.join(list(map(str, ans[i]))))


(r, c) = map(int, input().split())
a = []
b = [[0 for j in range(c)] for i in range(r)]
for i in range(r):
	a.append(list(map(int, input().split())))
if a == b:
	print(0)
else:
	ind = []
	k = 0
	for i in range(r - 1):
		for j in range(c - 1):
			if a[i][j] == 1 and a[i + 1][j] == 1 and (a[i][j + 1] == 1) and (a[i + 1][j + 1] == 1):
				k += 1
				ind.append((i + 1, j + 1))
				b[i][j] = b[i + 1][j] = b[i][j + 1] = b[i + 1][j + 1] = 1
	if a == b:
		print(k)
		for elem in ind:
			print(*elem)
	else:
		print(-1)


from sys import stdin

def r():
	return stdin.readline().strip()

def r_t(tp):
	return map(tp, r().strip().split())

def r_a(tp):
	return list(r_t(tp))

def solve(n, m, M):
	(marked, ans) = ([[False for _ in range(m)] for _ in range(n)], list())
	for i in range(n - 1):
		for j in range(m - 1):
			if M[i][j] and M[i + 1][j] and M[i][j + 1] and M[i + 1][j + 1]:
				ans.append((i, j))
				marked[i][j] = marked[i + 1][j] = marked[i][j + 1] = marked[i + 1][j + 1] = True
	for i in range(n):
		for j in range(m):
			if M[i][j] and (not marked[i][j]):
				return [-1]
	return ans

def main():
	(n, m) = r_t(int)
	M = []
	for i in range(n):
		M.append(r_a(int))
	ans = solve(n, m, M)
	if ans == [-1]:
		print(-1)
	else:
		print(len(ans))
		for (a, b) in ans:
			print(a + 1, 1 + b)
main()


from collections import defaultdict as dc
import sys
import math

def inp():
	p = sys.stdin.readline()
	return p
(n, m) = list(map(int, inp().split()))
p = []
for _ in range(n):
	q = list(map(int, inp().split()))
	p.append(q)
q = [[0 for i in range(m)] for i in range(n)]
r = []
for i in range(n - 1):
	for j in range(m - 1):
		if p[i][j] and p[i + 1][j] and p[i][j + 1] and p[i + 1][j + 1]:
			(q[i][j], q[i + 1][j], q[i][j + 1], q[i + 1][j + 1]) = (1, 1, 1, 1)
			r.append((i + 1, j + 1))
k = 0
for i in range(n):
	for j in range(m):
		if p[i][j] != q[i][j]:
			k = 1
if k == 1:
	print(-1)
else:
	print(len(r))
	for i in range(len(r)):
		print(*r[i])


def read():
	(n, m) = map(int, input().split())
	a = []
	for i in range(n):
		a.append(input().split())
	return (n, m, a)

def solve(n, m, a):
	steps = []
	b = [['0'] * m for i in range(n)]
	for i in range(n - 1):
		for j in range(m - 1):
			if a[i][j] == '1':
				if a[i + 1][j] == '1' and a[i][j + 1] == '1' and (a[i + 1][j + 1] == '1'):
					steps.append((i + 1, j + 1))
					b[i][j] = b[i + 1][j] = b[i][j + 1] = b[i + 1][j + 1] = '1'
	for i in range(n):
		for j in range(m):
			if a[i][j] != b[i][j]:
				return None
	return steps
result = solve(*read())
if result is not None:
	print(len(result))
	for step in result:
		print(*step)
else:
	print(-1)


(n, m) = map(int, input().split())
A = [[] for _ in range(n)]
Ans = []
for i in range(n):
	A[i] = [int(j) for j in input().split()]
B = [[False] * m for _ in range(n)]
D = ((0, 0), (1, 0), (0, 1), (1, 1))
for i in range(n - 1):
	for j in range(m - 1):
		if A[i][j] == 0:
			continue
		else:
			ct = 0
			for (dx, dy) in D:
				if A[i + dx][j + dy] != 0:
					ct += 1
			if ct == 4:
				Ans.append([i + 1, j + 1])
				for (dx, dy) in D:
					B[i + dx][j + dy] = True
flag = True
for i in range(n):
	for j in range(m):
		if A[i][j] == 1 and B[i][j] != True:
			flag = False
if flag:
	print(len(Ans))
	for i in range(len(Ans)):
		print(*Ans[i])
else:
	print(-1)


(x, y) = map(int, input().split())
li = [0] * x
for i in range(x):
	(*li[i],) = map(int, input().split())
li1 = []
for i in range(x - 1):
	for j in range(y - 1):
		if li[i][j] * li[i + 1][j + 1] * li[i][j + 1] * li[i + 1][j] > 0:
			li1.append([i + 1, j + 1])
			li[i][j] += 1
			li[i + 1][j] += 1
			li[i][j + 1] += 1
			li[i + 1][j + 1] += 1
cnt = 0
for i in range(x):
	cnt += li[i].count(1)
if cnt:
	print(-1)
else:
	print(len(li1))
	for i in li1:
		print(i[0], i[1])


(a, b) = list(map(int, input().split()))
array = []
array_b = []
answer = []
flag = 5
for x in range(a):
	row = list(map(int, input().split()))
	array.append(row)
	row = [0] * b
	array_b.append(row)
for z in range(len(array_b)):
	row = array_b[z]
	for x in range(len(row)):
		if row[x] == 0:
			if array[z][x] == 0:
				pass
			elif x + 1 < b and z + 1 < a:
				if array[z][x + 1] == 1 and array[z + 1][x] == 1 and (array[z + 1][x + 1] == 1):
					array_b[z][x] = 1
					array_b[z][x + 1] = 1
					array_b[z + 1][x] = 1
					array_b[z + 1][x + 1] = 1
					answer.append([z + 1, x + 1])
				else:
					flag = 6
					break
			else:
				flag = 6
				break
		elif array[z][x] == 0:
			pass
		elif x + 1 < b and z + 1 < a:
			if array[z][x + 1] == 1 and array[z + 1][x] == 1 and (array[z + 1][x + 1] == 1):
				array_b[z][x] = 1
				array_b[z][x + 1] = 1
				array_b[z + 1][x] = 1
				array_b[z + 1][x + 1] = 1
				answer.append([z + 1, x + 1])
			else:
				pass
		else:
			pass
	if flag == 6:
		break
if flag == 6:
	print(-1)
else:
	print(len(answer))
	for it in answer:
		print(*it)


import sys
(n, m) = list(map(int, sys.stdin.readline().strip().split()))
A = []
for i in range(0, n):
	A.append(list(map(int, sys.stdin.readline().strip().split())))
C = []
for i in range(0, n - 1):
	for j in range(0, m - 1):
		if min([A[i][j], A[i][j + 1], A[i + 1][j], A[i + 1][j + 1]]) == 1:
			C.append([i + 1, j + 1])
			A[i][j] = 2
			A[i][j + 1] = 2
			A[i + 1][j] = 2
			A[i + 1][j + 1] = 2
v = True
for i in range(0, n):
	if 1 in A[i]:
		v = False
if v == False:
	print(-1)
else:
	print(len(C))
	for c in C:
		print(str(c[0]) + ' ' + str(c[1]))


from sys import stdin

def iinput():
	return int(stdin.readline())

def minput():
	return map(int, stdin.readline().split())

def linput():
	return list(map(int, stdin.readline().split()))
(n, m) = minput()
matA = []
for _ in range(n):
	matA.append(linput())
op = []
for i in range(n - 1):
	for j in range(m - 1):
		if matA[i][j] and matA[i][j + 1] and matA[i + 1][j] and matA[i + 1][j + 1]:
			matA[i][j] = matA[i][j + 1] = matA[i + 1][j] = matA[i + 1][j + 1] = -1
			op.append((i + 1, j + 1))
c = 0
for i in range(n):
	c += matA[i].count(1)
if c:
	print(-1)
else:
	print(len(op))
	for e in op:
		print(*e)


import sys
input = sys.stdin.readline
(n, m) = [int(x) for x in input().split()]
a = []
b = [[0] * m for j in range(n)]
ans = []
for i in range(n):
	a.append([int(x) for x in input().split()])
for x in range(n - 1):
	for y in range(m - 1):
		if a[x][y] == a[x][y + 1] == a[x + 1][y] == a[x + 1][y + 1] == 1:
			b[x][y] = 1
			b[x][y + 1] = 1
			b[x + 1][y] = 1
			b[x + 1][y + 1] = 1
			ans.append(str(x + 1) + ' ' + str(y + 1))
if a == b:
	print(len(ans))
	for i in ans:
		print(i)
else:
	print(-1)


(n, m) = list(map(int, input().split()))
shape = []
zero_shape = []
for i in range(n):
	shape.append(list(map(int, input().split())))
	zero_shape.append([0] * m)
order = []
for i in range(n - 1):
	for j in range(m - 1):
		if shape[i][j] == 1 and shape[i + 1][j] == 1 and (shape[i][j + 1] == 1) and (shape[i + 1][j + 1] == 1):
			zero_shape[i][j] = 1
			zero_shape[i + 1][j] = 1
			zero_shape[i][j + 1] = 1
			zero_shape[i + 1][j + 1] = 1
			order.append(str(i + 1) + ' ' + str(j + 1))
if shape == zero_shape:
	print(len(order))
	for row in order:
		print(row)
else:
	print(-1)


(x, y) = [int(i) for i in input().split()]
arr1 = []
for i in range(x):
	d = [int(i) for i in input().split()]
	arr1.append(d)
dict1 = {}
dict2 = {}
g = [[0] * y for _ in range(x)]
f = []
case = True
case1 = False
for i in range(x - 1):
	for j in range(y - 1):
		d = []
		if arr1[i][j] == arr1[i + 1][j] == arr1[i][j + 1] == arr1[i + 1][j + 1] == 1:
			d.append(i + 1)
			d.append(j + 1)
			f.append(d)
			g[i][j] = 1
			g[i + 1][j + 1] = 1
			g[i + 1][j] = 1
			g[i][j + 1] = 1
if arr1 != g:
	case = False
	print(-1)
if case:
	print(len(f))
	for i in f:
		print(*i)


(n, m) = map(int, input().split())
matrix = []
one = 0
one2 = 0
for i in range(n):
	matrix.append([int(i) for i in input().split()])
used = [[False for i in range(m)] for j in range(n)]
for i in matrix:
	for j in i:
		if j == 1:
			one += 1
squares = 0
seq = []
for i in range(n - 1):
	for j in range(m - 1):
		if matrix[i][j] == 1 and matrix[i][j + 1] == 1 and (matrix[i + 1][j] == 1) and (matrix[i + 1][j + 1] == 1):
			squares += 1
			seq.append('{} {}'.format(i + 1, j + 1))
			if not used[i][j]:
				used[i][j] = True
				one2 += 1
			if not used[i][j + 1]:
				used[i][j + 1] = True
				one2 += 1
			if not used[i + 1][j]:
				used[i + 1][j] = True
				one2 += 1
			if not used[i + 1][j + 1]:
				used[i + 1][j + 1] = True
				one2 += 1
if one2 == one:
	print(len(seq))
	for i in seq:
		print(i)
else:
	print(-1)


n = input().split()
i = 0
ans = []
while int(n[0]) > i:
	str = input()
	if i == 0:
		x = [None] * int(n[0])
		y = [None] * int(n[0])
	x[i] = str.split()
	y[i] = ['0'] * int(n[1])
	i += 1
i = 0
end = 1
while int(n[0]) > i:
	for (j, item) in enumerate(x[i]):
		if item == '0':
			continue
		if j + 1 < len(x[i]) and i + 1 < int(n[0]):
			if x[i + 1][j + 1] == '1' and x[i][j + 1] == '1' and (x[i + 1][j] == '1'):
				y[i + 1][j + 1] = y[i][j + 1] = y[i + 1][j] = y[i][j] = '1'
				ans.append([i, j])
	i += 1
i = 0
while int(n[0]) > i:
	for (j, item) in enumerate(x[i]):
		if item != y[i][j]:
			print('-1')
			end = 0
			break
	if not end:
		break
	i += 1
i = 0
if end:
	if not ans:
		print(0)
	else:
		print(len(ans))
		for item in ans:
			print('{one} {two}'.format(one=int(item[0]) + 1, two=int(item[1]) + 1))


(n, m) = map(int, input().split())
l = [list(map(int, input().split())) for _ in range(n)]
x = [[0] * m for _ in range(n)]
r = []
for i in range(n - 1):
	for j in range(m - 1):
		if [l[i][j], l[i + 1][j], l[i][j + 1], l[i + 1][j + 1]].count(0) == 0:
			r.append([i + 1, j + 1])
			(x[i][j], x[i + 1][j], x[i][j + 1], x[i + 1][j + 1]) = (1, 1, 1, 1)
if x == l:
	print(len(r))
	for i in r:
		print(*i)
else:
	print(-1)


def s(x, y):
	ans = 0
	global m, n
	if x:
		ans += arr[x - 1][y]
	if x + 1 < n:
		ans += arr[x + 1][y]
	if y:
		ans += arr[x][y - 1]
	if y + 1 < m:
		ans += arr[x][y + 1]
	return ans
(n, m) = map(int, input().split())
arr = []
for i in range(n):
	arr.append(list(map(int, input().split())))
for i in range(n):
	for j in range(m):
		if arr[i][j] and s(i, j) <= 1:
			print(-1)
			exit()
cnt = 0
ans = []
test = [[0] * m for i in range(n)]
for i in range(n - 1):
	for j in range(m - 1):
		if arr[i][j] and arr[i + 1][j] and arr[i][j + 1] and arr[i + 1][j + 1]:
			cnt += 1
			test[i][j] = test[i + 1][j] = test[i][j + 1] = test[i + 1][j + 1] = 1
			ans.append([i + 1, j + 1])
if arr == test:
	print(cnt)
	for i in ans:
		print(*i)
else:
	print(-1)


a = input().split()
(n, m) = (int(a[0]), int(a[1]))
k = []
s = 0
result = []
if n == 1 or m == 1:
	s = -1
for i in range(n):
	a = input().split()
	k.append(a)
mas = []
for i in range(n):
	d = []
	for i in range(m):
		d.append('0')
	mas.append(d)
if k == mas:
	print(0)
else:
	for i in range(n - 1):
		for j in range(m - 1):
			if k[i][j] == '1' and k[i][j + 1] == '1' and (k[i + 1][j + 1] == '1') and (k[i + 1][j] == '1'):
				result.append([str(i + 1), str(j + 1)])
				mas[i][j] = '1'
				mas[i][j + 1] = '1'
				mas[i + 1][j + 1] = '1'
				mas[i + 1][j] = '1'
				s += 1
	if k == mas:
		print(s)
		for i in result:
			print(' '.join(i))
	else:
		print(-1)


(n, m) = [int(x) for x in input().split()]
matrix = []
visited = []
for i in range(n):
	matrix.append([int(x) for x in input().split()])
	visited.append([0] * m)
o = [(0, 0), (0, 1), (1, 0), (1, 1)]
path = []
flag = True
for i in range(n - 1):
	for j in range(m - 1):
		if matrix[i][j] == 1:
			if sum([matrix[i + x][j + y] for (x, y) in o]) == 4:
				path.append((i, j))
				for (x, y) in o:
					visited[i + x][j + y] = 1
			elif visited[i][j] == 1:
				pass
			else:
				flag = False
				break
	if not flag:
		break
for i in range(n):
	if matrix[i][m - 1] == 1 and visited[i][m - 1] == 0:
		flag = False
for j in range(m):
	if matrix[n - 1][j] == 1 and visited[n - 1][j] == 0:
		flag = False
if flag:
	print(len(path))
	for (x, y) in path:
		print('%d %d' % (x + 1, y + 1))
else:
	print(-1)


(n, m) = map(int, input().split())
A = []
B = []
C = []
for i in range(n):
	A.append(list(map(int, input().split())))
	B.append([0] * m)
for i in range(n - 1):
	for j in range(m - 1):
		if A[i][j] == 1 and A[i][j + 1] == 1 and (A[i + 1][j] == 1) and (A[i + 1][j + 1] == 1):
			B[i][j] = 1
			B[i][j + 1] = 1
			B[i + 1][j] = 1
			B[i + 1][j + 1] = 1
			C.append((i + 1, j + 1))
f = True
for i in range(n):
	for j in range(m):
		if A[i][j] != B[i][j]:
			f = False
if f:
	print(len(C))
	for c in C:
		print(*c)
else:
	print(-1)


(n, m) = map(int, input().split())
A = []
for i in range(n):
	A.append(list(map(int, input().split())))
B = [0] * n
for i in range(n):
	B[i] = [0] * m
ans = 0
for i in range(n - 1):
	for j in range(m - 1):
		if A[i][j] + A[i + 1][j] + A[i][j + 1] + A[i + 1][j + 1] == 4:
			B[i][j] = B[i + 1][j] = B[i][j + 1] = B[i + 1][j + 1] = 1
			ans += 1
flag = True
for i in range(n):
	for j in range(m):
		if A[i][j] ^ B[i][j]:
			flag = False
			break
if flag:
	print(ans)
	for i in range(n - 1):
		for j in range(m - 1):
			if B[i][j] + B[i + 1][j] + B[i][j + 1] + B[i + 1][j + 1] == 4:
				print(i + 1, j + 1)
else:
	print(-1)


I = lambda : map(int, input().split())
(n, m) = I()
A = [list(I()) for _ in range(n)]
B = [[0] * m for _ in range(n)]
P = []
for i in range(n - 1):
	for j in range(m - 1):
		if A[i][j] * A[i][j + 1] * A[i + 1][j] * A[i + 1][j + 1] and B[i][j] * B[i][j + 1] * B[i + 1][j] * B[i + 1][j + 1] < 1:
			P.append((i + 1, j + 1))
			B[i][j] = B[i][j + 1] = B[i + 1][j] = B[i + 1][j + 1] = 1
if A == B:
	print(len(P))
	for p in P:
		print(*p)
else:
	print(-1)


(n, m) = map(int, input().split())
matrix = [[0 for j in range(m)] for i in range(n)]
original = []
for i in range(n):
	row = list(map(int, input().split()))
	original.append(row)
ops = []
for i in range(n - 1):
	for j in range(m - 1):
		if original[i][j] and original[i + 1][j] and original[i][j + 1] and original[i + 1][j + 1]:
			matrix[i][j] = matrix[i + 1][j] = matrix[i][j + 1] = matrix[i + 1][j + 1] = 1
			ops.append((i, j))
if original == matrix:
	print(len(ops))
	for x in ops:
		print(x[0] + 1, x[1] + 1)
else:
	print(-1)


def foo(a, rez, n, m):
	c = 0
	for i in range(n - 1):
		for j in range(m - 1):
			if a[i][j] == 1:
				if (a[i][j + 1] == 0 or a[i + 1][j] == 0) or a[i + 1][j + 1] == 0:
					return -1
				a[i][j + 1] = 2
				a[i + 1][j] = 2
				a[i + 1][j + 1] = 2
				c += 1
				rez.append((i + 1, j + 1))
			if a[i][j] == 2:
				if (a[i][j + 1] > 0 and a[i + 1][j] > 0) and a[i + 1][j + 1] > 0:
					a[i][j + 1] = 2
					a[i + 1][j] = 2
					a[i + 1][j + 1] = 2
					c += 1
					rez.append((i + 1, j + 1))
	for j in range(m):
		if a[n - 1][j] == 1:
			return -1
	for i in range(n):
		if a[i][m - 1] == 1:
			return -1
	return c
(n, m) = map(int, input().split())
a = [None] * n
rez = []
for i in range(n):
	a[i] = [int(s) for s in input().split()]
c_o = foo(a, rez, n, m)
print(c_o)
if c_o > -1:
	for el in rez:
		print(el[0], el[1])


(n, m) = map(int, input().split())
l = []
for i in range(n):
	l.append(list(map(int, input().split())))
b = [[0] * m for i in range(n)]
ans = []
for i in range(n - 1):
	for j in range(m - 1):
		if l[i][j] * l[i + 1][j] * l[i][j + 1] * l[i + 1][j + 1] > 0:
			l[i][j] = 2
			l[i][j + 1] = 2
			l[i + 1][j] = 2
			l[i + 1][j + 1] = 2
			ans.append([i, j])
cnt = 0
for i in range(n):
	for j in range(m):
		if l[i][j] == 1:
			cnt += 1
if cnt != 0:
	print(-1)
else:
	print(len(ans))
	for x in ans:
		print(x[0] + 1, x[1] + 1)


import sys
from typing import List

def findValue(n, m):
	a = []
	b = []
	ans = []
	for i in range(n):
		a.append(list(map(int, input().split())))
	b = [[0] * m for _ in range(n)]
	for i in range(n - 1):
		for j in range(m - 1):
			if a[i][j] == a[i + 1][j] == a[i][j + 1] == a[i + 1][j + 1] == 1:
				ans.append([i + 1, j + 1])
				for x in range(2):
					for y in range(2):
						b[i + x][j + y] = 1
	if a != b:
		print(-1)
	else:
		print(len(ans))
		for i in ans:
			print(i[0], i[1])

def main():
	(n, m) = map(int, input().strip().split())
	findValue(n, m)
main()


(N, M) = [int(i) for i in input().split()]
(N, M) = (M, N)
A = [[int(i) for i in input().split()] for j in range(M)]
A_cov = [[0 for i in range(N)] for j in range(M)]
pseq = []
for i in range(M - 1):
	for j in range(N - 1):
		if A[i][j] & A[i + 1][j] & A[i][j + 1] & A[i + 1][j + 1] == 1:
			pseq.append(str(i + 1) + ' ' + str(j + 1))
			A_cov[i][j] = 1
			A_cov[i + 1][j] = 1
			A_cov[i][j + 1] = 1
			A_cov[i + 1][j + 1] = 1
if A == A_cov:
	print(len(pseq))
	if pseq:
		print(*pseq, sep='\n')
else:
	print(-1)


(n, m) = map(int, input().split())
a = []
for j in range(n):
	a.append(list(map(int, input().split())))
an = []
f = 0
for j in range(n):
	for k in range(m):
		if a[j][k] == 1:
			if j + 1 < n and k + 1 < m and (a[j + 1][k + 1] == 1) and (a[j][k + 1] == 1) and (a[j + 1][k] == 1):
				an.append((j + 1, k + 1))
			elif j - 1 >= 0 and k - 1 >= 0 and (a[j - 1][k - 1] == 1) and (a[j][k - 1] == 1) and (a[j - 1][k] == 1):
				continue
			elif j - 1 >= 0 and k + 1 < m and (a[j - 1][k + 1] == 1) and (a[j - 1][k] == 1) and (a[j][k + 1] == 1):
				continue
			elif j + 1 < n and k - 1 >= 0 and (a[j + 1][k - 1] == 1) and (a[j + 1][k] == 1) and (a[j][k - 1] == 1):
				continue
			else:
				f = 1
				break
if f == 1:
	print(-1)
else:
	print(len(an))
	for (u, v) in an:
		print(u, v)


def do():
	(n, m) = map(int, input().split(' '))
	grid = []
	for i in range(n):
		grid.append([int(c) for c in input().split(' ')])
	blank = [[0] * m for _ in range(n)]
	res = []
	for i in range(n - 1):
		for j in range(m - 1):
			if all([grid[i][j], grid[i + 1][j], grid[i][j + 1], grid[i + 1][j + 1]]):
				res.append([i, j])
	for (x, y) in res:
		blank[x][y] = 1
		blank[x + 1][y] = 1
		blank[x][y + 1] = 1
		blank[x + 1][y + 1] = 1
	equal = True
	for i in range(n):
		if blank[i] != grid[i]:
			equal = False
			break
	if not equal:
		print(-1)
		return 0
	if not res:
		print(0)
		return 0
	print(len(res))
	for (x, y) in res:
		print(str(x + 1) + ' ' + str(y + 1))
	return 0
do()


(n, m) = list(map(int, input().split()))
inputMatrix = []
for index in range(n):
	inputMatrix.append(list(map(int, input().split())))
outputMatrix = [[0 for col in range(m)] for row in range(n)]
ones = [[1 for col in range(2)] for row in range(2)]
changes = 'placeholder'
for row in range(n - 1):
	for col in range(m - 1):
		subMat = [[inputMatrix[i][j] for i in range(row, row + 2)] for j in range(col, col + 2)]
		if subMat == ones:
			outputMatrix[row][col] = 1
			outputMatrix[row][col + 1] = 1
			outputMatrix[row + 1][col] = 1
			outputMatrix[row + 1][col + 1] = 1
			changes = changes + str(row + 1) + ' ' + str(col + 1) + '\n'
zeros = [[0 for col in range(m)] for row in range(n)]
newLineCount = str(changes.count('\n'))
changes = changes.replace('placeholder', newLineCount + '\n')
if outputMatrix == inputMatrix:
	print(changes[:-1])
else:
	print(-1)


(n, m) = [int(i) for i in input().split()]
matrix = list()
for i in range(n):
	a = [int(x) for x in input().split()]
	matrix.append(a)
ones = 0
for i in range(n):
	for j in range(m):
		if matrix[i][j] == 1:
			ones += 1
(count, lst, s) = (0, list(), set())
for i in range(n - 1):
	for j in range(m - 1):
		if matrix[i][j] == 1 and matrix[i + 1][j] == 1 and (matrix[i][j + 1] == 1) and (matrix[i + 1][j + 1] == 1):
			count += 1
			lst.append([i + 1, j + 1])
			s.add((i, j))
			s.add((i + 1, j))
			s.add((i, j + 1))
			s.add((i + 1, j + 1))
if ones == len(s):
	print(count)
	for elem in lst:
		print(elem[0], elem[1])
else:
	print(-1)


chgs = 0
(n, m) = map(int, input().split())
a = [[0 for j in range(m)] for i in range(n)]
b = [[0 for j in range(m)] for i in range(n)]
for i in range(n):
	a[i] = list(map(int, input().split()))
for i in range(1, n):
	for j in range(1, m):
		if a[i][j] == 1 & a[i][j - 1] == 1 & a[i - 1][j] == 1 & a[i - 1][j - 1] == 1:
			b[i][j] = 1
			chgs = chgs + 1
flag_found_bad = 0
for i in range(n):
	for j in range(m):
		cell_is_1 = 0
		if i > 0 and j > 0:
			if b[i][j] == 1:
				cell_is_1 = 1
		if i > 0 and j + 1 < m:
			if b[i][j + 1] == 1:
				cell_is_1 = 1
		if i + 1 < n and j > 0:
			if b[i + 1][j] == 1:
				cell_is_1 = 1
		if i + 1 < n and j + 1 < m:
			if b[i + 1][j + 1] == 1:
				cell_is_1 = 1
		if a[i][j] != cell_is_1:
			flag_found_bad = 1
if flag_found_bad == 1:
	print(-1)
else:
	print(chgs)
	for i in range(1, n):
		for j in range(1, m):
			if b[i][j] == 1:
				print(i, j)


def print_operations(map_, sum_):
	if sum_ == 0:
		print(0)
		return
	ret = []
	map_2 = [map_[_][:] for _ in range(len(map_))]
	for i in range(1, n):
		for j in range(1, m):
			if map_[i - 1][j - 1] & map_[i][j] & map_[i][j - 1] & map_[i - 1][j]:
				map_2[i - 1][j - 1] = 0
				map_2[i][j] = 0
				map_2[i][j - 1] = 0
				map_2[i - 1][j] = 0
				ret += [[i, j]]
		if sum(map_2[i - 1]):
			print(-1)
			return
	if sum(map_2[-1]):
		print(-1)
		return
	print(len(ret))
	for (i, j) in ret:
		print(i, j)
	return
(n, m) = map(int, input().split())
map_ = []
sum_ = 0
for i in range(n):
	list_ = list(map(int, input().split()))
	map_ += [list_]
	sum_ += sum(list_)
print_operations(map_, sum_)


(r, c) = map(int, input().split())
mat = [list(map(int, input().split())) for i in range(r)]
dup = [[0 for j in range(c)] for i in range(r)]
odp = []
for i in range(r - 1):
	for j in range(c - 1):
		if mat[i][j] == 1 and mat[i + 1][j] == 1 and (mat[i + 1][j + 1] == 1) and (mat[i][j + 1] == 1):
			odp.append([i, j])
			dup[i][j] = 1
			dup[i][j + 1] = 1
			dup[i + 1][j] = 1
			dup[i + 1][j + 1] = 1
if mat == dup:
	print(len(odp))
	for i in odp:
		print(i[0] + 1, i[1] + 1)
else:
	print(-1)


otv = []

def right_down(i, j):
	k1 = matr[i + 1][j]
	k2 = matr[i][j + 1]
	k3 = matr[i + 1][j + 1]
	if int(k1) and int(k2) and int(k3):
		return True
	else:
		return False

def right_up(i, j):
	k1 = matr[i - 1][j]
	k2 = matr[i][j + 1]
	k3 = matr[i - 1][j + 1]
	if int(k1) and int(k2) and int(k3):
		return True
	else:
		return False

def left_down(i, j):
	k1 = matr[i + 1][j]
	k2 = matr[i][j - 1]
	k3 = matr[i + 1][j - 1]
	if int(k1) and int(k2) and int(k3):
		return True
	else:
		return False

def left_up(i, j):
	k1 = matr[i - 1][j]
	k2 = matr[i][j - 1]
	k3 = matr[i - 1][j - 1]
	if int(k1) and int(k2) and int(k3):
		return True
	else:
		return False
(n, m) = map(int, input().split())
matr = []
ans = True
for i in range(0, n):
	h = input().split()
	matr.append(h)
for i in range(0, len(matr)):
	for j in range(0, len(matr[i])):
		if matr[i][j] == '1':
			if j == len(matr[i]) - 1 and i == len(matr) - 1:
				h1 = left_up(i, j)
				if not h1:
					ans = False
			elif i == 0 and j == 0:
				h1 = right_down(i, j)
				if not h1:
					ans = False
			elif j == len(matr[i]) - 1 and i == 0:
				h1 = left_down(i, j)
				if not h1:
					ans = False
			elif j == 0 and i == len(matr) - 1:
				h1 = right_up(i, j)
				if not h1:
					ans = False
			elif i == 0:
				h1 = left_down(i, j)
				h2 = right_down(i, j)
				if not (h1 or h2):
					ans = False
			elif j == 0:
				h1 = right_up(i, j)
				h2 = right_down(i, j)
				if not (h1 or h2):
					ans = False
			elif i == len(matr) - 1:
				h1 = right_up(i, j)
				h2 = left_up(i, j)
				if not (h1 or h2):
					ans = False
			elif j == len(matr[i]) - 1:
				h1 = left_up(i, j)
				h2 = left_down(i, j)
				if not (h1 or h2):
					ans = False
			else:
				h1 = right_up(i, j)
				h2 = left_up(i, j)
				h3 = left_down(i, j)
				h4 = right_down(i, j)
				if not (h1 or h2 or h3 or h4):
					ans = False
if ans and m != 1 and (n != 1):
	for i in range(0, len(matr) - 1):
		for j in range(0, len(matr[i]) - 1):
			if matr[i][j] == '1':
				if matr[i + 1][j + 1] == '1':
					if matr[i + 1][j] == '1':
						if matr[i][j + 1] == '1':
							x = str(i + 1) + ' ' + str(j + 1)
							otv.append(x)
	print(len(otv))
	print('\n'.join(otv))
else:
	print(-1)


(n, m) = map(int, input().split())
L = []
pos = []
for i in range(0, n):
	s = [int(x) for x in input().split()]
	p = [0] * m
	pos.append(p)
	L.append(s)
flag = 0
for i in range(0, len(L)):
	for j in range(0, len(L[i])):
		if L[i][j] == 1:
			flag = 1
ans = []
for i in range(0, len(L) - 1):
	for j in range(0, len(L[i]) - 1):
		if L[i][j] == 1 and L[i + 1][j] == 1 and (L[i][j + 1] == 1) and (L[i + 1][j + 1] == 1):
			ans.append((i + 1, j + 1))
			pos[i][j] = 1
			pos[i + 1][j] = 1
			pos[i][j + 1] = 1
			pos[i + 1][j + 1] = 1
if L != pos:
	print(-1)
else:
	print(len(ans))
	for i in range(0, len(ans)):
		print(ans[i][0], ans[i][1])


(n, m) = [int(x) for x in input().split(' ')]
B = []
A = []
for _ in range(n):
	temp = [int(x) for x in input().split(' ')]
	A.append([0] * m)
	B.append(temp)
ans = []
for x in range(n - 1):
	for y in range(m - 1):
		if B[x][y] and B[x + 1][y] and B[x][y + 1] and B[x + 1][y + 1]:
			ans.append((x, y))
			A[x][y] = 1
			A[x][y + 1] = 1
			A[x + 1][y] = 1
			A[x + 1][y + 1] = 1
if A == B:
	print(len(ans))
	for (a, b) in ans:
		print(a + 1, b + 1)
else:
	print('-1')


def make_equal_matrix(n, m, a, cmd):
	b = [['0'] * m for _ in range(n)]
	for i in range(n - 1):
		for j in range(m - 1):
			summ = sum(map(int, (a[i][j], a[i + 1][j], a[i][j + 1], a[i + 1][j + 1])))
			if summ == 4:
				cmd.append((str(i + 1), str(j + 1)))
				(b[i][j], b[i + 1][j], b[i][j + 1], b[i + 1][j + 1]) = ('1', '1', '1', '1')
	return a == b
(n, m) = map(int, input().split())
a = [input().split() for _ in range(n)]
cmd = []
if not make_equal_matrix(n, m, a, cmd):
	print(-1)
else:
	print(len(cmd))
	print(*[p[0] + ' ' + p[1] for p in cmd], sep='\n')


(n, m) = [int(x) for x in input().split()]
mat_a = []
ops = []
success = True
for i in range(n):
	i += 1
	mat_a.append([int(x) for x in input().split()])
mat_b = [[0 for _ in range(m)] for _ in range(n)]
for i in range(n - 1):
	for j in range(m - 1):
		if mat_a[i][j] == 1 and mat_a[i + 1][j] == 1 and (mat_a[i][j + 1] == 1) and (mat_a[i + 1][j + 1] == 1):
			mat_b[i][j] = 1
			mat_b[i + 1][j] = 1
			mat_b[i][j + 1] = 1
			mat_b[i + 1][j + 1] = 1
			ops.append((i + 1, j + 1))
for i in range(n):
	for j in range(m):
		if mat_a[i][j] != mat_b[i][j]:
			success = False
			break
if success:
	print(len(ops))
	for (x, y) in ops:
		print(x, y, sep=' ')
else:
	print(-1)


(n, m) = map(int, input().split())
l = []
ans = []
for _ in range(n):
	l.append(list(map(int, input().split())))
	ans.append([0] * m)
f = []
for i in range(n - 1):
	for j in range(m - 1):
		if l[i][j] == 1 and l[i][j + 1] == 1 and (l[i + 1][j] == 1) and (l[i + 1][j + 1] == 1):
			ans[i][j] = 1
			ans[i][j + 1] = 1
			ans[i + 1][j] = 1
			ans[i + 1][j + 1] = 1
			f.append([i + 1, j + 1])
tag = True
for i in range(n):
	for j in range(m):
		if l[i][j] != ans[i][j]:
			tag = False
			break
if tag:
	print(len(f))
	for i in f:
		print(*i)
else:
	print(-1)


(n, m) = map(int, input().split())
a = []
x = []
for i in range(0, n):
	x = list(map(int, input().split()))
	a.append(x)
b = []
s = []
c = 0
for i in range(0, n):
	p = []
	for j in range(0, m):
		p.append(0)
	b.append(p)
print()
for i in range(0, n - 1):
	for j in range(0, m - 1):
		if a[i][j] == 1 and a[i + 1][j] == 1 and (a[i][j + 1] == 1) and (a[i + 1][j + 1] == 1):
			b[i][j] = 1
			b[i + 1][j] = 1
			b[i][j + 1] = 1
			b[i + 1][j + 1] = 1
			c += 1
			t1 = i + 1
			t2 = j + 1
			t = str(t1) + ' ' + str(t2)
			s.append(t)
f = 0
for i in range(0, n):
	for j in range(0, m):
		if a[i][j] != b[i][j]:
			f = 1
			break
if f == 0:
	print(c)
	for i in range(0, len(s)):
		print(s[i])
else:
	print(-1)


mod = 1000000007
ii = lambda : int(input())
si = lambda : input()
dgl = lambda : list(map(int, input()))
f = lambda : map(int, input().split())
il = lambda : list(map(int, input().split()))
ls = lambda : list(input())
(n, m) = f()
l = [il() for i in range(n)]
lb = [[0 for i in range(m)] for j in range(n)]
lop = []
for i in range(n - 1):
	for j in range(m - 1):
		if l[i][j] == l[i + 1][j] == l[i][j + 1] == l[i + 1][j + 1] == 1:
			(lb[i][j], lb[i + 1][j], lb[i][j + 1], lb[i + 1][j + 1]) = (1, 1, 1, 1)
			lop.append([i + 1, j + 1])
for i in range(n):
	for j in range(m):
		if l[i][j] != lb[i][j]:
			print(-1)
			exit(0)
print(len(lop))
for i in lop:
	print(*i)


def check(matrix, row, column):
	matrixB = [[0 for x in range(m)] for y in range(n)]
	count = 0
	result = ''
	for x in range(row - 1):
		for y in range(column - 1):
			if matrix[x][y] == 1 and matrix[x][y + 1] == 1 and (matrix[x + 1][y] == 1) and (matrix[x + 1][y + 1] == 1):
				count += 1
				result += str(x + 1) + ' ' + str(y + 1) + '\n'
				matrixB[x][y] = matrixB[x][y + 1] = matrixB[x + 1][y] = matrixB[x + 1][y + 1] = 1
	if matrix == matrixB:
		return str(count) + '\n' + result
	else:
		return -1
(n, m) = map(int, input().split())
matrix = [[0 for x in range(m)] for y in range(n)]
for x in range(n):
	row = input().split()
	for y in range(m):
		matrix[x][y] = int(row[y])
print(check(matrix, n, m))


(n, m) = [int(x) for x in input().split()]
a = []
for i in range(n):
	b = [int(x) for x in input().split()]
	a.append(b)
c = [[0 for i in range(m)] for j in range(n)]
s = []
for i in range(n - 1):
	for j in range(m - 1):
		if a[i][j] == 1 and a[i + 1][j] == 1 and (a[i][j + 1] == 1) and (a[i + 1][j + 1] == 1):
			c[i][j] = 1
			c[i + 1][j] = 1
			c[i][j + 1] = 1
			c[i + 1][j + 1] = 1
			s.append([i + 1, j + 1])
flag = True
for i in range(n):
	for j in range(m):
		if a[i][j] != c[i][j]:
			flag = False
	if flag == False:
		print(-1)
		break
else:
	print(len(s))
	for i in s:
		print(i[0], i[1])


dim = input().split()
n = int(dim[0])
m = int(dim[1])
A = []
for i in range(0, n):
	A.append(list(map(int, input().split())))
B = [[0 for i in range(m)] for j in range(n)]

def poscheck(A, n, m):
	for i in range(0, n):
		for j in range(0, m):
			if A[i][j] == 1:
				num = 0
				coords = [(i - 1, j - 1), (i, j - 1), (i - 1, j), (i + 1, j), (i, j + 1), (i + 2, j), (i, j + 2), (i + 2, j + 2)]
				for k in range(0, 8):
					try:
						if A[coords[k][0]][coords[k][1]] == 1:
							num += 1
					except:
						pass
				if num < 3:
					return False
	return True
if A == B:
	print(0)
else:
	instr = []
	for i in range(0, n):
		for j in range(0, m):
			if A[i][j] == 1:
				num = 0
				coords = [(i + 1, j), (i, j + 1), (i + 1, j + 1)]
				for k in range(0, 3):
					try:
						if A[coords[k][0]][coords[k][1]] == 1:
							num += 1
					except:
						pass
				if num == 3:
					instr.append([i + 1, j + 1])
	for coord in instr:
		ccoord = coord.copy()
		ccoord[0] -= 1
		ccoord[1] -= 1
		B[ccoord[0]][ccoord[1]] = 1
		B[ccoord[0]][ccoord[1] + 1] = 1
		B[ccoord[0] + 1][ccoord[1]] = 1
		B[ccoord[0] + 1][ccoord[1] + 1] = 1
	if A == B:
		print(len(instr))
		for coord in instr:
			print(coord[0], coord[1])
	else:
		print(-1)


import os
import heapq
import sys, threading
import math
import bisect
import operator
from collections import defaultdict
sys.setrecursionlimit(10 ** 5)
from io import BytesIO, IOBase

def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a % b)

def power(x, p, m):
	res = 1
	while p:
		if p & 1:
			res = res * x % m
		x = x * x % m
		p >>= 1
	return res

def inar():
	return [int(k) for k in input().split()]

def lcm(num1, num2):
	return num1 * num2 // gcd(num1, num2)

def main():
	t = 1
	for _ in range(t):
		(n, m) = inar()
		a = []
		ans = []
		for i in range(n):
			arr = inar()
			a.append(arr)
		b = [[0 for j in range(m)] for i in range(n)]
		for i in range(n - 1):
			for j in range(m - 1):
				one = 0
				for r in range(2):
					for c in range(2):
						if a[i + r][j + c] == 1:
							one += 1
				if one == 4:
					for r in range(2):
						for c in range(2):
							b[i + r][j + c] = 1
					ans.append([i + 1, j + 1])
		check = True
		for i in range(n):
			for j in range(m):
				if a[i][j] != b[i][j]:
					check = False
					break
		if check:
			print(len(ans))
			for i in range(len(ans)):
				print(*ans[i])
		else:
			print(-1)
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())
a = [list(map(int, input().split())) for _ in range(n)]
b = [[0] * m for i in range(n)]
if a == b:
	exit(print(0))
operations = []
for i in range(n - 1):
	for j in range(m - 1):
		if a[i][j] and a[min(n - 1, i + 1)][j] and a[i][min(m - 1, j + 1)] and a[min(n - 1, i + 1)][min(m - 1, j + 1)]:
			operations.append([i + 1, j + 1])
			b[i][j] = 1
			b[min(n - 1, i + 1)][j] = 1
			b[i][min(m - 1, j + 1)] = 1
			b[min(n - 1, i + 1)][min(m - 1, j + 1)] = 1
if a == b:
	print(len(operations))
	for op in operations:
		print(*op)
else:
	print(-1)


(n, m) = map(int, input().split())
a = [list(map(int, input().split())) for i in range(n)]
ans = []
z = 0
for i in range(n - 1):
	for j in range(m - 1):
		if a[i][j] * a[i][j + 1] * a[i + 1][j + 1] * a[i + 1][j] > 0:
			(a[i][j], a[i][j + 1], a[i + 1][j + 1], a[i + 1][j]) = (2, 2, 2, 2)
			ans.append([i + 1, j + 1])
			z += 1
ok = True
for i in range(n):
	if ok:
		for j in range(m):
			if a[i][j] == 1:
				ok = False
				print(-1)
				break
if ok:
	print(z)
	for k in ans:
		print(k[0], k[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')
from math import gcd, ceil

def pre(s):
	n = len(s)
	pi = [0] * n
	for i in range(1, n):
		j = pi[i - 1]
		while j and s[i] != s[j]:
			j = pi[j - 1]
		if s[i] == s[j]:
			j += 1
		pi[i] = j
	return pi

def prod(a):
	ans = 1
	for each in a:
		ans = ans * each
	return ans

def lcm(a, b):
	return a * b // gcd(a, b)

def binary(x, length=16):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y
for _ in range(int(input()) if not True else 1):
	(n, m) = map(int, input().split())
	a = []
	for __ in range(n):
		a += [list(map(int, input().split()))]
	marked = [[False] * m for __ in range(n)]
	ops = []
	pos = True
	for i in range(n - 1):
		for j in range(m - 1):
			if a[i][j] == a[i][j + 1] == a[i + 1][j] == a[i + 1][j + 1] == 1:
				ops += [[i + 1, j + 1]]
				marked[i][j] = marked[i][j + 1] = marked[i + 1][j] = marked[i + 1][j + 1] = True
			elif a[i][j] == 1 and (not marked[i][j]):
				pos = False
				break
	for i in range(n):
		for j in range(m):
			if a[i][j] == 1 and (not marked[i][j]):
				pos = False
				break
		if not pos:
			break
	if not pos:
		print(-1)
		continue
	print(len(ops))
	for i in ops:
		print(*i)


(n, m) = [int(ele) for ele in input().split()]
A = []
for i in range(n):
	A.append([])
	A[-1] = [int(ele) for ele in input().split()]
pos = []
for i in range(n - 1):
	for j in range(m - 1):
		if A[i][j] == 1 and A[i][j + 1] == 1 and (A[i + 1][j] == 1) and (A[i + 1][j + 1] == 1):
			pos.append([i, j])
B = []
for i in range(n):
	B.append([])
	for j in range(m):
		B[-1].append(0)
if B == A:
	print(0)
else:
	flag = 0
	sol = []
	k = 0
	for ele in pos:
		B[ele[0]][ele[1]] = 1
		B[ele[0] + 1][ele[1]] = 1
		B[ele[0]][ele[1] + 1] = 1
		B[ele[0] + 1][ele[1] + 1] = 1
		k += 1
		sol.append([])
		sol[-1] = [ele[0], ele[1]]
		if B == A:
			flag = 1
			break
	if flag == 1:
		print(k)
		for ele in sol:
			print(ele[0] + 1, ele[1] + 1)
	else:
		print(-1)


def mp():
	return map(int, input().split())

def f(i, j):
	return a[i][j] == a[i + 1][j] == a[i][j + 1] == a[i + 1][j + 1] == 1
(n, m) = mp()
a = [list(mp()) for i in range(n)]
b = [[0] * m for i in range(n)]
ans = []
for i in range(n - 1):
	for j in range(m - 1):
		if f(i, j):
			ans.append((i + 1, j + 1))
			b[i][j] = 1
			b[i][j + 1] = 1
			b[i + 1][j] = 1
			b[i + 1][j + 1] = 1
fail = False
for i in range(n):
	for j in range(m):
		if a[i][j] != b[i][j]:
			fail = True
if fail:
	print(-1)
else:
	print(len(ans))
	for i in ans:
		print(*i)


import sys
from collections import defaultdict

def main():
	(n, m) = map(int, input().split())
	A = [[0] * m for _ in range(n)]
	B = [[0] * m for _ in range(n)]
	res = []
	for i in range(n):
		A[i] = list(map(int, input().split()))
	for i in range(n - 1):
		for j in range(m - 1):
			if A[i][j] == 1 and A[i + 1][j] == 1 and (A[i][j + 1] == 1) and (A[i + 1][j + 1] == 1):
				res.append((i + 1, j + 1))
				B[i][j] = 1
				B[i + 1][j] = 1
				B[i][j + 1] = 1
				B[i + 1][j + 1] = 1
	ok = True
	for i in range(n):
		for j in range(m):
			if A[i][j] != B[i][j]:
				ok = False
				break
			if not ok:
				break
	if not ok:
		print(-1)
	else:
		print(len(res))
		for x in res:
			print(*x)
main()


rd = lambda : [int(x) for x in input().split()]
(n, m) = rd()
A = [[0] for _ in range(n)]
B = [[0 for _ in range(m)] for __ in range(n)]
for i in range(n):
	A[i] = rd()
ans = []
for i in range(n - 1):
	for j in range(m - 1):
		if A[i][j] and A[i][j + 1] and A[i + 1][j] and A[i + 1][j + 1]:
			ans += [(i + 1, j + 1)]
			B[i][j] = B[i][j + 1] = B[i + 1][j] = B[i + 1][j + 1] = 1
if A != B:
	print(-1)
else:
	print(len(ans))
	for (i, j) in ans:
		print(i, j)


(n, m) = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]
b = [i[:] for i in a]
c = []
for i in range(n - 1):
	for j in range(m - 1):
		if a[i][j] == 1 and a[i][j + 1] == 1 and (a[i + 1][j] == 1) and (a[i + 1][j + 1] == 1):
			b[i][j] = 2
			b[i][j + 1] = 2
			b[i + 1][j] = 2
			b[i + 1][j + 1] = 2
			c.append((i + 1, j + 1))
for i in b:
	if 1 in i:
		print(-1)
		break
else:
	print(len(c))
	for i in c:
		print(*i)


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())
matr = []
for s in range(n):
	v0 = list(map(int, input().split()))
	matr.append(v0)
ans = []
broke = False
for s in range(n):
	for b in range(m):
		if matr[s][b] == 1:
			a1 = 0
			if s > 0 and b > 0:
				if matr[s - 1][b] == 1 and matr[s][b - 1] == 1 and (matr[s - 1][b - 1] == 1):
					a1 += 1
			if s > 0 and b < m - 1:
				if matr[s - 1][b] == 1 and matr[s][b + 1] == 1 and (matr[s - 1][b + 1] == 1):
					a1 += 1
			if s < n - 1 and b > 0:
				if matr[s + 1][b] == 1 and matr[s][b - 1] == 1 and (matr[s + 1][b - 1] == 1):
					a1 += 1
			if s < n - 1 and b < m - 1:
				if matr[s + 1][b] == 1 and matr[s][b + 1] == 1 and (matr[s + 1][b + 1] == 1):
					a1 += 1
					ans.append((s + 1, b + 1))
			if a1 == 0:
				broke = True
				break
	if broke == True:
		break
if broke == False:
	print(len(ans))
	for s in range(len(ans)):
		print(*ans[s])
else:
	print(-1)


def are_all_zeros(a):
	for i in range(len(a)):
		for j in range(len(a[0])):
			if a[i][j] == 1:
				return -1
	return 1

def main():
	(n, m) = map(int, input().split())
	a = []
	i = 0
	while i < n:
		a.append(list(map(int, input().split(' '))))
		i += 1
	steps = 0
	i = 0
	ans = []
	for i in range(n - 1):
		for j in range(m - 1):
			if a[i][j] * a[i][j + 1] * a[i + 1][j] * a[i + 1][j + 1] > 0:
				steps += 1
				a[i][j] = 2
				a[i + 1][j] = 2
				a[i][j + 1] = 2
				a[i + 1][j + 1] = 2
				ans.append([i + 1, j + 1])
	result = are_all_zeros(a)
	if result == -1:
		print('-1')
	else:
		print(steps)
		for i in ans:
			print(str(i[0]) + ' ' + str(i[1]))
main()


from copy import deepcopy
(m, n) = map(int, input().split())
a = list()
for i in range(m):
	a.append(list(map(int, input().split())))
b = list()
for i in range(m):
	b.append(list([0] * n))
answer = list()
for i in range(m - 1):
	for j in range(n - 1):
		if a[i][j] and a[i + 1][j] and a[i][j + 1] and a[i + 1][j + 1]:
			answer.append([i, j])
			b[i][j] = 1
			b[i + 1][j] = 1
			b[i][j + 1] = 1
			b[i + 1][j + 1] = 1
for i in range(m):
	for j in range(n):
		if not a[i][j] == b[i][j]:
			print(-1)
			quit()
if len(answer) > 0:
	print(len(answer))
	for a in answer:
		print(' '.join(map(lambda x: str(x + 1), a)))
else:
	print(0)


(n, m) = [int(s) for s in input().split()]
a = []
for i in range(n):
	a.append([int(s) for s in input().split()])
b = [[0] * m for i in range(n)]
sites = []
for i in range(n - 1):
	for j in range(m - 1):
		if a[i][j] == a[i][j + 1] == a[i + 1][j] == a[i + 1][j + 1] == 1:
			b[i][j] = b[i][j + 1] = b[i + 1][j] = b[i + 1][j + 1] = 1
			sites.append([i + 1, j + 1])
if a == b:
	print(len(sites))
	for site in sites:
		print(site[0], site[1])
else:
	print(-1)


(n, m) = [int(x) for x in str(input()).split()]
a = [0] * n
b = [0] * n
for i in range(n):
	a[i] = [0] * m
	b[i] = [0] * m
for i in range(n):
	a[i] = [int(x) for x in str(input()).split()]
ans = []
for i in range(n - 1):
	for j in range(m - 1):
		if a[i][j] == 1 and a[i + 1][j] == 1 and (a[i][j + 1] == 1) and (a[i + 1][j + 1] == 1):
			if b[i][j] == 0 or b[i + 1][j] == 0 or b[i][j + 1] == 0 or (b[i + 1][j + 1] == 0):
				ans.append((i + 1, j + 1))
				b[i][j] = 1
				b[i + 1][j] = 1
				b[i][j + 1] = 1
				b[i + 1][j + 1] = 1
impos = False
for i in range(n):
	for j in range(m):
		if a[i][j] != b[i][j]:
			impos = True
			break
if impos:
	print(-1)
else:
	print(len(ans))
	for (a, b) in ans:
		print(a, b)


(n, m) = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(n)]
B = [[0] * m for _ in range(n)]
ans = []
for i in range(n - 1):
	for j in range(m - 1):
		if A[i][j] == 1 and A[i + 1][j] == 1 and (A[i][j + 1] == 1) and (A[i + 1][j + 1] == 1):
			B[i][j] = B[i + 1][j] = B[i][j + 1] = B[i + 1][j + 1] = 1
			ans.append((i, j))
solved = True
for i in range(n):
	for j in range(m):
		if A[i][j] != B[i][j]:
			solved = False
if solved:
	print(len(ans))
	for turn in ans:
		print(turn[0] + 1, turn[1] + 1)
else:
	print(-1)


(n, m) = list(map(int, input().split()))
matrix_a = list()
matrix_b = list()
for i in range(n):
	matrix_a.append(list(map(int, input().split())))
	matrix_b.append([0] * len(matrix_a[i]))
k = 0
transforms = list()

def transform_matrix_b(x, y):
	matrix_b[x][y] = 1
	matrix_b[x + 1][y] = 1
	matrix_b[x][y + 1] = 1
	matrix_b[x + 1][y + 1] = 1
	global k
	k += 1
	transforms.append((x + 1, y + 1))
for i in range(n - 1):
	for j in range(m - 1):
		if matrix_a[i][j] == 1 and matrix_a[i + 1][j] == 1 and (matrix_a[i][j + 1] == 1) and (matrix_a[i + 1][j + 1] == 1):
			transform_matrix_b(i, j)
if matrix_a == matrix_b:
	if matrix_b.count(0) == n * m:
		print(0)
	else:
		print(k)
		for i in range(k):
			print(*transforms[i])
else:
	print(-1)


(n, m) = map(int, input().split())
a = [[*map(int, input().split())] for _ in range(n)]
b = [[0] * m for _ in range(n)]
res = []
for x in range(n - 1):
	for y in range(m - 1):
		if a[x][y] + a[x + 1][y] + a[x][y + 1] + a[x + 1][y + 1] == 4:
			b[x][y] = b[x + 1][y] = b[x][y + 1] = b[x + 1][y + 1] = 1
			res.append((x, y))
ans = len(res)
for x in range(n):
	for y in range(m):
		if a[x][y] != b[x][y]:
			ans = -1
print(ans)
if ans > 0:
	for i in res:
		print(i[0] + 1, i[1] + 1)


(m, n) = input().split()
(m, n) = (int(m), int(n))
mat = []
m2 = m
while m2 != 0:
	line = input().split()
	line = [int(x) for x in line]
	mat.append(line)
	m2 -= 1
mat2 = []
for i in range(0, m):
	line = []
	for j in range(0, n):
		line.append(0)
	mat2.append(line)
res = []
for i in range(0, m):
	for j in range(0, n):
		if mat[i][j] == 1:
			try:
				logic = mat[i + 1][j] == 1 and mat[i][j + 1] == 1 and (mat[i + 1][j + 1] == 1)
			except:
				logic = False
			if logic is True:
				mat2[i][j] = 1
				mat2[i + 1][j] = 1
				mat2[i][j + 1] = 1
				mat2[i + 1][j + 1] = 1
				res.append([i + 1, j + 1])
if mat != mat2:
	print('-1')
else:
	print(len(res))
	for r in res:
		print(*r)


from sys import stdin, stdout
(n, m) = stdin.readline().strip().split(' ')
(n, m) = (int(n), int(m))
a = []
for i in range(n):
	a.append(list(map(int, stdin.readline().strip().split(' '))))
t1 = [[0 for i in range(m)] for i in range(n)]
ansarr = []

def pos(x, y):
	global a
	if x < n - 1 and y < m - 1:
		if a[x][y] == a[x + 1][y] == a[x + 1][y + 1] == a[x][y + 1] == 1:
			ansarr.append([x, y])
			return True
		else:
			return False
	else:
		return False

def fill(x, y):
	global t1
	t1[x][y] = 1
	t1[x][y + 1] = 1
	t1[x + 1][y] = 1
	t1[x + 1][y + 1] = 1
for i in range(n):
	for j in range(m):
		if a[i][j] == 1:
			if pos(i, j):
				fill(i, j)
if a == t1:
	stdout.write(str(len(ansarr)) + '\n')
	for i in ansarr:
		stdout.write(str(i[0] + 1) + ' ' + str(i[1] + 1) + '\n')
else:
	stdout.write(str(-1))


import sys
input = lambda : sys.stdin.readline().strip()
(n, m) = map(int, input().split())
A = []
for i in range(n):
	A.append(input().split())
B = []
for i in range(n):
	B.append(['0'] * m)
k = []
for i in range(n - 1):
	for j in range(m - 1):
		if A[i][j] == '1' and A[i + 1][j] == '1' and (A[i][j + 1] == '1') and (A[i + 1][j + 1] == '1'):
			k.append((i, j))
			B[i][j] = '1'
			B[i + 1][j] = '1'
			B[i][j + 1] = '1'
			B[i + 1][j + 1] = '1'
if A != B:
	print(-1)
else:
	print(len(k))
	for i in k:
		print(i[0] + 1, i[1] + 1)


(n, m) = map(int, input().split())
a = [[0 for k in range(m + 2)] for l in range(n + 2)]
b = [[0 for k in range(m + 2)] for l in range(n + 2)]
for k in range(n):
	s = list(map(int, input().split()))
	for l in range(m):
		a[k + 1][l + 1] = s[l]
ans = []
for k in range(1, n):
	for l in range(1, m):
		if a[k][l] == 1:
			if a[k + 1][l + 1] == 1 and a[k + 1][l] == 1 and (a[k][l + 1] == 1):
				b[k][l] = 1
				b[k + 1][l + 1] = 1
				b[k + 1][l] = 1
				b[k][l + 1] = 1
				ans.append([k, l])
for k in range(1, n + 1):
	for l in range(1, m + 1):
		if a[k][l] != b[k][l]:
			print(-1)
			exit(0)
if len(ans) == 0:
	print(0)
else:
	print(len(ans))
	for e in ans:
		print(*e)


import sys
(n, m) = tuple(map(int, input().split()))
A = []
for _ in range(n):
	A.append(list(map(int, input().split())))
B = []
for _ in range(n):
	B.append([0 for __ in range(m)])
q = []
for i in range(n - 1):
	for j in range(m - 1):
		if A[i][j] == 1 and A[i][j + 1] == 1 and (A[i + 1][j] == 1) and (A[i + 1][j + 1] == 1):
			B[i][j] = 1
			B[i][j + 1] = 1
			B[i + 1][j] = 1
			B[i + 1][j + 1] = 1
			q.append((i, j))
for i in range(n):
	for j in range(m):
		if A[i][j] != B[i][j]:
			print(-1)
			sys.exit(0)
print(len(q))
for (i, j) in q:
	print(i + 1, j + 1)


(n, m) = list(map(int, input().split()))
a = []
b = [[0 for j in range(m)] for i in range(n)]
for i in range(n):
	a.append(list(map(int, input().split())))
k = []
if a == b:
	print(0)
else:
	ct = 0
	for i in range(1, n):
		for j in range(1, m):
			if a[i][j] + a[i][j - 1] + a[i - 1][j] + a[i - 1][j - 1] == 4:
				b[i][j] = b[i][j - 1] = b[i - 1][j] = b[i - 1][j - 1] = 1
				ct += 1
				k.append([i, j])
	if ct == 0 or a != b:
		print(-1)
	else:
		print(ct)
	if a == b:
		for i in k:
			print(i[0], end=' ')
			print(i[1])


(n, m) = map(int, input().split())
grid = [list(map(int, input().split())) for _ in range(n)]
required = set()
solved = set()
for x in range(n):
	for y in range(m):
		if grid[x][y] == 1:
			required.add(x * m + y)
steps = []
for x in range(n - 1):
	for y in range(m - 1):
		if grid[x][y] != 1:
			continue
		if grid[x][y + 1] == 1 and grid[x + 1][y] == 1 and (grid[x + 1][y + 1] == 1):
			steps.append([x + 1, y + 1])
			solved.add(x * m + y)
			solved.add(x * m + y + 1)
			solved.add(x * m + y + m)
			solved.add(x * m + y + m + 1)
if solved != required:
	print(-1)
else:
	print(len(steps))
	for (a, b) in steps:
		print(a, b)


I0 = lambda : map(int, input().split())
I1 = lambda : int(input())
I2 = lambda : list(map(int, input().split()))
(n, m) = I0()
B = [[0] * m for i in range(n)]
A = list()
for i in range(n):
	A.append(I2())
res = list()
k = 0
for i in range(n - 1):
	for j in range(m - 1):
		if A[i][j] == A[i + 1][j] == A[i][j + 1] == A[i + 1][j + 1] == 1:
			k += 1
			res.append([i + 1, j + 1])
			(B[i][j], B[i + 1][j], B[i][j + 1], B[i + 1][j + 1]) = (1, 1, 1, 1)
for i in range(n):
	for j in range(m):
		if A[i][j] != B[i][j]:
			print(-1)
			exit()
print(k)
for i in range(k):
	print(*res[i])


(r, c) = list(map(int, input().split()))
a = [[0] * c for _ in range(r)]
ans = 0
l = list()
for i in range(r):
	a[i] = [int(j) for j in input().strip().split(' ')]
b = [[0] * c for _ in range(r)]
for i in range(0, r):
	for j in range(0, c):
		b[i][j] = 0
for i in range(0, r - 1):
	for j in range(0, c - 1):
		if a[i + 1][j] == 1 and a[i + 1][j + 1] == 1 and (a[i][j + 1] == 1) and (a[i][j] == 1):
			b[i + 1][j] = 1
			b[i][j + 1] = 1
			b[i][j] = 1
			b[i + 1][j + 1] = 1
			ans = ans + 1
			l.append((i + 1, j + 1))
if a == b:
	print(ans)
	for i in range(0, ans):
		print(l[i][0], l[i][1])
else:
	print(-1)


(n, m) = map(int, input().split())
matrix = [list(map(int, input().split())) for i in range(n)]
copy_matrix = [[0 for i in range(m)] for i in range(n)]
ans = []
for i in range(n):
	for j in range(m):
		try:
			a = matrix[i][j]
			b = matrix[i + 1][j]
			c = matrix[i][j + 1]
			d = matrix[i + 1][j + 1]
			if a & b & c & d:
				copy_matrix[i][j] = copy_matrix[i + 1][j] = copy_matrix[i][j + 1] = copy_matrix[i + 1][j + 1] = 1
				ans.append(str(i + 1) + ' ' + str(j + 1))
		except:
			pass
if matrix == copy_matrix:
	print(len(ans))
	print(*ans, sep='\n')
else:
	print(-1)


(n, m) = list(map(int, input().split()))
mat = []
for i in range(n):
	mat.append(list(map(int, input().split())))

def swappa(mt, x, y):
	for i in range(x, x + 2):
		mt[i][y:y + 2] = [1, 1]
	return mt

def check(mat, x, y):
	for i in range(x, x + 2):
		if 0 in mat[i][y:y + 2]:
			return False
	return True

def fullcheck(mat, mmat):
	for (x1, x2) in zip(mat, mmat):
		for (y1, y2) in zip(x1, x2):
			if y1 != y2:
				return False
	return True
mmat = [[0 for i in range(m)] for j in range(n)]
moves = []
for i in range(n - 1):
	for j in range(m - 1):
		if check(mat, i, j):
			moves.append((i + 1, j + 1))
			mmat = swappa(mmat, i, j)
if fullcheck(mat, mmat):
	print(len(moves))
	for (x, y) in moves:
		print(x, y)
else:
	print(-1)


(n, m) = map(int, input().split())
A = []
ones = set()
for i in range(n):
	temp = list(map(int, input().split()))
	for j in range(m):
		if temp[j] == 1:
			ones.add((i, j))
	A.append(temp)
i = 0
j = 0
res = 0
ress = []
while ones:
	if A[i][j] == 1:
		try:
			if A[i + 1][j] == 1 and A[i][j + 1] == 1 and (A[i + 1][j + 1] == 1):
				res += 1
				ress.append((i, j))
				try:
					ones.remove((i, j))
				except KeyError:
					pass
				try:
					ones.remove((i, j + 1))
				except KeyError:
					pass
				try:
					ones.remove((i + 1, j))
				except KeyError:
					pass
				try:
					ones.remove((i + 1, j + 1))
				except KeyError:
					pass
		except IndexError:
			pass
	if i + 1 == n:
		break
	if j + 1 == m:
		j = 0
		i += 1
	else:
		j += 1
if ones:
	print(-1)
else:
	print(res)
	for i in range(res):
		print(ress[i][0] + 1, ress[i][1] + 1)


X = list(map(int, input().split()))
(A, B, Answer) = ([], [[0] * X[1] for i in range(X[0])], [])
for i in range(X[0]):
	A.append(list(map(int, input().split())))
for i in range(X[0] - 1):
	for j in range(X[1] - 1):
		if A[i][j] + A[i + 1][j] + A[i + 1][j + 1] + A[i][j + 1] == 4:
			B[i][j] = B[i + 1][j] = B[i + 1][j + 1] = B[i][j + 1] = 1
			Answer.append([i + 1, j + 1])
if A != B:
	print(-1)
	exit()
print(len(Answer))
for i in Answer:
	print(*i)


ans = []
(n, m) = list(map(int, input().split()))
mat = []
for i in range(n):
	row = list(map(lambda x: x == '1', input().split()))
	mat.append(row)
conv = []
for i in range(n - 1):
	for j in range(m - 1):
		if mat[i][j] and mat[i][j + 1] and mat[i + 1][j] and mat[i + 1][j + 1]:
			ans.append((i, j))
mat2 = [[0 for j in range(m)] for i in range(n)]
for (i, j) in ans:
	(mat2[i][j], mat2[i][j + 1], mat2[i + 1][j], mat2[i + 1][j + 1]) = [True] * 4
if mat == mat2:
	print(len(ans))
	print('\n'.join(map(lambda x: f'{x[0] + 1} {x[1] + 1}', ans)))
else:
	print(-1)


(n, m) = map(int, input().split())
l = []
b = []
for i in range(n):
	ka = list(map(int, input().split()))
	l.append(ka)
	b.append([0] * len(ka))
ans = []
for i in range(n):
	for j in range(m):
		if l[i][j] == 1:
			flag = 0
			try:
				if l[i][j + 1] == 1 and l[i + 1][j] == 1 and (l[i + 1][j + 1] == 1):
					flag = 1
					b[i][j] = 1
					b[i + 1][j] = 1
					b[i + 1][j + 1] = 1
					b[i][j + 1] = 1
					ans.append((i, j))
				else:
					flag = 0
			except:
				flag = 0
if b == l:
	print(len(ans))
	for i in ans:
		(x, y) = i
		print(x + 1, y + 1)
else:
	print(-1)


(n, m) = map(int, input().split())
grid = []
good = []
for _ in range(n):
	grid.append(list(map(int, input().split())))
	good.append([False] * m)
ok = True
commands = []
for r in range(n):
	for c in range(m):
		if grid[r][c] == 1:
			if r < n - 1 and c < m - 1 and (grid[r + 1][c] == 1) and (grid[r + 1][c + 1] == 1) and (grid[r][c + 1] == 1):
				good[r + 1][c] = True
				good[r + 1][c + 1] = True
				good[r][c + 1] = True
				commands.append([r, c])
			elif not good[r][c]:
				ok = False
if not ok:
	print(-1)
else:
	print(len(commands))
	for com in commands:
		print('{} {}'.format(com[0] + 1, com[1] + 1))


(n, m) = list(map(int, input().split()))
A = []
B = [[0 for i in range(m)] for j in range(n)]
k = 0
opn = []
for _ in range(n):
	A.append(list(map(int, input().split(' '))))
for i in range(n - 1):
	for j in range(m - 1):
		if A[i][j] == 1 and A[i + 1][j] == 1 and (A[i][j + 1] == 1) and (A[i + 1][j + 1] == 1):
			B[i][j] = 1
			B[i + 1][j] = 1
			B[i][j + 1] = 1
			B[i + 1][j + 1] = 1
			k += 1
			opn.append([i + 1, j + 1])
counter = 1
for i in range(n):
	if counter == -1:
		break
	for j in range(m):
		if A[i][j] != B[i][j]:
			counter = -1
			print(-1)
			break
if counter == 1:
	print(k)
	for i in opn:
		print(i[0], i[1])


(n, m) = map(int, input().split())
arr = []
re = []
flag = 0
for i in range(n):
	x = [int(i) for i in input().strip().split()]
	arr.append(x)
b = [[0 for i in range(m)] for j in range(n)]
if arr == b:
	print(0)
else:
	for i in range(n - 1):
		for j in range(m - 1):
			if arr[i][j] == 1 and arr[i][j + 1] == 1 and (arr[i + 1][j] == 1) and (arr[i + 1][j + 1] == 1):
				re.append([i + 1, j + 1])
				b[i][j] = 1
				b[i][j + 1] = 1
				b[i + 1][j] = 1
				b[i + 1][j + 1] = 1
				flag = 1
	if flag == 0 or arr != b:
		print(-1)
	else:
		print(len(re))
		for i in range(len(re)):
			print(re[i][0], re[i][1])


def main():
	import sys
	input = sys.stdin.readline
	(N, M) = map(int, input().split())
	grid = []
	for _ in range(N):
		grid.append(list(map(int, input().split())))
	ans = []
	B = [[0] * M for _ in range(N)]
	for i in range(N - 1):
		for j in range(M - 1):
			if grid[i][j] == grid[i + 1][j] == grid[i][j + 1] == grid[i + 1][j + 1] == 1:
				ans.append((i + 1, j + 1))
				B[i][j] = 1
				B[i + 1][j] = 1
				B[i][j + 1] = 1
				B[i + 1][j + 1] = 1
	for i in range(N):
		for j in range(M):
			if grid[i][j] != B[i][j]:
				print(-1)
				exit()
	print(len(ans))
	for line in ans:
		print(*line)
main()


import math
(n, m) = map(int, input().split())
a = [list(map(int, input().split())) for i in range(n)]
b = [[0] * m for i in range(n)]
q = []
for i in range(n - 1):
	for j in range(m - 1):
		if a[i][j] == a[i + 1][j] == a[i][j + 1] == a[i + 1][j + 1] == 1:
			b[i][j] = b[i + 1][j] = b[i][j + 1] = b[i + 1][j + 1] = 1
			q.append((i + 1, j + 1))
if a != b:
	print(-1)
else:
	print(len(q))
	for i in range(len(q)):
		print(*q[i])


(n, m) = map(int, input().split())
a = [list(map(int, input().split())) for i in range(n)]
b = [[0 for j in range(m)] for i in range(n)]
(res, lst) = (0, [])
for i in range(n - 1):
	for j in range(m - 1):
		if a[i][j] == 1 and a[i + 1][j] == 1 and (a[i][j + 1] == 1) and (a[i + 1][j + 1] == 1):
			(b[i][j], b[i + 1][j], b[i][j + 1], b[i + 1][j + 1]) = (1, 1, 1, 1)
			res += 1
			lst.append([i + 1, j + 1])
if a == b:
	print(res)
	for (i, x) in enumerate(lst):
		print(*x)
else:
	print(-1)


(n, m) = map(int, input().split())
a = [0] * n
b = [[0 for i in range(m)] for j in range(n)]
c = []
p = 0
for i in range(n):
	a[i] = list(map(int, input().split()))
for i in range(n - 1):
	for j in range(m - 1):
		if a[i][j] == 1 and a[i][j + 1] == 1 and (a[i + 1][j] == 1) and (a[i + 1][j + 1] == 1):
			b[i][j] = 1
			b[i][j + 1] = 1
			b[i + 1][j] = 1
			b[i + 1][j + 1] = 1
			c.append(i + 1)
			c.append(j + 1)
if a == b:
	if len(c) == 0:
		print(0)
	else:
		x = len(c) // 2
		print(x)
		for i in range(0, x * 2, 2):
			print(c[i], c[i + 1])
else:
	print(-1)


import sys
(N, M) = list(map(int, sys.stdin.readline().split()))
A = [[0 for _ in range(M + 1)]]
for n in range(N):
	A.append([0] + list(map(int, sys.stdin.readline().split())))

def detectsquare(a):
	answer = []
	for n in range(1, N):
		for m in range(1, M):
			if a[n][m:m + 2] == [1, 1] and a[n + 1][m:m + 2] == [1, 1]:
				answer.append([n, m])
	return answer
B = [[0 for _ in range(M + 1)] for _ in range(N + 1)]
array = detectsquare(A)
for index in array:
	n = index[0]
	m = index[1]
	B[n][m:m + 2] = [1, 1]
	B[n + 1][m:m + 2] = [1, 1]
answer = -1
if A == B:
	answer = len(array)
if answer == -1:
	print(-1)
else:
	print(answer)
	for i in range(answer):
		print(' '.join(list(map(str, array[i]))))


temp = input().split()
n = int(temp[0])
m = int(temp[1])
A = []
for i in range(n):
	A.append(input().split())
out = []
t = 0
for i in range(n):
	for j in range(m):
		if A[i][j] == '1':
			F1 = 1
			if i == n - 1 or j == m - 1:
				pass
			elif A[i][j] == '1' and A[i + 1][j + 1] == '1' and (A[i + 1][j] == '1') and (A[i][j + 1] == '1'):
				out.append(str(i + 1) + ' ' + str(j + 1))
				t += 1
				F1 = 0
			F2 = 1
			if i == 0 or j == m - 1:
				pass
			elif A[i - 1][j] == '1' and A[i - 1][j + 1] == '1' and (A[i][j] == '1') and (A[i][j + 1] == '1'):
				F2 = 0
			F3 = 1
			if j == 0 or i == n - 1:
				pass
			elif A[i + 1][j - 1] == '1' and A[i + 1][j] == '1' and (A[i][j - 1] == '1') and (A[i][j] == '1'):
				F3 = 0
			F4 = 1
			if j == 0 or i == 0:
				pass
			elif A[i][j - 1] == '1' and A[i][j] == '1' and (A[i - 1][j - 1] == '1') and (A[i - 1][j] == '1'):
				F4 = 0
			FLAG = min(F1, F2, F3, F4)
			if FLAG:
				print('-1')
				exit()
print(t)
for el in out:
	print(el)


garbage = list(map(int, input().split()))
arr = []
brr = []
crr = []
check = 1
for i in range(garbage[0]):
	arr.append(list(map(int, input().split())))
	brr.append([0] * garbage[1])
for i in range(garbage[0] - 1):
	for j in range(garbage[1] - 1):
		if arr[i][j] != 0 and arr[i][j + 1] != 0 and (arr[i + 1][j] != 0) and (arr[i + 1][j + 1] != 0):
			brr[i][j] = 1
			brr[i][j + 1] = 1
			brr[i + 1][j] = 1
			brr[i + 1][j + 1] = 1
			crr.append([i + 1, j + 1])
for i in range(garbage[0]):
	for j in range(garbage[1]):
		if arr[i][j] != brr[i][j]:
			check = 0
if check == 0:
	print(-1)
else:
	print(len(crr))
	for i in range(len(crr)):
		print(str(crr[i][0]) + ' ' + str(crr[i][1]))


(n, m) = [int(x) for x in input().split()]
a = [[int(x) for x in input().split()] for j in range(n)]
b = [[0 for i in range(m)] for j in range(n)]
x = []
count = 0

def check(a, i, j, n, m):
	if i + 1 < n and j + 1 < m and (a[i][j] == 1) and (a[i][j + 1] == 1) and (a[i + 1][j] == 1) and (a[i + 1][j + 1] == 1):
		return True
	return False
for i in range(n):
	for j in range(m):
		if check(a, i, j, n, m):
			b[i][j] = 1
			b[i + 1][j] = 1
			b[i][j + 1] = 1
			b[i + 1][j + 1] = 1
			x.append([i, j])
			count += 1
flag = 0
for i in range(n):
	for j in range(m):
		if b[i][j] != a[i][j]:
			flag = 1
			break
if flag == 1:
	print(-1)
if flag == 0:
	print(count)
	for i in range(count):
		print(x[i][0] + 1, x[i][1] + 1)


import math
import sys
DEBUG = False

def inp():
	return sys.stdin.readline().rstrip()

def dprint(*value, sep=' ', end='\n'):
	if DEBUG:
		print(*value, sep=sep, end=end)

def solve(N, M, A):
	B = [[0] * M for _ in range(N)]
	ops = []
	for y in range(N - 1):
		for x in range(M - 1):
			if A[y][x] and A[y][x + 1] and A[y + 1][x] and A[y + 1][x + 1]:
				ops.append((y, x))
				B[y][x] = B[y][x + 1] = B[y + 1][x] = B[y + 1][x + 1] = 1
	if A != B:
		return None
	return ops

def main():
	(N, M) = [int(e) for e in inp().split()]
	A = [[int(e) for e in inp().split()] for _ in range(N)]
	ans = solve(N, M, A)
	if ans is None:
		print(-1)
	else:
		print(len(ans))
		for (x, y) in ans:
			print(x + 1, y + 1)
main()


(n, m) = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(n)]
B = [[0 for j in range(m)] for i in range(n)]
v = []
for i in range(n - 1):
	for j in range(m - 1):
		if A[i][j] + A[i + 1][j] + A[i][j + 1] + A[i + 1][j + 1] == 4:
			v.append((i + 1, j + 1))
			B[i][j] = B[i + 1][j] = B[i][j + 1] = B[i + 1][j + 1] = 1
for i in range(n):
	for j in range(m):
		if B[i][j] != A[i][j]:
			print('-1')
			exit(0)
print(len(v))
for k in v:
	print(f'{k[0]} {k[1]}')


(n, m) = map(int, input().split())
a = [[int(j) for j in input().split()] for i in range(n)]
dots = []
for i in range(n - 1):
	for j in range(m - 1):
		if a[i][j] * a[i + 1][j] * a[i][j + 1] * a[i + 1][j + 1] > 0:
			(a[i][j], a[i + 1][j + 1]) = (69, 69)
			(a[i + 1][j], a[i][j + 1]) = (69, 69)
			dots.append([i + 1, j + 1])
close = 0
for i in range(n):
	for j in range(m):
		if a[i][j] == 1:
			close = 1
			break
	if close == 1:
		break
if close == 1:
	print(-1)
else:
	print(len(dots))
	for i in range(len(dots)):
		print(*dots[i])


import sys
(n, m) = map(int, input().strip().split())
a = [[0 for i in range(m + 1)] for j in range(n + 1)]
for i in range(1, n + 1):
	a[i] = [0] + input().strip().split()
	a[i] = [int(x) for x in a[i]]
d = [[-1, -1], [-1, 1], [1, 1], [1, -1]]

def ok(x, y):
	return x >= 1 and x <= n and (y >= 1) and (y <= m)

def f(x, y):
	for (i, j) in d:
		if ok(x + i, y + j) and ok(x + i, y) and ok(x, y + j):
			if a[x + i][y + j] == 1 and a[x + i][y] == 1 and (a[x][y + j] == 1):
				return True
	return False
flag = True
ans = 0
b = [[] for i in range(n * m)]
for i in range(1, n + 1):
	for j in range(1, m + 1):
		if a[i][j] == 1:
			if f(i, j) == False:
				flag = False
				break
	if flag == False:
		break
if flag == False:
	print(-1)
	sys.exit(0)
for i in range(1, n):
	for j in range(1, m):
		if a[i][j] == 1:
			if ok(i + 1, j + 1) and a[i + 1][j + 1] == 1 and (a[i][j + 1] == 1) and (a[i + 1][j] == 1):
				ans += 1
				b[ans].append(i)
				b[ans].append(j)
print(ans)
for i in range(1, ans + 1):
	print(b[i][0], b[i][1])


import math
import sys
import collections

def getdict(n):
	d = {}
	if type(n) is list:
		for i in n:
			if i in d:
				d[i] += 1
			else:
				d[i] = 1
	else:
		for i in range(n):
			t = ii()
			if t in d:
				d[t] += 1
			else:
				d[t] = 1
	return d

def cdiv(n, k):
	return n // k + (n % k != 0)

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(map(int, input().split()))

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def check(a, i, j):
	if a[i][j] == a[i][j + 1] == a[i + 1][j] == a[i + 1][j + 1] == 1:
		return True
	else:
		return False
(n, m) = mi()
a = []
b = []
for i in range(n):
	a.append(li())
	b.append([0] * m)
r = []
for i in range(n - 1):
	for j in range(m - 1):
		if check(a, i, j):
			r.append([i, j])
			b[i][j] = b[i][j + 1] = b[i + 1][j] = b[i + 1][j + 1] = 1
if a == b:
	print(len(r))
	for i in r:
		print(i[0] + 1, i[1] + 1)
else:
	print(-1)


import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10 ** 9 + 7
inf = float('inf')

def I():
	return int(sys.stdin.readline())

def LI():
	return list(map(int, sys.stdin.readline().split()))
(n, m) = LI()
A = [LI() for _ in range(n)]
B = [[0] * m for _ in range(n)]
ans = []
for i in range(n - 1)[::-1]:
	for j in range(m - 1)[::-1]:
		if A[i][j] == 1 and B[i][j] == 0:
			if A[i + 1][j] == 0 or A[i + 1][j + 1] == 0 or A[i][j + 1] == 0:
				continue
			B[i][j] = 1
			B[i + 1][j] = 1
			B[i][j + 1] = 1
			B[i + 1][j + 1] = 1
			ans.append([i + 1, j + 1])
for i in range(n):
	for j in range(m):
		if A[i][j] != B[i][j]:
			print(-1)
			quit()
print(len(ans))
for (i, j) in ans[::-1]:
	print(i, j)


import sys
from collections import defaultdict as dd
from itertools import permutations as pp
from itertools import combinations as cc
from collections import Counter as ccd
from random import randint as rd
from bisect import bisect_left as bl
from heapq import heappush as hpush
from heapq import heappop as hpop
mod = 10 ** 9 + 7

def ri(flag=0):
	if flag == 0:
		return [int(i) for i in sys.stdin.readline().split()]
	else:
		return int(sys.stdin.readline())
(n, m) = ri()
b = []
a = [[0 for i in range(m)] for j in range(n)]
for i in range(n):
	b.append(ri())
ans = []
for i in range(n - 1):
	for j in range(m - 1):
		if b[i][j] + b[i + 1][j] + b[i][j + 1] + b[i + 1][j + 1] == 4:
			a[i][j] = 1
			a[i + 1][j] = 1
			a[i][j + 1] = 1
			a[i + 1][j + 1] = 1
			ans.append((i, j))
status = 1
for i in range(n):
	for j in range(m):
		status = status & (a[i][j] == b[i][j])
if status:
	print(len(ans))
	for (i, j) in ans:
		print(i + 1, j + 1)
else:
	print(-1)


(n, m) = map(int, input().strip().split())
A = []
for p in range(n):
	A.append(list(map(int, input().strip().split())))
for k in range(n):
	A[k].append(0)
	A[k].insert(0, 0)
A.insert(0, [0 for i in range(m + 2)])
A.append([0 for i in range(m + 2)])
visited = [[False for i in range(m + 2)] for j in range(n + 2)]
flag = True
l = []
for i in range(1, 1 + n):
	for j in range(1, 1 + m):
		if A[i][j] == 1:
			if A[i][j + 1] == 1 and A[i + 1][j] == 1 and (A[i + 1][j + 1] == 1):
				l.append([i, j])
				visited[i][j] = True
				visited[i][j + 1] = True
				visited[i + 1][j] = True
				visited[i + 1][j + 1] = True
			elif not visited[i][j]:
				flag = False
				break
	if not flag:
		break
if not flag:
	print(-1)
else:
	print(len(l))
	for i in l:
		print(*i)


import sys, os, io

def rs():
	return sys.stdin.readline().rstrip()

def ri():
	return int(sys.stdin.readline())

def ria():
	return list(map(int, sys.stdin.readline().split()))

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math, datetime, functools
from collections import deque, defaultdict, OrderedDict
import collections

def main():
	starttime = datetime.datetime.now()
	if os.path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	for _ in range(1):
		(n, m) = ria()
		mat = []
		b = []
		for i in range(n):
			mat.append([int(x) for x in input().split()])
			b.append([0] * m)
		z = []
		for i in range(n - 1):
			for j in range(m - 1):
				if mat[i][j] == 1 and mat[i + 1][j] == 1 and (mat[i][j + 1] == 1) and (mat[i + 1][j + 1] == 1):
					z.append([i + 1, j + 1])
					b[i][j] = 1
					b[i + 1][j + 1] = 1
					b[i][j + 1] = 1
					b[i + 1][j] = 1
		t = 0
		for i in range(n):
			for j in range(m):
				if mat[i][j] != b[i][j]:
					t = 1
					print(-1)
					break
			if t == 1:
				break
		if t == 0:
			wi(len(z))
			for i in z:
				wia(i)
	endtime = datetime.datetime.now()
	time = (endtime - starttime).total_seconds() * 1000
	if os.path.exists('input.txt'):
		print('Time:', time, 'ms')

class FastReader(io.IOBase):
	newlines = 0

	def __init__(self, fd, chunk_size=1024 * 8):
		self._fd = fd
		self._chunk_size = chunk_size
		self.buffer = io.BytesIO()

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size))
			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, size=-1):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size if size == -1 else size))
			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()

class FastWriter(io.IOBase):

	def __init__(self, fd):
		self._fd = fd
		self.buffer = io.BytesIO()
		self.write = self.buffer.write

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

class FastStdin(io.IOBase):

	def __init__(self, fd=0):
		self.buffer = FastReader(fd)
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

class FastStdout(io.IOBase):

	def __init__(self, fd=1):
		self.buffer = FastWriter(fd)
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.flush = self.buffer.flush
sys.stdin = FastStdin()
sys.stdout = FastStdout()
main()