#include <bits/stdc++.h>
using namespace std;

#include "code.h"

int mat[1005][1005];

/*static int n, k;
static int question_num = 0;
static int h[1001][1001];

int Pitaj(int i, int j){
	question_num++;
	if ((i < 1) || (i > n)) return -1;
	if ((j < 1) || (j > n)) return -1;
	return h[i][j];
}*/

int maxred[1005];
int minkol[1005];
int cntred[1005];
int cntkol[1005];

std::vector <int> Nadji(int N, int K){
    for(int i=1; i<=N; i++){
        for(int j=1; j<=N; j++){
            mat[i][j] = Pitaj(i, j);
            maxred[i] = max(maxred[i], mat[i][j]);
            if(!minkol[j]) minkol[j] = mat[i][j];
            else minkol[j] = min(minkol[j], mat[i][j]);
        }
    }
    for(int i=1; i<=N; i++){
        for(int j=1; j<=N; j++){
            if(mat[i][j] == maxred[i]) cntred[i]++;
            if(mat[i][j] == minkol[j]) cntkol[j]++;
        }
    }
    for(int i=1; i<=N; i++){
        for(int j=1; j<=N; j++){
            if(maxred[i] == mat[i][j] && minkol[j] == mat[i][j]){
                if(cntred[i] == 1 && cntkol[j] == 1) return {i, j};
            }
        }
    }
    return {0, 0};
}


/*int main()
{
	scanf("%d%d", &n, &k);

	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++)
			scanf("%d", &h[i][j]);

	std::vector<int> out = Nadji(n, k);

	printf("%d %d %d\n", out[0], out[1], question_num);

	return 0;
}*/