#include <bits/stdc++.h>
#include "code.h"
#define maxN 100005

using namespace std;

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];
}


map<pair<int,int>,int> m;

int pitajjj(int x,int y){
if(m.find({x,y})!=m.end()) return m[{x,y}];
//cout<<x<<" "<<y<<endl;
m[{x,y}]=Pitaj(x,y);
return m[{x,y}];
}
/*
pair<int,int> poredi(pair<int,int> a,pair<int,int> b){
if(a==make_pair(0,0)) return b;
if(b==make_pair(0,0)) return a;
//cout<<"!"<<b.first<<" "<<b.second<<endl;
int tmp,pom;
tmp=pitaj(a.first,b.second);
pom=pitaj(b.first,a.second);
if(pitaj(a.first,a.second)>tmp && pitaj(a.first,a.second)<pom) return a;
if(pitaj(b.first,b.second)<tmp && pitaj(b.first,b.second)>pom) return b;
return {0,0};
}
*/

bool proveri(pair<int,int> a,int x1,int x2,int y1,int y2){
if(a==make_pair(0,0)) return false;
for(int i=x1;i<=x2;i++) if(pitajjj(a.first,a.second)>=pitajjj(i,a.second)) return false;
for(int i=y1;i<=y2;i++) if(pitajjj(a.first,a.second)<=pitajjj(a.first,i)) return false;
return true;
}

pair<int,int> resi(int x1,int y1,int x2,int y2){
if(x2<x1 || y2<y1) return {0,0};
if(x1==x2 && y1==y2) return {x1,y1};
pair<int,int> p1,p2,p3,p4,r;
int mx=(x1+x2)/2,my=(y1+y2)/2;
p1=resi(x1,y1,mx,my);
if(proveri(p1,mx+1,x2,my+1,y2)) r=p1;
p2=resi(x1,my+1,mx,y2);
if(proveri(p2,mx+1,x2,y1,my)) r=p2;
p3=resi(mx+1,y1,x2,my);
if(proveri(p3,x1,mx,my+1,y2)) r=p3;
p4=resi(mx+1,my+1,x2,y2);
if(proveri(p4,x1,mx,y1,my)) r=p4;
//cout<<x1<<" "<<y1<<" "<<mx<<" "<<my<<endl;
//cout<<p1.first<<" "<<p1.second<<endl;
//cout<<"!"<<r.first<<" "<<r.second<<endl;
return r;
}

std::vector<int> Nadji(int N, int K)
{
	pair<int,int> p=resi(1,1,N,N);
	std::vector<int> out;
    out.push_back(p.first);
    out.push_back(p.second);
	return out;
}