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: interview

Starter code:

Solutions:
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] = 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 a, b in ans:
        print(a, b)
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)


n,m=list(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)


n, m = map(int, input().split())
a = [input().split() for _ in range(n)]
mk = [[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 + 1][j] == a[i][j + 1] == a[i + 1][j + 1] == '1':
            ans.append((i + 1, j + 1))
            mk[i][j] = mk[i + 1][j] = mk[i][j + 1] = mk[i + 1][j + 1] = 1

if any(a[i][j] == '1' and not mk[i][j] for i in range(n) for j in range(m)):
    print(-1)
else:
    print(len(ans))
    print(*('%d %d' % (i, j) for i, j in ans), sep='\n')

n,m=list(map(int,input().split()))
ar=[]
for x in range(n):
    e=list(map(int,input().split()))
    ar.append(e)
col=set()
moves=[]
for i in range(n-1):
    for j in range(m-1):
        if(ar[i][j]==ar[i+1][j]==ar[i][j+1]==ar[i+1][j+1]==1):
            moves.append([i+1,j+1])
            col.add((i,j))
            col.add((i+1,j))
            col.add((i+1,j+1))
            col.add((i,j+1))
for i in range(n):
    for j in range(m):
        if(ar[i][j]):
            if((i,j) not in col):
                print(-1)
                quit()
print(len(moves))
for x in moves:
    print(*x)


#E71_B

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]))


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)


n, m = list(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)


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)]

#print(*a,*b, sep="\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)
      return

print(len(ans))
for i in ans:
  print(*i)

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)


''' بِسْمِ اللَّهِ الرَّحْمَٰنِ الرَّحِيمِ '''
#codeforces1207B_live
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)
			return
print(len(ans))
for e in ans:
	print(*e)

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)

import sys
input = sys.stdin.readline

n,m=list(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 = 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)

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)

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)

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 = list(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)


def mi():
        return list(map(int, input().split()))
'''
3 3
1 1 1
1 1 1
0 1 1
'''
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=map(int,input().split())
ans=[]
b=[[0]*m for i in range(n)]
a=[]
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]==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 b!=a:
    print(-1)
else:
    print(len(ans))
    for i in range(len(ans)):
        print(*ans[i])

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)
    
    


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 list(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)


# TAIWAN NUMBER ONE!!!!!!!!!!!!!!!!!!!
# TAIWAN NUMBER ONE!!!!!!!!!!!!!!!!!!!
# TAIWAN NUMBER ONE!!!!!!!!!!!!!!!!!!!
from sys import stdin, stdout
from collections import defaultdict
import math
import copy
 
#T = int(input())
#N = int(input())
#s = input()
N,M = [int(x) for x in stdin.readline().split()]
#arr = [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])
        

        


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)