from atcoder import dsu N, K = map(int, input().split()) D = [] for i in range(N): S = input() L = [] for j in range(N): L.append(int(S[j])) D.append(L) dx = [0, 1, 0, -1] dy = [1, 0, -1, 0] def merge(i, j): return i * N + j def sep(ij): return ij //N, ij % N def calc_score(L): S = set(L) DS = dsu.DSU(N * N) for i in range(N): for j in range(N): if((i, j) in S or D[i][j] < 5): continue ij = merge(i, j) for k in range(4): x2 = i + dx[k] y2 = j + dy[k] if(0 <= x2 < N and 0 <= y2 < N): if((x2, y2) not in S and D[x2][y2] >= 5): xy2 = merge(x2, y2) DS.merge(ij, xy2) s = 0 # print(DS.groups()) for l in DS.groups(): s += len(l) ** 2 return s best_ans = [] best_score = calc_score([]) for i in range(1, N - 1): for j in range(1, N - 1): L = set() for x in range(N): if(D[x][i + x % 2] != 0): L.add((x, i + x % 2)) for y in range(N): if(D[j + y % 2][y] != 0): L.add((j + y % 2, y)) score = calc_score(L) if(score < best_score): best_score = score best_ans = L print(len(best_ans)) for x, y in best_ans: print(x, y)