#include using namespace std; const int MAX_M = 100; const int MAX_N = 100; int PA[MAX_M][MAX_N]; int PB[MAX_M][MAX_N]; int bestA[MAX_N]; int bestB[MAX_M]; int main (){ int m, n, N; while (true){ cin >> m >> n; if (m == 0 && n == 0) break; for (int i = 0; i < m; i++) for (int j = 0; j < n; j++) cin >> PA[i][j]; for (int i = 0; i < m; i++) for (int j = 0; j < n; j++) cin >> PB[i][j]; // compute value of best responses for (int i = 0; i < m; i++){ bestB[i] = PB[i][0]; for (int j = 1; j < n; j++) bestB[i] = max (bestB[i], PB[i][j]); } for (int j = 0; j < n; j++){ bestA[j] = PA[0][j]; for (int i = 1; i < m; i++) bestA[j] = max (bestA[j], PA[i][j]); } // compute number of Nash equilibria N = 0; for (int i = 0; i < m; i++) for (int j = 0; j < n; j++) if (PA[i][j] == bestA[j] && PB[i][j] == bestB[i]) N++; cout << N << endl; // list all Nash equilibria for (int i = 0; i < m; i++) for (int j = 0; j < n; j++) if (PA[i][j] == bestA[j] && PB[i][j] == bestB[i]) cout << i+1 << ' ' << j+1 << endl; } return 0; }