from sys import stdin
input = stdin.readline
inp = lambda : list(map(int,input().split()))
def check(x , y):
if(x + 1 >= n or y + 1 >= m):return False
count = a[x][y] + a[x + 1][y] + a[x][y + 1] + a[x + 1][y + 1]
if(count == 4):return True
return False
def answer():
ans = []
b = [[0 for i in range(m)] for j in range(n)]
for i in range(n):
for j in range(m):
if(check(i , j)):
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[i][j] == 0 and a[i][j] == 1):
if(not check(i , j)):
print(-1)
return
print(len(ans))
for x in ans:
print(*x)
for T in range(1):
n , m = inp()
a = [inp() for i in range(n)]
answer()
#include <bits/stdc++.h>
using namespace std;
vector<pair<int , int>> operations;
void check(vector<vector<int>> &v , int x , int y)
{
int total = v[x][y] + v[x + 1][y] + v[x][y + 1] + v[x + 1][y + 1];
if(total == 4) operations.push_back({x , y});
}
void testcase()
{
int n , m; cin >> n >> m;
vector<vector<int>> v(n , vector<int>(m , 0));
for(auto &vec : v) for(auto &i : vec) cin >> i;
for (int i = 0; i < n - 1; ++i)
{
for (int j = 0; j < m - 1 ; ++j)
{
check(v , i , j);
}
}
vector<vector<int>> dup(n , vector<int>(m , 0));
for(auto &[x , y] : operations)
{
int a = x , b = y;
dup[x][y] = 1;
dup[x + 1][y] = 1;
dup[x][y + 1] = 1;
dup[x + 1][y + 1] = 1;
}
if(dup == v)
{
cout << operations.size() << endl;
for(auto &[x , y] : operations)
{
cout << x + 1 << " " << y + 1 << endl;
}
}
else cout << -1 << endl;
}
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
clock_t z = clock();
int tc = 1;
// cin >> tc;
while (tc--) testcase();
cerr << "Run Time : " << ((double)(clock() - z) / CLOCKS_PER_SEC) << endl;
return 0;
}
150. Evaluate Reverse Polish Notation | 144. Binary Tree Preorder Traversal |
137. Single Number II | 130. Surrounded Regions |
129. Sum Root to Leaf Numbers | 120. Triangle |
102. Binary Tree Level Order Traversal | 96. Unique Binary Search Trees |
75. Sort Colors | 74. Search a 2D Matrix |
71. Simplify Path | 62. Unique Paths |
50. Pow(x, n) | 43. Multiply Strings |
34. Find First and Last Position of Element in Sorted Array | 33. Search in Rotated Sorted Array |
17. Letter Combinations of a Phone Number | 5. Longest Palindromic Substring |
3. Longest Substring Without Repeating Characters | 1312. Minimum Insertion Steps to Make a String Palindrome |
1092. Shortest Common Supersequence | 1044. Longest Duplicate Substring |
1032. Stream of Characters | 987. Vertical Order Traversal of a Binary Tree |
952. Largest Component Size by Common Factor | 212. Word Search II |
174. Dungeon Game | 127. Word Ladder |
123. Best Time to Buy and Sell Stock III | 85. Maximal Rectangle |