from collections import deque
N,M = map(int,input().split(" "))
graph = []
cheeze = 0
for i in range(N):
graph.append(list(map(int,input().split(" "))))
for i in range(N):
cheeze += sum(graph[i])
dx = [-1,0,1,0]
dy = [0,-1,0,1]
def BFS():
melt = []
global count
Q = deque()
Q.append([0,0])
while Q:
x,y = Q.popleft()
for i in range(4):
nx,ny = x+dx[i], y+dy[i]
if 0<=nx<N and 0<=ny<M and visited[nx][ny] == False:
visited[nx][ny] = True
if graph[nx][ny] == 0:
Q.append([nx,ny])
if graph[nx][ny] == 1:
melt.append([nx,ny])
for x,y in melt:
graph[x][y] = 0
count += 1
return len(melt)
count = 0
remained = []
while 1:
visited = [[False for _ in range(M)] for _ in range(N)]
melted = BFS()
cheeze = cheeze - melted
if cheeze == 0:
print(count)
print(melted)
break