#include<bits/stdc++.h>
using namespace std;
#define mem(a,b) memset(a,b,sizeof a) ;
#define vi vector<int>
#define vit vector<int> :: iterator
#define all(ans) ans.begin(),ans.end()
//#define sz(a) int(a.size())
#define ub upper_bound
#define lb lower_bound
#define create(Name,N,M,val) vector<vector<int> > Name(N,vector<int>(M,val))
#define ull unsigned long long
#define ll long long
#define db double
#define ldb long double
#define fl float
#define rep(i,a,b) for(int i=a;i<b;i++)
#define lrep(i,a,b) for(ll i=a;i<b;i++)
//#define all(c) c.begin(),c.end()
#define tr(c,it) for(typeof(c.begin()) it=c.begin();it!=c.end();it++)
#define mpr make_pair
#define pb push_back
#define fr first
#define sn second
int dx[]={1,-1,0,0};
int dy[]={0,0,1,-1};
bool vis[2001][2001];
void solve()
{
int n,m,k; cin>>n>>m>>k;
int ax,ay;
queue< pair<int,int> >q;
rep(i,0,k)
{ cin>>ax>>ay;
q.push({ax,ay});
vis[ax][ay]=1; }
pair < int,int > ans;
while(!q.empty())
{
	pair < int,int > p;
	p=q.front();
	ans=p;
	q.pop();
	int xx=p.first;
	int yy=p.second;
	rep(j,0,4)
	{
	int nx=xx+dx[j];
	int ny=yy+dy[j];
	if(nx>0 && nx<=n && ny>0 && ny<=m && vis[nx][ny]==0)
	{
	vis[nx][ny]=1;
	q.push({nx,ny});
	}
	}
}
cout<<ans.fr<<' '<<ans.sn;
return;
}
int main()
{
ios_base::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
//	cin>>t;
while(t--)
{
solve();
}
return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define sn second
#define fr first
#define pb push_back
#define ll long long int
#define pa pair<int,int>
ll dx[]={1,-1,0,0};
ll dy[]={0,0,1,-1};
queue< pa > q;
int n,m;
bool vis[2003][2003];
pair<int,int> bfs()
{
    pa ans;
    while(!q.empty())
    {
        ans=q.front();
        int x,y,nx,ny;
        q.pop();
        x=ans.first;
        y=ans.second;
        for(int i=0;i<4;i++)
        {
            nx=x+dx[i];
            ny=y+dy[i];
            if(nx<=n&&ny<=m&&nx>0&&ny>0&&vis[nx][ny]==0)
            {
                q.push({nx,ny});
                vis[nx][ny]=1;
            }
        }
    }
    return ans;
}
int main()
{
    ifstream cin("input.txt");
    ofstream cout("output.txt");
    cin>>n>>m;
    int k;
    cin>>k;
    while(k--)
    {
        int x,y;
        cin>>x>>y;
        q.push({x,y});
        vis[x][y]=1;
    }
    pair<int,int> ans=bfs();
    cout<<ans.fr<<" "<<ans.sn;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define mem(a,b) memset(a,b,sizeof a) ;
#define vi vector<int>
#define vit vector<int> :: iterator
#define all(ans) ans.begin(),ans.end()
//#define sz(a) int(a.size())
#define ub upper_bound
#define lb lower_bound
#define create(Name,N,M,val) vector<vector<int> > Name(N,vector<int>(M,val))
#define ull unsigned long long
#define ll long long
#define db double
#define ldb long double
#define fl float
#define rep(i,a,b) for(int i=a;i<b;i++)
#define lrep(i,a,b) for(ll i=a;i<b;i++)
//#define all(c) c.begin(),c.end()
#define tr(c,it) for(typeof(c.begin()) it=c.begin();it!=c.end();it++)
#define mpr make_pair
#define pb push_back
#define fr first
#define sn second
#define bpp(x) __builtin_popcountll(x)
const ldb PI = 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899863;
const long long INF = 1e9+7;
/*
bool ok(string &s ,int l ,int r)
{
while(s[l]==s[r]) l++,r--;
return l>=r;
}
int prime[]={2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89,97,101,103};
int add(int a,int b) // integer range
{
long x=a+b;
if(x>=INF)
x-=INF;
return x;
}
int gcd(int a, int b)
{
while(b)
{
a%=b;
swap(a,b);
}
return a;
}
ll pw(ll a,int b)
{
ll res=1;
while(b)
{
if(b&1) res=(res*a)%998244353;
a=(a*a)%998244353;
b>>=1;
}
return res;
}
bool isFib(int n)
{
int x,y;
x=sqrt(5*n*n+4); y=sqrt(5*n*n-4);
return ((x*x)==(5*n*n+4))||((y*y)==(5*n*n-4));
}
int ExtU(int a,int b,int &x,int &y)
{
if(a==0)
{
x=0; y=1; return b;
}
int x1,y1;
int d=ExtU(b%a,a,x1,y1);
x=y1-(b/a)*x1;
y=x1;
return d;
}
int factors(int n)
{
int ct=0;
for(int i=1;i*i<=n;i++)
{
if(n%i==0)
{
if(i*i==n)
ct++;
else
ct+=2;
}
return ct;
}
}
vector<int>factorize(int n)
{
vi ans;
while(n%2==0)
{
ans.pb(2); n/=2;
}
for(int i=3;i<=sqrt(n);i+=2)
{
while(n%i==0)
{
ans.pb(i); n/=i;
}
}
if(n>2)
ans.pb(n);
return ans;
}
int mnpr[500003]={0};
void sprime(int n)
{
for(int i=2;i*i<=n;i++)
{
if(mnpr[i]==0)
{
for(int j=i*i;j<=n;j+=i)
{
if(mnpr[j]==0)
mnpr[j]=i;
}
}
}
for(int i=1;i<=n;i++)
if(mnpr[i]==0)
mnpr[i]=i;
}
int mxpr(int n)
{
int mx;
while(n&1==0)
{
mx=2; n>>=1;
}
for(int i=3;i*i<=n;i+=2)
{
while(n%i==0)
{
mx=i; n/=i;
}
}
if(n>2)
mx=n;
return mx;
}
bool seg[100005]={true};
void ss(int r,int l)
{
rep(i,0,r-l+2)
seg[i]=true;
for(int i=2;i*i<=r;i++)
{
for(int j=max(i*i,((l+i-1)/i)*i);j<=r;j+=i)
seg[j-l]=false;
}
}
int phi(int n)
{
int res=n;
for(int i=2;i*i<=n;i++)
{
if(n%i==0)
{
while(n%i==0)
n/=i;
res-=res/i;
}
}
if(n>1)
res-=res/n;
return res;
}
int ncr(int n,int r)
{
int C[r+1];
mem(C,0);
C[0]=1;
for(int i=1;i<=n;i++)
{
for(int j=min(i,r);j;j--)
{
C[j]=(C[j]+C[j-1])%INF;
}
}
return C[r];
}
int bitzero(int n)
{
int ct=0;
while(n)
{
ct+=!(n&1);
n>>=1;
}
return ct;
}
string twocom(string &s)
{
int i;
for(i=s.length()-1;i>=0;i--)
if(s[i]=='1')
break;
if(i==-1)
{
return '1'+s;
}
for(int k=i-1;k>=0;k--)
{
if(s[k]=='1')
s[k]='0';
else
s[k]='1';
}
return s;
}
void sl()
{
int n;
goto e;
cin>>n;
e:
;
cout<<n;
return ;
}
*/
void edit()
{
// string s; getline(cin,s);
// v.resize(num);
//create(dp,N,M,val);
//vector<int> vec;
//vec.pb(10);vec.pb(20);vec.pb(70);vec.pb(80);
//tr(vec,it)
//cout<<(*it)<<' ';
//vector<int> v;
//v.pb(30);v.pb(40);v.pb(50);v.pb(60);
//vec.insert(vec.begin()+2,all(v));
// copy(all(v1),inserter(v2,it));

// a[i]^a[i+j]^a[i+j+k]=='B'^'G'^'R';
// last element of set -> s.rbegin()
// sqrt= binary search
return;
}
/*
void solv()
{
string s; cin>>s;
reverse(all(s));
int a[s.size()+1];
a[0]=0;
int ct[2019]={0};
ct[0]=1;
int ml=1;
rep(i,0,s.size())
{
a[i+1]=(a[i]+(s[i-1]-'0')*ml)%2019;
ml=10*ml % 2019;
ct[a[i+1]]++;
}
int ans=0;
rep(i,0,2019)
{
int x=ct[i]*(ct[i]-1)/2;
ans+=x;
}
cout<<ans;
return ;
}
*/
int dx[]={1,-1,0,0};
int dy[]={0,0,1,-1};
int dis[2001][2001];
bool vis[2001][2001];
void solve()
{
int n,m; cin>>n>>m;
rep(i,1,n+1)
rep(j,1,m+1)
dis[i][j]=1000009;
int k; cin>>k;
int ax[k],ay[k];
rep(i,0,k)
{ cin>>ax[i]>>ay[i]; }
queue< pair<int,int> >q;
rep(i,0,k)
{
rep(i,0,n+1)
rep(j,1,m+1)
vis[i][j]=0;
q.push({ax[i],ay[i]}); dis[ax[i]][ay[i]]=0;
while(!q.empty())
{
	pair < int,int > p;
	p=q.front();
	q.pop();
	int xx=p.first;
	int yy=p.second;
	rep(j,0,4)
	{
	int nx=xx+dx[j];
	int ny=yy+dy[j];
	if(nx>0 && nx<=n && ny>0 && ny<=m && vis[nx][ny]==0)
	{
	vis[nx][ny]=1;
	if(dis[nx][ny]<=dis[xx][yy]+1)
	continue;
	dis[nx][ny]=dis[xx][yy]+1;
	q.push({nx,ny});
	}
	}
}
}
int mx=0;
int ans[2];
rep(i,1,n+1)
{
rep(j,1,m+1)
{
if(dis[i][j]>=mx)
{
mx=dis[i][j];
ans[0]=i;ans[1]=j;
}
}
}
cout<<ans[0]<<' '<<ans[1];
return;
}
int main()
{
ios_base::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
//	cin>>t;
while(t--)
{
solve();
}
return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define mem(a,b) memset(a,b,sizeof a) ;
#define vi vector<int>
#define vit vector<int> :: iterator
#define all(ans) ans.begin(),ans.end()
//#define sz(a) int(a.size())
#define ub upper_bound
#define lb lower_bound
#define create(Name,N,M,val) vector<vector<int> > Name(N,vector<int>(M,val))
#define ull unsigned long long
#define ll long long
#define db double
#define ldb long double
#define fl float
#define rep(i,a,b) for(int i=a;i<b;i++)
#define lrep(i,a,b) for(ll i=a;i<b;i++)
//#define all(c) c.begin(),c.end()
#define tr(c,it) for(typeof(c.begin()) it=c.begin();it!=c.end();it++)
#define mpr make_pair
#define pb push_back
#define fr first
#define sn second
int dx[]={1,-1,0,0};
int dy[]={0,0,1,-1};
void solve()
{
int n,m; cin>>n>>m;
int dis[n+1][m+1];
bool vis[n+1][m+1];
rep(i,1,n+1)
rep(j,1,m+1)
dis[i][j]=1000009;
int k; cin>>k;
int ax[k],ay[k];
rep(i,0,k)
{ cin>>ax[i]>>ay[i]; }
queue< pair<int,int> >q;
rep(i,0,k)
{
rep(i,0,n+1)
rep(j,1,m+1)
vis[i][j]=0;
q.push({ax[i],ay[i]}); dis[ax[i]][ay[i]]=0;
while(!q.empty())
{
	pair < int,int > p;
	p=q.front();
	q.pop();
	int xx=p.fr;
	int yy=p.sn;
	rep(j,0,4)
	{
	int nx=xx+dx[j];
	int ny=yy+dy[j];
	if(nx>0 && nx<=n && ny>0 && ny<=m && vis[nx][ny]==0)
	{
	vis[nx][ny]=1;
	if(dis[nx][ny]<=dis[xx][yy]+1)
	continue;
	dis[nx][ny]=dis[xx][yy]+1;
	q.push({nx,ny});
	}
	}
}
}
int mx=0;
int ans[2];
rep(i,1,n+1)
{
rep(j,1,m+1)
{
if(dis[i][j]>=mx)
{
mx=dis[i][j];
ans[0]=i;ans[1]=j;
}
}
}
cout<<ans[0]<<' '<<ans[1];
return;
}
int main()
{
ios_base::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
//	cin>>t;
while(t--)
{
solve();
}
return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define ll long long
#define rep(i,a,b) for(int i=a;i<b;i++)
#define pb push_back
#define fr first
#define sn second
int dx[]={1,-1,0,0};
int dy[]={0,0,1,-1};
bool vis[2002][2002];
queue< pair<int,int> >q;
int n,m;
pair < int,int > bfs()
{
      pair < int,int > ans;
while(!q.empty())
{
	ans=q.front();
	q.pop();
	int xx=ans.first;
	int yy=ans.second;
	rep(j,0,4)
	{
	int nx=xx+dx[j];
	int ny=yy+dy[j];
	if(nx>0 && nx<=n && ny>0 && ny<=m && vis[nx][ny]==0)
	{
	vis[nx][ny]=1;
	q.push({nx,ny});
	}
	}
}
return ans;
}
void solve()
{
int k; cin>>n>>m>>k;
//bool vis[n+1][m+1];
rep(i,1,n+1)
rep(j,1,m+1)
vis[i][j]=0;
int ax,ay;
rep(i,0,k)
{ cin>>ax>>ay;
q.push({ax,ay});
vis[ax][ay]=1; }
pair<int,int> ans=bfs();
cout<<ans.fr<<' '<<ans.sn;
return;
}
int main()
{
ifstream cin("input.txt");
    ofstream cout("output.txt");
ios_base::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
//	cin>>t;
while(t--)
{
solve();
}
return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define ll long long
#define rep(i,a,b) for(int i=a;i<b;i++)
#define pb push_back
#define fr first
#define sn second
int dx[]={1,-1,0,0};
int dy[]={0,0,1,-1};
bool vis[2002][2002];
int n,m;
pair < int,int > bfs()
{
      pair < int,int > ans;
while(!q.empty())
{
	ans=q.front();
	q.pop();
	int xx=ans.first;
	int yy=ans.second;
	rep(j,0,4)
	{
	int nx=xx+dx[j];
	int ny=yy+dy[j];
	if(nx>0 && nx<=n && ny>0 && ny<=m && vis[nx][ny]==0)
	{
	vis[nx][ny]=1;
	q.push({nx,ny});
	}
	}
}
return ans;
}
void solve()
{
int k; cin>>n>>m>>k;
//bool vis[n+1][m+1];
rep(i,1,n+1)
rep(j,1,m+1)
vis[i][j]=0;
int ax,ay;
queue< pair<int,int> >q;
rep(i,0,k)
{ cin>>ax>>ay;
q.push({ax,ay});
vis[ax][ay]=1; }
pair<int,int> ans=bfs();
cout<<ans.fr<<' '<<ans.sn;
return;
}
int main()
{
ifstream cin("input.txt");
    ofstream cout("output.txt");
ios_base::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
//	cin>>t;
while(t--)
{
solve();
}
return 0;
}


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

const int maxn = 4e3;
int n, m, k;
int dist[maxn][maxn];
bool vis[maxn][maxn];
int pointx[] = {0, 0, 1, -1};
int pointy[] = {1, -1, 0, 0};
queue<pair<int, int>> q;

int main()
{

    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    cin.sync_with_stdio(0);
    cin>>n>>m>>k;int x,y,max=-100;
    for(int i=0;i<k;i++){cin>>x>>y;q.push({x,y});dist[x][y]=0;vis[x][y]=1;}
    while(!q.empty())
    {
    	auto p = q.front();q.pop();
    	vis[p.first][p.second] = true;
    	for(int i=0;i<4;i++){x=p.first+pointx[i];y=p.second+pointy[i];if(x > n || x <= 0 || y > m || y <= 0 || vis[x][y] == 1){continue;}dist[x][y]=dist[p.first][p.second] + 1;q.push({x,y});}
    }
    for(int i = 1 ; i <= n ; ++i)
        for(int j = 1 ; j <= m ; ++j)
            if(dist[i][j] > max)
            {
                x = i, y = j;
                max = dist[i][j];
            }
    cout<<x<<" "<<y;
    return 0;
}


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

const int maxn = 4e3;
int n, m, k;
int dist[maxn][maxn];
int pointx[] = {0, 0, 1, -1};
int pointy[] = {1, -1, 0, 0};
queue<pair<int, int>> q;

int main()
{

    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    cin.sync_with_stdio(0);
    cin>>n>>m>>k;int x,y,max=-100;
    memset(dist, -1, sizeof dist);
    for(int i=0;i<k;i++){cin>>x>>y;q.push({x,y});dist[x][y]=0;}
    while(!q.empty())
    {
    	auto p = q.front();q.pop();
    	for(int i=0;i<4;i++){x=p.first+pointx[i];y=p.second+pointy[i];if(x > n || x <= 0 || y > m || y <= 0 || dist[x][y] != -1){continue;}dist[x][y]=dist[p.first][p.second] + 1;q.push({x,y});}
    }
    for(int i = 1 ; i <= n ; ++i)
        for(int j = 1 ; j <= m ; ++j)
            if(dist[i][j] > max)
            {
                x = i, y = j;
                max = dist[i][j];
            }
    cout<<x<<" "<<y;
    return 0;
}


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

const int maxn = 4e3;
int n, m, k;
int dist[maxn][maxn];
int pointx[] = {0, 0, 1, -1};
int pointy[] = {1, -1, 0, 0};
queue<pair<int, int>> q;

int main()
{

    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    cin.sync_with_stdio(0);
    cin>>n>>m>>k;int x,y,max=-100;
    memset(dist, -1, sizeof dist);
    for(int i=0;i<k;i++){cin>>x>>y;q.push({x,y});dist[x][y]=0;}
    while(!q.empty())
    {
    	auto p = q.front();q.pop();
    	vis[p.first][p.second] = true;
    	for(int i=0;i<4;i++){x=p.first+pointx[i];y=p.second+pointy[i];if(x > n || x <= 0 || y > m || y <= 0 || dist[x][y] != -1){continue;}dist[x][y]=dist[p.first][p.second] + 1;q.push({x,y});}
    }
    for(int i = 1 ; i <= n ; ++i)
        for(int j = 1 ; j <= m ; ++j)
            if(dist[i][j] > max)
            {
                x = i, y = j;
                max = dist[i][j];
            }
    cout<<x<<" "<<y;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int maxn = 2e3;
int n,m,k,dist[maxn][maxn];
bool vis[maxn][maxn];
queue<pair<int, int>> q;

int main()
{
	ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	cin>>n>>m>>k;int x,y;
	for(int i=0;i<k;i++){cin>>x>>y;q.push(make_pair(x,y));dist[x][y]=0;}
	pair<int,int> p,ans = make_pair(x,y);
	while(!q.empty())
	{
		p = q.front();q.pop();x=p.first;y=p.second;if(dist[x][y]>dist[ans.first][ans.second]){ans=p;}vis[x][y] = true;
		if(x>1 && !vis[x-1][y]){dist[x-1][y] = dist[x][y] + 1;q.push(make_pair(x+1,y));}
		if(x<n && !vis[x+1][y]){dist[x+1][y] = dist[x][y] + 1;q.push(make_pair(x+1,y));}
		if(y>1 && !vis[x][y-1]){dist[x][y-1] = dist[x][y] + 1;q.push(make_pair(x,y-1));}
		if(y<m && !vis[x][y+1]){dist[x][y+1] = dist[x][y] + 1;q.push(make_pair(x,y+1));}
	}
	cout<<ans.first<<" "<<ans.second;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int maxn = 4e3;
int n,m,k,dist[maxn][maxn];
bool vis[maxn][maxn];
queue<pair<int, int>> q;

int main()
{
	ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	cin>>n>>m>>k;int x,y;
	for(int i=0;i<k;i++){cin>>x>>y;q.push(make_pair(x,y));dist[x][y]=0;}
	pair<int,int> p,ans = make_pair(x,y);
	while(!q.empty())
	{
		p = q.front();q.pop();x=p.first;y=p.second;if(dist[x][y]>dist[ans.first][ans.second]){ans=p;}vis[x][y] = true;
		if(x>1 && !vis[x-1][y]){dist[x-1][y] = dist[x][y] + 1;q.push(make_pair(x+1,y));}
		if(x<n && !vis[x+1][y]){dist[x+1][y] = dist[x][y] + 1;q.push(make_pair(x+1,y));}
		if(y>1 && !vis[x][y-1]){dist[x][y-1] = dist[x][y] + 1;q.push(make_pair(x,y-1));}
		if(y<m && !vis[x][y+1]){dist[x][y+1] = dist[x][y] + 1;q.push(make_pair(x,y+1));}
	}
	cout<<ans.first<<" "<<ans.second;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int maxn = 2e4+10;
int n,m,k,dist[maxn][maxn];
bool vis[maxn][maxn];
queue <pair<int,int>> q;
pair<int,int> p,ans;

int main()
{
	freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
	cin>>n>>m>>k;int x,y;for(int i=1;i<=k;i++){cin>>x>>y;q.push(make_pair(x,y));};
	//dfs:
	ans={20001,2001};dist[ans.first][ans.second] = 0;
	while(!q.empty())
	{
		p = q.front();q.pop();
		x=p.first;y=p.second;
		vis[x][y] = true;
		if(dist[x][y]>dist[ans.first][ans.second])
			ans = p;
		if(x>1 && !vis[x-1][y]){q.push(make_pair(x-1,y));dist[x-1][y] = dist[x][y] + 1;}
		if(x<n && !vis[x+1][y]){q.push(make_pair(x+1,y));dist[x+1][y] = dist[x][y] + 1;}
		if(y>1 && !vis[x][y-1]){q.push(make_pair(x,y-1));dist[x][y-1] = dist[x][y] + 1;}
		if(y<m && !vis[x][y+1]){q.push(make_pair(x,y+1));dist[x][y+1] = dist[x][y] + 1;}
	}
	cout<<ans.first<<" "<<ans.second;
	return 0;
}


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

const int maxn = 2e3+1;
int n, m, k;
int dist[maxn][maxn];
bool vis[maxn][maxn];
int pointx[] = {0, 0, 1, -1};
int pointy[] = {1, -1, 0, 0};
queue<pair<int, int>> q;

int main()
{

    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    cin.sync_with_stdio(0);
    cin>>n>>m>>k;int x,y,max=-100;
    for(int i=0;i<k;i++){cin>>x>>y;q.push({x,y});dist[x][y]=0;vis[x][y]=1;}
    while(!q.empty())
    {
    	auto p = q.front();q.pop();
    	vis[p.first][p.second] = true;
    	for(int i=0;i<4;i++){x=p.first+pointx[i];y=p.second+pointy[i];if(x > n || x <= 0 || y > m || y <= 0 || vis[x][y] == 1){continue;}dist[x][y]=dist[p.first][p.second] + 1;q.push({x,y});}
    }
    for(int i = 1 ; i <= n ; ++i)
        for(int j = 1 ; j <= m ; ++j)
            if(dist[i][j] > max)
            {
                x = i, y = j;
                max = dist[i][j];
            }
    cout<<x<<" "<<y;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int maxn = 2e4+10;
int n,m,k,dist[maxn][maxn];
bool vis[maxn][maxn];
queue <pair<int,int>> q;
pair<int,int> p,ans;

int main()
{
	cin>>n>>m>>k;
	int x,y;
	for(int i=1;i<=k;i++){cin>>x>>y;q.push(make_pair(x,y));};
	//dfs:
	ans={20001,2001};
	dist[ans.first][ans.second] = 0;
	while(!q.empty())
	{
		p = q.front();q.pop();
		x=p.first;y=p.second;
		vis[x][y] = true;
		if(dist[x][y]>dist[ans.first][ans.second])
			ans = p;
		if(x>1 && !vis[x-1][y])
		{
			q.push(make_pair(x-1,y));
			dist[x-1][y] = dist[x][y] + 1;
		}
		if(x<n && !vis[x+1][y])
		{
			q.push(make_pair(x+1,y));
			dist[x+1][y] = dist[x][y] + 1;
		}
		if(y>1 && !vis[x][y-1])
		{
			q.push(make_pair(x,y-1));
			dist[x][y-1] = dist[x][y] + 1;
		}
		if(y<m && !vis[x][y+1])
		{
			q.push(make_pair(x,y+1));
			dist[x][y+1] = dist[x][y] + 1;
		}
	}
	cout<<ans.first<<" "<<ans.second;
	return 0;
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <stack>
#include <ctime>
#include <unordered_map>
#include <unordered_set>
#pragma comment (linker, "/STACK:256000000")

using namespace std;

const int maxN = 2100;
int d[maxN][maxN];
int n, m;

bool valid(int x, int y) {
	return 1 <= x && x <= n && 1 <= y && y <= m;
}

int dx[] = {-1, 0, 0, 1};
int dy[] = { 0,-1, 1, 0};

int main() {
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);

	scanf("%d%d", &n, &m);
	queue < pair < int, int > > q;
	int k;
	scanf("%d", &k);
	memset(d, -1, sizeof(d));
	for (int i = 1; i <= k; ++i) {
		int u, v;
		scanf("%d%d", &u, &v);
		d[u][v] = 0;
		q.push(make_pair(u, v));
	}

	while (!q.empty()) {
		pair < int, int > p = q.front();
		q.pop();
		int x = p.first;
		int y = p.second;
		for (int i = 0; i < 4; ++i) {
			int nx = x + dx[i];
			int ny = y + dy[i];
			if (valid(nx, ny) && d[nx][ny] == -1) {
				d[nx][ny] = d[x][y] + 1;
				q.push(make_pair(nx, ny));
			}
		}
	}

	int res = 0;
	int x = 1, y = 1;
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= m; ++j) {
			if (d[i][j] >= res) {
				res = d[i][j];
				x = i;
				y = j;
			}
		}
	}
	cout << x << " " << y << endl;

	return 0;
}


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

//print with endl
template <typename Arg1>
void pf(Arg1&& arg1)
{ cout<<arg1<<"\n";}
template <typename Arg1, typename... Args>
void pf(Arg1&& arg1, Args&&... args)
{ cout<<arg1<<"\n"; pf(args...); }

//print with space
template <typename Arg1>
void ps(Arg1&& arg1)
{ cout<<arg1<<" ";}
template <typename Arg1, typename... Args>
void ps(Arg1&& arg1, Args&&... args)
{ cout<<arg1<<" "; ps(args...); }

//printing via for loop
template <typename Arg1>
void pvs(Arg1&& arg1, ll n)
{ for(ll i=0;i<n;i++)ps(arg1[i]); }
template <typename Arg1>
void pvn(Arg1&& arg1, ll n)
{ for(ll i=0;i<n;i++)ps(arg1[i]); }

ll lcm(ll a,ll b)
{ return (a*b)/__gcd(a,b); }

#define fast  ios::sync_with_stdio(false); cin.tie(NULL);  cout.tie(NULL);
#define MOD 1000000007
#define MAX 1e9
#define MIN -1e9
#define rep0(i,n) for(i=0;i<n;i++)
#define rep1(i,n) for(i=1;i<=n;i++)
#define repr(i,n) for(i=n-1;i>=0;i--)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define vl vector<ll>
#define vll vector<vl>
#define vs vector<string>
#define pl pair<ll,ll>
#define vpl vector<pl>
#define f first
#define s second
#define um unordered_map
const int maxN = 2100;
int d[maxN][maxN];

int dx[] = {-1, 0, 0, 1};
int dy[] = { 0,-1, 1, 0};

bool isValid(int x, int y,int n,int m)
{ return 1 <= x && x <= n && 1 <= y && y <= m;

}
void solve()
{

    int n,m,i,j;
    scanf("%d%d", &n, &m);

    int k;
   scanf("%d", &k);
      memset(d, -1, sizeof(d));
    queue <pair<int,int>> q;
    for (int i = 1; i <= k; ++i) {

        int x,y;
        scanf("%d%d", &x, &y);
       q.push(make_pair(x, y));

        d[x][y]=0;

    }

    while(!q.empty())
    {
        int currX=q.front().first;
        int currY=q.front().second;
        q.pop();

        for(int i=0;i<4;i++)
        {
            if(isValid(currX+dx[i],currY+dy[i],n,m) && d[currX+dx[i]][currY+dy[i]]==-1)
            {
                int newX=currX+dx[i];
                int newY=currY+dy[i];

                d[newX][newY]=d[currX][currY]+1;

                q.push(make_pair(newX, newY));
            }
        }
    }
    int ans1=1,ans2=1;
    int maxi=0;
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=m;j++)
        {
            if(d[i][j]>maxi)
            {
                maxi=d[i][j];
                ans1=i;
                ans2=j;
            }
        }
    }
    cout<<ans1<<" "<<ans2<<endl;

 }
int main()
{

// 	ll t;
// 	cin>>t;
// 	while(t--)
// 	{
	   solve();
	//}
}


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

//print with endl
template <typename Arg1>
void pf(Arg1&& arg1)
{ cout<<arg1<<"\n";}
template <typename Arg1, typename... Args>
void pf(Arg1&& arg1, Args&&... args)
{ cout<<arg1<<"\n"; pf(args...); }

//print with space
template <typename Arg1>
void ps(Arg1&& arg1)
{ cout<<arg1<<" ";}
template <typename Arg1, typename... Args>
void ps(Arg1&& arg1, Args&&... args)
{ cout<<arg1<<" "; ps(args...); }

//printing via for loop
template <typename Arg1>
void pvs(Arg1&& arg1, ll n)
{ for(ll i=0;i<n;i++)ps(arg1[i]); }
template <typename Arg1>
void pvn(Arg1&& arg1, ll n)
{ for(ll i=0;i<n;i++)ps(arg1[i]); }

ll lcm(ll a,ll b)
{ return (a*b)/__gcd(a,b); }

#define fast  ios::sync_with_stdio(false); cin.tie(NULL);  cout.tie(NULL);
#define MOD 1000000007
#define MAX 1e9
#define MIN -1e9
#define rep0(i,n) for(i=0;i<n;i++)
#define rep1(i,n) for(i=1;i<=n;i++)
#define repr(i,n) for(i=n-1;i>=0;i--)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define vl vector<ll>
#define vll vector<vl>
#define vs vector<string>
#define pl pair<ll,ll>
#define vpl vector<pl>
#define f first
#define s second
#define um unordered_map

 ll d[2001][2001];

ll dx[]={-1,0,1,0};
ll dy[]={0,1,0,-1};

bool isValid(ll x, ll y,ll n,ll m)
{
    if(x<=0 || x>n || y<=0 || y>m)
    return false;

    return true;

}
void solve()
{

    ll n,m,i,j;
    cin>>n>>m;

    ll k;
    cin>>k;
      memset(d, -1, sizeof(d));
    queue <pair<ll,ll>> q;
    for(i=0;i<k;i++)
    {
        ll x,y;
        cin>>x>>y;
        q.push({x,y});

        d[x][y]=0;

    }

    while(!q.empty())
    {
        ll currX=q.front().first;
        ll currY=q.front().second;
        q.pop();

        for(ll i=0;i<4;i++)
        {
            if(isValid(currX+dx[i],currY+dy[i],n,m) && d[currX+dx[i]][currY+dy[i]]==-1)
            {
                int newX=currX+dx[i];
                int newY=currY+dy[i];

                d[newX][newY]=d[currX][currY]+1;

                q.push({newX,newY});
            }
        }
    }
    ll ans1,ans2;
    ll maxi=0;
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=m;j++)
        {
            if(d[i][j]>maxi)
            {
                maxi=d[i][j];
                ans1=i;
                ans2=j;
            }
        }
    }
    cout<<ans1<<" "<<ans2<<endl;

 }
int main()
{
    fast;
// 	ll t;
// 	cin>>t;
// 	while(t--)
// 	{
	   solve();
	//}
}


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

//print with endl
template <typename Arg1>
void pf(Arg1&& arg1)
{ cout<<arg1<<"\n";}
template <typename Arg1, typename... Args>
void pf(Arg1&& arg1, Args&&... args)
{ cout<<arg1<<"\n"; pf(args...); }

//print with space
template <typename Arg1>
void ps(Arg1&& arg1)
{ cout<<arg1<<" ";}
template <typename Arg1, typename... Args>
void ps(Arg1&& arg1, Args&&... args)
{ cout<<arg1<<" "; ps(args...); }

//printing via for loop
template <typename Arg1>
void pvs(Arg1&& arg1, ll n)
{ for(ll i=0;i<n;i++)ps(arg1[i]); }
template <typename Arg1>
void pvn(Arg1&& arg1, ll n)
{ for(ll i=0;i<n;i++)ps(arg1[i]); }

ll lcm(ll a,ll b)
{ return (a*b)/__gcd(a,b); }

#define fast  ios::sync_with_stdio(false); cin.tie(NULL);  cout.tie(NULL);
#define MOD 1000000007
#define MAX 1e9
#define MIN -1e9
#define rep0(i,n) for(i=0;i<n;i++)
#define rep1(i,n) for(i=1;i<=n;i++)
#define repr(i,n) for(i=n-1;i>=0;i--)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define vl vector<ll>
#define vll vector<vl>
#define vs vector<string>
#define pl pair<ll,ll>
#define vpl vector<pl>
#define f first
#define s second
#define um unordered_map

 int d[2100][2100];

int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};

bool isValid(int x, int y,int n,int m)
{ return 1 <= x && x <= n && 1 <= y && y <= m;

}
void solve()
{

    int n,m,i,j;
    scanf("%d%d", &n, &m);

    int k;
   scanf("%d", &k);
      memset(d, -1, sizeof(d));
    queue <pair<ll,ll>> q;
    for(i=0;i<k;i++)
    {
        int x,y;
        scanf("%d%d", &x, &y);
       q.push(make_pair(x, y));

        d[x][y]=0;

    }

    while(!q.empty())
    {
        int currX=q.front().first;
        int currY=q.front().second;
        q.pop();

        for(int i=0;i<4;i++)
        {
            if(isValid(currX+dx[i],currY+dy[i],n,m) && d[currX+dx[i]][currY+dy[i]]==-1)
            {
                int newX=currX+dx[i];
                int newY=currY+dy[i];

                d[newX][newY]=d[currX][currY]+1;

                q.push(make_pair(newX, newY));
            }
        }
    }
    int ans1=1,ans2=1;
    int maxi=0;
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=m;j++)
        {
            if(d[i][j]>maxi)
            {
                maxi=d[i][j];
                ans1=i;
                ans2=j;
            }
        }
    }
    cout<<ans1<<" "<<ans2<<endl;

 }
int main()
{

// 	ll t;
// 	cin>>t;
// 	while(t--)
// 	{
	   solve();
	//}
}


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

//print with endl
template <typename Arg1>
void pf(Arg1&& arg1)
{ cout<<arg1<<"\n";}
template <typename Arg1, typename... Args>
void pf(Arg1&& arg1, Args&&... args)
{ cout<<arg1<<"\n"; pf(args...); }

//print with space
template <typename Arg1>
void ps(Arg1&& arg1)
{ cout<<arg1<<" ";}
template <typename Arg1, typename... Args>
void ps(Arg1&& arg1, Args&&... args)
{ cout<<arg1<<" "; ps(args...); }

//printing via for loop
template <typename Arg1>
void pvs(Arg1&& arg1, ll n)
{ for(ll i=0;i<n;i++)ps(arg1[i]); }
template <typename Arg1>
void pvn(Arg1&& arg1, ll n)
{ for(ll i=0;i<n;i++)ps(arg1[i]); }

ll lcm(ll a,ll b)
{ return (a*b)/__gcd(a,b); }

#define fast  ios::sync_with_stdio(false); cin.tie(NULL);  cout.tie(NULL);
#define MOD 1000000007
#define MAX 1e9
#define MIN -1e9
#define rep0(i,n) for(i=0;i<n;i++)
#define rep1(i,n) for(i=1;i<=n;i++)
#define repr(i,n) for(i=n-1;i>=0;i--)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define vl vector<ll>
#define vll vector<vl>
#define vs vector<string>
#define pl pair<ll,ll>
#define vpl vector<pl>
#define f first
#define s second
#define um unordered_map

 ll v[2001][2001],d[2001][2001];
 ll a[2001][2001];
ll dx[]={-1,0,1,0};
ll dy[]={0,1,0,-1};

bool isValid(ll x, ll y,ll n,ll m)
{
    if(x<=0 || x>n || y<=0 || y>m)
    return false;
    if(v[x][y]==true)
    return false;

    return true;

}
void solve()
{

    ll n,m,i,j;
    cin>>n>>m;

    for(i=1;i<=n;i++)
    {
        for(j=1;j<=m;j++)
        {
            a[i][j]=0;
        }
    }
    ll k;
    cin>>k;
    queue <pair<ll,ll>> q;
    for(i=0;i<k;i++)
    {
        ll x,y;
        cin>>x>>y;
        q.push({x,y});
        v[x][y]=1;
        d[x][y]=0;

    }

    while(!q.empty())
    {
        ll currX=q.front().first;
        ll currY=q.front().second;
        q.pop();

        for(ll i=0;i<4;i++)
        {
            if(isValid(currX+dx[i],currY+dy[i],n,m))
            {
                int newX=currX+dx[i];
                int newY=currY+dy[i];

                d[newX][newY]=d[currX][currY]+1;
                v[newX][newY]=1;
                q.push({newX,newY});
            }
        }
    }
    ll ans1,ans2;
    ll maxi=0;
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=m;j++)
        {
            if(d[i][j]>maxi)
            {
                maxi=d[i][j];
                ans1=i;
                ans2=j;
            }
        }
    }
    cout<<ans1<<" "<<ans2<<endl;

 }
int main()
{
    fast;
// 	ll t;
// 	cin>>t;
// 	while(t--)
// 	{
	   solve();
	//}
}


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

//print with endl
template <typename Arg1>
void pf(Arg1&& arg1)
{ cout<<arg1<<"\n";}
template <typename Arg1, typename... Args>
void pf(Arg1&& arg1, Args&&... args)
{ cout<<arg1<<"\n"; pf(args...); }

//print with space
template <typename Arg1>
void ps(Arg1&& arg1)
{ cout<<arg1<<" ";}
template <typename Arg1, typename... Args>
void ps(Arg1&& arg1, Args&&... args)
{ cout<<arg1<<" "; ps(args...); }

//printing via for loop
template <typename Arg1>
void pvs(Arg1&& arg1, ll n)
{ for(ll i=0;i<n;i++)ps(arg1[i]); }
template <typename Arg1>
void pvn(Arg1&& arg1, ll n)
{ for(ll i=0;i<n;i++)ps(arg1[i]); }

ll lcm(ll a,ll b)
{ return (a*b)/__gcd(a,b); }

#define fast  ios::sync_with_stdio(false); cin.tie(NULL);  cout.tie(NULL);
#define MOD 1000000007
#define MAX 1e9
#define MIN -1e9
#define rep0(i,n) for(i=0;i<n;i++)
#define rep1(i,n) for(i=1;i<=n;i++)
#define repr(i,n) for(i=n-1;i>=0;i--)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define vl vector<ll>
#define vll vector<vl>
#define vs vector<string>
#define pl pair<ll,ll>
#define vpl vector<pl>
#define f first
#define s second
#define um unordered_map

 int d[2100][2100];

int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};

bool isValid(int x, int y,int n,int m)
{ return 1 <= x && x <= n && 1 <= y && y <= m;

}
void solve()
{

    int n,m,i,j;
    scanf("%d%d", &n, &m);

    int k;
   scanf("%d", &k);
      memset(d, -1, sizeof(d));
    queue <pair<int,int>> q;
    for (int i = 1; i <= k; ++i) {

        int x,y;
        scanf("%d%d", &x, &y);
       q.push(make_pair(x, y));

        d[x][y]=0;

    }

    while(!q.empty())
    {
        int currX=q.front().first;
        int currY=q.front().second;
        q.pop();

        for(int i=0;i<4;i++)
        {
            if(isValid(currX+dx[i],currY+dy[i],n,m) && d[currX+dx[i]][currY+dy[i]]==-1)
            {
                int newX=currX+dx[i];
                int newY=currY+dy[i];

                d[newX][newY]=d[currX][currY]+1;

                q.push(make_pair(newX, newY));
            }
        }
    }
    int ans1=1,ans2=1;
    int maxi=0;
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=m;j++)
        {
            if(d[i][j]>maxi)
            {
                maxi=d[i][j];
                ans1=i;
                ans2=j;
            }
        }
    }
    cout<<ans1<<" "<<ans2<<endl;

 }
int main()
{

// 	ll t;
// 	cin>>t;
// 	while(t--)
// 	{
	   solve();
	//}
}


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

//print with endl
template <typename Arg1>
void pf(Arg1&& arg1)
{ cout<<arg1<<"\n";}
template <typename Arg1, typename... Args>
void pf(Arg1&& arg1, Args&&... args)
{ cout<<arg1<<"\n"; pf(args...); }

//print with space
template <typename Arg1>
void ps(Arg1&& arg1)
{ cout<<arg1<<" ";}
template <typename Arg1, typename... Args>
void ps(Arg1&& arg1, Args&&... args)
{ cout<<arg1<<" "; ps(args...); }

//printing via for loop
template <typename Arg1>
void pvs(Arg1&& arg1, ll n)
{ for(ll i=0;i<n;i++)ps(arg1[i]); }
template <typename Arg1>
void pvn(Arg1&& arg1, ll n)
{ for(ll i=0;i<n;i++)ps(arg1[i]); }

ll lcm(ll a,ll b)
{ return (a*b)/__gcd(a,b); }

#define fast  ios::sync_with_stdio(false); cin.tie(NULL);  cout.tie(NULL);
#define MOD 1000000007
#define MAX 1e9
#define MIN -1e9
#define rep0(i,n) for(i=0;i<n;i++)
#define rep1(i,n) for(i=1;i<=n;i++)
#define repr(i,n) for(i=n-1;i>=0;i--)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define vl vector<ll>
#define vll vector<vl>
#define vs vector<string>
#define pl pair<ll,ll>
#define vpl vector<pl>
#define f first
#define s second
#define um unordered_map

 ll d[2100][2100];

ll dx[]={-1,0,1,0};
ll dy[]={0,1,0,-1};

bool isValid(ll x, ll y,ll n,ll m)
{
    if(x<=0 || x>n || y<=0 || y>m)
    return false;

    return true;

}
void solve()
{

    ll n,m,i,j;
    scanf("%lld%lld", &n, &m);

    ll k;
   scanf("%lld", &k);
      memset(d, -1, sizeof(d));
    queue <pair<ll,ll>> q;
    for(i=0;i<k;i++)
    {
        ll x,y;
        cin>>x>>y;
        q.push({x,y});

        d[x][y]=0;

    }

    while(!q.empty())
    {
        ll currX=q.front().first;
        ll currY=q.front().second;
        q.pop();

        for(ll i=0;i<4;i++)
        {
            if(isValid(currX+dx[i],currY+dy[i],n,m) && d[currX+dx[i]][currY+dy[i]]==-1)
            {
                int newX=currX+dx[i];
                int newY=currY+dy[i];

                d[newX][newY]=d[currX][currY]+1;

                q.push({newX,newY});
            }
        }
    }
    ll ans1,ans2;
    ll maxi=0;
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=m;j++)
        {
            if(d[i][j]>maxi)
            {
                maxi=d[i][j];
                ans1=i;
                ans2=j;
            }
        }
    }
    cout<<ans1<<" "<<ans2<<endl;

 }
int main()
{

// 	ll t;
// 	cin>>t;
// 	while(t--)
// 	{
	   solve();
	//}
}


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

//print with endl
template <typename Arg1>
void pf(Arg1&& arg1)
{ cout<<arg1<<"\n";}
template <typename Arg1, typename... Args>
void pf(Arg1&& arg1, Args&&... args)
{ cout<<arg1<<"\n"; pf(args...); }

//print with space
template <typename Arg1>
void ps(Arg1&& arg1)
{ cout<<arg1<<" ";}
template <typename Arg1, typename... Args>
void ps(Arg1&& arg1, Args&&... args)
{ cout<<arg1<<" "; ps(args...); }

//printing via for loop
template <typename Arg1>
void pvs(Arg1&& arg1, ll n)
{ for(ll i=0;i<n;i++)ps(arg1[i]); }
template <typename Arg1>
void pvn(Arg1&& arg1, ll n)
{ for(ll i=0;i<n;i++)ps(arg1[i]); }

ll lcm(ll a,ll b)
{ return (a*b)/__gcd(a,b); }

#define fast  ios::sync_with_stdio(false); cin.tie(NULL);  cout.tie(NULL);
#define MOD 1000000007
#define MAX 1e9
#define MIN -1e9
#define rep0(i,n) for(i=0;i<n;i++)
#define rep1(i,n) for(i=1;i<=n;i++)
#define repr(i,n) for(i=n-1;i>=0;i--)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define vl vector<ll>
#define vll vector<vl>
#define vs vector<string>
#define pl pair<ll,ll>
#define vpl vector<pl>
#define f first
#define s second
#define um unordered_map

 int d[2100][2100];

int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};

bool isValid(int x, int y,int n,int m)
{ return 1 <= x && x <= n && 1 <= y && y <= m;

}
void solve()
{

    int n,m,i,j;
    scanf("%d%d", &n, &m);

    int k;
   scanf("%d", &k);
      memset(d, -1, sizeof(d));
    queue <pair<ll,ll>> q;
    for (int i = 1; i <= k; ++i) {

        int x,y;
        scanf("%d%d", &x, &y);
       q.push(make_pair(x, y));

        d[x][y]=0;

    }

    while(!q.empty())
    {
        int currX=q.front().first;
        int currY=q.front().second;
        q.pop();

        for(int i=0;i<4;i++)
        {
            if(isValid(currX+dx[i],currY+dy[i],n,m) && d[currX+dx[i]][currY+dy[i]]==-1)
            {
                int newX=currX+dx[i];
                int newY=currY+dy[i];

                d[newX][newY]=d[currX][currY]+1;

                q.push(make_pair(newX, newY));
            }
        }
    }
    int ans1=1,ans2=1;
    int maxi=0;
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=m;j++)
        {
            if(d[i][j]>maxi)
            {
                maxi=d[i][j];
                ans1=i;
                ans2=j;
            }
        }
    }
    cout<<ans1<<" "<<ans2<<endl;

 }
int main()
{

// 	ll t;
// 	cin>>t;
// 	while(t--)
// 	{
	   solve();
	//}
}


#include <iostream>
#include <vector>
#include <stdio.h>
using namespace std;

int main()
{int m,n,i,l,s;
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
cin >> n >> m;
vector <vector <int> > x (n,vector <int> (m,10000));
cin >> s;
while (s>0) {cin >> i >> l; x[i-1][l-1]=0; s--;}
vector <vector <int> > c (n,vector <int> (m,0));
while (x!=c) {
c=x;
i=0;
while (i<n) {l=0;
while (l<m) {if (x[i][l]==s) {
if (i-1>=0&&x[i-1][l]>s+1) {x[i-1][l]=s+1;}
if (l-1>=0&&x[i][l-1]>s+1) {x[i][l-1]=s+1;}
if (l+1<m&&x[i][l+1]>s+1) {x[i][l+1]=s+1;}
if (i+1<n&&x[i+1][l]>s+1) {x[i+1][l]=s+1;}
} l++;}
i++;}
s++;}
s--;
i=0;
while (i<n) {l=0;
while (l<m) {if (x[i][l]==s) {printf("%d %d", i+1, l+1); return 0;} l++;}
i++;}
return 0;
}


#include <iostream>
#include <vector>
#include <stdio.h>
using namespace std;

int main()
{int m,n,i,l,s;
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
cin >> n >> m;
vector <vector <int> > x (n,vector <int> (m,10000));
cin >> s;
while (s>0) {cin >> i >> l; x[i-1][l-1]=0; s--;}
vector <vector <int> > c (n,vector <int> (m,0));
while (x!=c) {
c=x;
i=0;
while (i<n) {l=0;
while (l<m) {if (x[i][l]==s) {
if (i-1>=0&&x[i-1][l]>s+1) {x[i-1][l]=s+1;}
if (l-1>=0&&x[i][l-1]>s+1) {x[i][l-1]=s+1;}
if (l+1<m&&x[i][l+1]>s+1) {x[i][l+1]=s+1;}
if (i+1<n&&x[i+1][l]>s+1) {x[i+1][l]=s+1;}
} l++;}
i++;}
s++;}
s--;
i=0;
while (i<n) {l=0;
while (l<m) {if (x[i][l]==s) {printf("%d %d", i+1, l+1); return 0;} l++;}
i++;}
printf("%d %d", 1, 1);
return 0;
}


#include <iostream>
#include <vector>
#include <cstdio>
using namespace std;

int main()
{int m,n,i,l,s;
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
cin >> n >> m;
vector <vector <int> > x (n,vector <int> (m,10000));
cin >> s;
while (s>0) {cin >> i >> l; x[i-1][l-1]=0; s--;}
vector <vector <int> > c (n,vector <int> (m,0));
while (x!=c) {
c=x;
i=0;
while (i<n) {l=0;
while (l<m) {if (x[i][l]==s) {
if (i-1>=0&&x[i-1][l]>s+1) {x[i-1][l]=s+1;}
if (l-1>=0&&x[i][l-1]>s+1) {x[i][l-1]=s+1;}
if (l+1<m&&x[i][l+1]>s+1) {x[i][l+1]=s+1;}
if (i+1<n&&x[i+1][l]>s+1) {x[i+1][l]=s+1;}
} l++;}
i++;}
s++;}
s--;
i=0;
while (i<n) {l=0;
while (l<m) {if (x[i][l]==s) {cout << i+1 << ' ' << l+1; return 0;} l++;}
i++;}
return 0;
}


#include<bits/stdc++.h>
using namespace std;
queue<pair<int,int> > fire;
bool used[2100][2100];
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int main()
{
	freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
	int n,m;
	int op;
	cin>>n>>m;
	cin>>op;
	for(int i=0;i<op;i++)
	{
		int a,b;
		cin>>a>>b;
		a--;b--;
		used[a][b]=true;
		fire.push({a,b});
	}
	int l=0,o=0;
	while(!fire.empty())
	{
		pair<int,int> p=fire.front();
		fire.pop();
		l=p.first,o=p.second;
		for(int i=0;i<4;i++)
		{
			int bx=l+dx[i],by=o+dy[i];
			if(bx>=0 && bx<n && by>=0 && by<m && !used[bx][by])
			{
				fire.push({bx,by});
				used[bx][by]=true;
			}
		}
	}
	cout<<l+1<<" "<<o+1<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
queue<pair<int,int> > fire;
bool used[2101][2101];
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int main()
{
	int n,m;
	int op;
	cin>>n>>m;
	cin>>op;
	for(int i=0;i<op;i++)
	{
		int a,b;
		cin>>a>>b;
		a--;b--;
		used[a][b]=true;
		fire.push({a,b});
	}
	int l=0,o=0;
	while(!fire.empty())
	{
		pair<int,int> g=fire.front();
		fire.pop();
		l=g.first,o=g.second;
		for(int i=0;i<4;i++)
		{
			int bx=l+dx[i],by=o+dy[i];
			if(bx>=0 && bx<n && by>=0 && by<m && !used[bx][by])
			{
				fire.push({bx,by});
				used[bx][by]=true;
			}
		}
	}
	cout<<l+1<<" "<<o+1<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
queue<pair<int,int> > fire;
bool used[2200][2200];
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int main()
{
	int n,m;
	int op;
	cin>>n>>m;
	cin>>op;
	for(int i=0;i<op;i++)
	{
		int a,b;
		cin>>a>>b;
		a--;b--;
		used[a][b]=true;
		fire.push({a,b});
	}
	while(!fire.empty())
	{
		pair<int,int> p=fire.front();
		fire.pop();
		int l=p.first,o=p.second;
		for(int i=0;i<4;i++)
		{
			int bx=l+dx[i],by=o+dy[i];
			if(bx>=0 && bx<n && by>=0 && by<m && !used[bx][by])
			{
				fire.push({bx,by});
				used[bx][by]=true;
			}
		}
		if(fire.empty())
		{
			cout<<l+1<<" "<<o+1<<endl;
			return 0;
		}
	}
}


#include<bits/stdc++.h>
using namespace std;
queue<pair<int,int> > fire;
bool used[2100][2100];
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int main()
{
	int n,m;
	int op;
	cin>>n>>m;
	cin>>op;
	for(int i=0;i<op;i++)
	{
		int a,b;
		cin>>a>>b;
		a--;b--;
		used[a][b]=true;
		fire.push({a,b});
	}
	while(!fire.empty())
	{
		pair<int,int> p=fire.front();
		fire.pop();
		int l=p.first,o=p.second;
		for(int i=0;i<4;i++)
		{
			int bx=l+dx[i],by=o+dy[i];
			if(bx>=0 && bx<n && by>=0 && by<m && !used[bx][by])
			{
				fire.push({bx,by});
				used[bx][by]=true;
			}
		}
		if(fire.empty())
		{
			cout<<l+1<<" "<<o+1<<endl;
			return 0;
		}
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
queue<pair<int,int> > fire;
bool used[2100][2100];
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int main()
{
	int n,m;
	int op;
	cin>>n>>m;
	cin>>op;
	for(int i=0;i<op;i++)
	{
		int a,b;
		cin>>a>>b;
		a--;b--;
		used[a][b]=true;
		fire.push({a,b});
	}
	while(!fire.empty())
	{
		pair<int,int> p=fire.front();
		fire.pop();
		int l=p.first,o=p.second;
		for(int i=0;i<4;i++)
		{
			int bx=l+dx[i],by=o+dy[i];
			if(bx>=0 && bx<n && by>=0 && by<m && !used[bx][by])
			{
				fire.push({bx,by});
				used[bx][by]=true;
			}
		}
		if(fire.empty())
		{
			cout<<l+1<<" "<<o+1<<endl;
			return 0;
		}
	}
}


#include<bits/stdc++.h>
using namespace std;
queue<pair<int,int> > fire;
bool used[2100][2100];
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int main()
{
	int n,m;
	int op;
	cin>>n>>m;
	cin>>op;
	for(int i=0;i<op;i++)
	{
		int a,b;
		cin>>a>>b;
		a--;b--;
		used[a][b]=true;
		fire.push({a,b});
	}
	int l=0,o=0;
	while(!fire.empty())
	{
		pair<int,int> p=fire.front();
		fire.pop();
		l=p.first,o=p.second;
		for(int i=0;i<4;i++)
		{
			int bx=l+dx[i],by=o+dy[i];
			if(bx>=0 && bx<n && by>=0 && by<m && !used[bx][by])
			{
				fire.push({bx,by});
				used[bx][by]=true;
			}
		}
	}
	cout<<l+1<<" "<<o+1<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
queue<pair<int,int> > fire;
bool used[2101][2101];
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int main()
{
	int n,m;
	int op;
	cin>>n>>m;
	cin>>op;
	for(int i=0;i<op;i++)
	{
		int a,b;
		cin>>a>>b;
		a--;b--;
		used[a][b]=true;
		fire.push({a,b});
	}
	int l=0,o=0;
	while(!fire.empty())
	{
		pair<int,int> p=fire.front();
		fire.pop();
		l=p.first,o=p.second;
		for(int i=0;i<4;i++)
		{
			int bx=l+dx[i],by=o+dy[i];
			if(bx>=0 && bx<n && by>=0 && by<m && !used[bx][by])
			{
				fire.push({bx,by});
				used[bx][by]=true;
			}
		}
	}
	cout<<l+1<<" "<<o+1<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
queue<pair<int,int> > fire;
bool used[2200][2200];
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int main()
{
	int n,m;
	int op;
	cin>>n>>m;
	cin>>op;
	for(int i=0;i<op;i++)
	{
		int a,b;
		cin>>a>>b;
		a--;b--;
		used[a][b]=true;
		fire.push({a,b});
	}
	int l=0,o=0;
	while(!fire.empty())
	{
		pair<int,int> p=fire.front();
		fire.pop();
		l=p.first,o=p.second;
		for(int i=0;i<4;i++)
		{
			int bx=l+dx[i],by=o+dy[i];
			if(bx>=0 && bx<n && by>=0 && by<m && !used[bx][by])
			{
				fire.push({bx,by});
				used[bx][by]=true;
			}
		}
	}
	cout<<l+1<<" "<<o+1<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
queue<pair<int,int> > fire;
bool used[2100][2100];
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int main()
{
	int n,m;
	int op;
	cin>>n>>m;
	cin>>op;
	for(int i=0;i<op;i++)
	{
		int a,b;
		cin>>a>>b;
		a--;b--;
		used[a][b]=true;
		fire.push({a,b});
	}
	int l=0,o=0;
	while(!fire.empty())
	{
		pair<int,int> p=fire.front();
		fire.pop();
		l=p.first,o=p.second;
		for(int i=0;i<4;i++)
		{
			int bx=l+dx[i],by=o+dy[i];
			if(bx>=0 && bx<n && by>=0 && by<m && !used[bx][by])
			{
				fire.push({bx,by});
				used[bx][by]=true;
			}
		}
	}
	cout<<l+1<<" "<<o+1<<endl;
	exit(0);
}


#include<bits/stdc++.h>
using namespace std;
queue<pair<int,int> > fire;
bool used[2100][2100];
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int n,m;
int op;
void go()
{
	int l=0,o=0;
	while(!fire.empty())
	{
		pair<int,int> p=fire.front();
		fire.pop();
		l=p.first,o=p.second;
		for(int i=0;i<4;i++)
		{
			int bx=l+dx[i],by=o+dy[i];
			if(bx>=0 && bx<n && by>=0 && by<m && !used[bx][by])
			{
				fire.push({bx,by});
				used[bx][by]=true;
			}
		}
	}
	cout<<l+1<<" "<<o+1<<endl;
}
int main()
{
	cin>>n>>m;
	cin>>op;
	for(int i=0;i<op;i++)
	{
		int a,b;
		cin>>a>>b;
		a--;b--;
		used[a][b]=true;
		fire.push({a,b});
	}
	int l=0,o=0;
	go();
	return 0;
}


#include <iostream>
#include <iomanip>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <vector>
#include <queue>
using namespace std;

bool visited[2000][2000];
int x[4]={1,-1,0,0};
int y[4]={0,0,-1,1};

int bfs(int src_i ,int src_j)
{

}

int main()
{
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    int n,m,k;
    cin>>m>>n>>k;

    queue<int> qi;
    queue<int> qj;
    for(int i=0;i<k;i++)
    {
        int x,y;
        cin>>x>>y;
        qi.push(x-1);
        qj.push(y-1);
        visited[x-1][y-1]=1;
    }

    int ii,jj,si,sj;
    while(!qi.empty())
    {

        int xi,yj;
        xi = qi.front();
        yj = qj.front();
        qi.pop();
        qj.pop();
        visited[xi][yj]=1;
        for(int i=0;i<4;i++)
        {
            ii = xi + x[i];
            jj = yj + y[i];

            if(ii>=n||jj>=m||ii<0||jj<0||visited[ii][jj])
            {

                continue;
            }

            si = ii;
            sj = jj;
            qi.push(ii);
            qj.push(jj);
        }
    }

    cout<<si+1<<" "<<sj+1;
    return 0;
}


#include <iostream>
#include <iomanip>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <vector>
#include <queue>
using namespace std;

bool visited[2000][2000];
int x[4]={1,-1,0,0};
int y[4]={0,0,-1,1};

int bfs(int src_i ,int src_j)
{

}

int main()
{
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);

    int n,m,k;
    cin>>n>>m>>k;

    queue<int> qi;
    queue<int> qj;
    for(int i=0;i<k;i++)
    {
        int x,y;
        cin>>x>>y;
        qi.push(x-1);
        qj.push(y-1);

    }

    int ii,jj,si=qi.front(),sj=qj.front();
    while(!qi.empty())
    {

        int xi,yj;
        xi = qi.front();
        yj = qj.front();
        qi.pop();
        qj.pop();
        if(visited[xi][yj])
            continue;

        visited[xi][yj]=1;
        si = xi;
        sj = yj;
        for(int i=0;i<4;i++)
        {
            ii = xi + x[i];
            jj = yj + y[i];

            if(ii<n&&jj<m&&ii>=0&&jj>=0&&!visited[ii][jj])
            {

                    qi.push(ii);
                    qj.push(jj);
            }

        }
    }

    cout<<si+1<<" "<<sj+1;
    return 0;
}


#include <iostream>
#include <iomanip>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <vector>
#include <queue>
using namespace std;

bool visited[2000][2000];
int x[4]={1,-1,0,0};
int y[4]={0,0,-1,1};

int bfs(int src_i ,int src_j)
{

}

int main()
{
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    int n,m,k;
    cin>>m>>n>>k;

    queue<int> qi;
    queue<int> qj;
    for(int i=0;i<k;i++)
    {
        int x,y;
        cin>>x>>y;
        qi.push(x-1);
        qj.push(y-1);
        visited[x-1][y-1]=1;
    }

    int ii,jj,si=qi.front(),sj=qj.front();
    while(!qi.empty())
    {

        int xi,yj;
        xi = qi.front();
        yj = qj.front();
        qi.pop();
        qj.pop();
        if(visited[xi][yj])
            continue;

        si = xi;
        sj = yj;
        visited[xi][yj]=1;
        for(int i=0;i<4;i++)
        {
            ii = xi + x[i];
            jj = yj + y[i];

            if(ii<n&&jj<m&&ii>=0&&jj>=0)
            {
                    qi.push(ii);
                    qj.push(jj);

                continue;
            }

        }
    }

    cout<<si+1<<" "<<sj+1;
    return 0;
}


#include <iostream>
#include <iomanip>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <vector>
#include <queue>
using namespace std;

bool visited[2000][2000];
int x[4]={1,-1,0,0};
int y[4]={0,0,-1,1};

int bfs(int src_i ,int src_j)
{

}

int main()
{
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    int n,m,k;
    cin>>m>>n>>k;

    queue<int> qi;
    queue<int> qj;
    for(int i=0;i<k;i++)
    {
        int x,y;
        cin>>x>>y;
        qi.push(x-1);
        qj.push(y-1);
        visited[x-1][y-1]=1;
    }

    int ii,jj,si=qi.front(),sj=qj.front();
    while(!qi.empty())
    {

        int xi,yj;
        xi = qi.front();
        yj = qj.front();
        qi.pop();
        qj.pop();
        if(visited[xi][yj])
            continue;
        visited[xi][yj]=1;
        for(int i=0;i<4;i++)
        {
            ii = xi + x[i];
            jj = yj + y[i];

            if(ii<n&&jj<m&&ii>=0&&jj>=0)
            {
                    si = ii;
                    sj = jj;
                    qi.push(ii);
                    qj.push(jj);

                continue;
            }

        }
    }

    cout<<si+1<<" "<<sj+1;
    return 0;
}


#include <iostream>
#include <iomanip>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <vector>
#include <queue>
using namespace std;

bool visited[2000][2000];
int x[4]={1,-1,0,0};
int y[4]={0,0,-1,1};

int bfs(int src_i ,int src_j)
{

}

int main()
{
    int n,m,k;
    cin>>m>>n>>k;
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    queue<int> qi;
    queue<int> qj;
    for(int i=0;i<k;i++)
    {
        int x,y;
        cin>>x>>y;
        qi.push(x-1);
        qj.push(y-1);
        visited[x-1][y-1]=1;
    }

    int ii,jj,si,sj;
    while(!qi.empty())
    {

        int xi,yj;
        xi = qi.front();
        yj = qj.front();
        qi.pop();
        qj.pop();
        visited[xi][yj]=1;
        for(int i=0;i<4;i++)
        {
            ii = xi + x[i];
            jj = yj + y[i];

            if(ii>=n||jj>=m||ii<0||jj<0||visited[ii][jj])
            {

                continue;
            }

            si = ii;
            sj = jj;
            qi.push(ii);
            qj.push(jj);
        }
    }

    cout<<si+1<<" "<<sj+1;
    return 0;
}


#include <iostream>
#include <iomanip>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <vector>
#include <queue>
using namespace std;

bool visited[2000][2000];
int x[4]={1,-1,0,0};
int y[4]={0,0,-1,1};

int bfs(int src_i ,int src_j)
{

}

int main()
{
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    int n,m,k;
    cin>>m>>n>>k;

    queue<int> qi;
    queue<int> qj;
    for(int i=0;i<k;i++)
    {
        int x,y;
        cin>>x>>y;
        qi.push(x-1);
        qj.push(y-1);

    }

    int ii,jj,si=qi.front(),sj=qj.front();
    while(!qi.empty())
    {

        int xi,yj;
        xi = qi.front();
        yj = qj.front();
        qi.pop();
        qj.pop();
        if(visited[xi][yj])
            continue;

        si = xi;
        sj = yj;
        visited[xi][yj]=1;
        for(int i=0;i<4;i++)
        {
            ii = xi + x[i];
            jj = yj + y[i];

            if(ii<n&&jj<m&&ii>=0&&jj>=0)
            {
                    qi.push(ii);
                    qj.push(jj);

                continue;
            }

        }
    }

    cout<<si+1<<" "<<sj+1;
    return 0;
}


#include <iostream>
#include <iomanip>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <vector>
#include <queue>
using namespace std;

bool visited[2000][2000];
int x[4]={1,-1,0,0};
int y[4]={0,0,-1,1};

int bfs(int src_i ,int src_j)
{

}

int main()
{
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);

    int n,m,k;
    cin>>n>>m>>k;

    queue<int> qi;
    queue<int> qj;
    for(int i=0;i<k;i++)
    {
        int x,y;
        cin>>x>>y;
        qi.push(x-1);
        qj.push(y-1);

    }

    int ii,jj,si=qi.front(),sj=qj.front();
    while(!qi.empty())
    {

        int xi,yj;
        xi = qi.front();
        yj = qj.front();
        qi.pop();
        qj.pop();
        if(visited[xi][yj])
            continue;

        visited[xi][yj]=1;

        for(int i=0;i<4;i++)
        {
            ii = xi + x[i];
            jj = yj + y[i];

            if(ii<n&&jj<m&&ii>=0&&jj>=0&&!visited[ii][jj])
            {
                si = ii;
                sj = jj;
                    qi.push(ii);
                    qj.push(jj);
            }

        }
    }

    cout<<si+1<<" "<<sj+1;
    return 0;
}


#include <iostream>
#include <iomanip>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <vector>
#include <queue>
using namespace std;

bool visited[2000][2000];
int x[4]={1,-1,0,0};
int y[4]={0,0,-1,1};

int bfs(int src_i ,int src_j)
{

}

int main()
{
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    int n,m,k;
    cin>>m>>n>>k;

    queue<int> qi;
    queue<int> qj;
    for(int i=0;i<k;i++)
    {
        int x,y;
        cin>>x>>y;
        qi.push(x-1);
        qj.push(y-1);
        visited[x-1][y-1]=1;
    }

    int ii,jj,si=qi.front(),sj=qj.front();
    while(!qi.empty())
    {

        int xi,yj;
        xi = qi.front();
        yj = qj.front();
        qi.pop();
        qj.pop();
        if(visited[xi][yj])
            continue;

        si = ii;
        sj = jj;
        visited[xi][yj]=1;
        for(int i=0;i<4;i++)
        {
            ii = xi + x[i];
            jj = yj + y[i];

            if(ii<n&&jj<m&&ii>=0&&jj>=0)
            {
                    qi.push(ii);
                    qj.push(jj);

                continue;
            }

        }
    }

    cout<<si+1<<" "<<sj+1;
    return 0;
}


#include <iostream>
#include <iomanip>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <vector>
#include <queue>
using namespace std;

bool visited[2000][2000];
int x[4]={1,-1,0,0};
int y[4]={0,0,-1,1};

int bfs(int src_i ,int src_j)
{

}

int main()
{
    int n,m,k;
    cin>>m>>n>>k;

    queue<int> qi;
    queue<int> qj;
    for(int i=0;i<k;i++)
    {
        int x,y;
        cin>>x>>y;
        qi.push(x-1);
        qj.push(y-1);
        visited[x-1][y-1]=1;
    }

    int ii,jj,si,sj;
    while(!qi.empty())
    {
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<m;j++)
            {
                cout<<visited[i][j];
            }
            cout<<endl;
        }
        cout<<endl;
        int xi,yj;
        xi = qi.front();
        yj = qj.front();
        qi.pop();
        qj.pop();
        visited[xi][yj]=1;
        for(int i=0;i<4;i++)
        {
            ii = xi + x[i];
            jj = yj + y[i];

            if(ii>=n||jj>=m||ii<0||jj<0||visited[ii][jj])
            {

                cout<<ii<<" "<<jj<<" deon\n";
                continue;
            }

            si = ii;
            sj = jj;
            qi.push(ii);
            qj.push(jj);
        }
    }

    cout<<si+1<<" "<<sj+1;
    return 0;
}


#include <iostream>
#include <iomanip>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <vector>
#include <queue>
using namespace std;

bool visited[2000][2000];
int x[4]={1,-1,0,0};
int y[4]={0,0,-1,1};

int bfs(int src_i ,int src_j)
{

}

int main()
{
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    int n,m,k;
    cin>>m>>n>>k;

    queue<int> qi;
    queue<int> qj;
    for(int i=0;i<k;i++)
    {
        int x,y;
        cin>>x>>y;
        qi.push(x-1);
        qj.push(y-1);
        visited[x-1][y-1]=1;
    }

    int ii,jj,si=qi.front(),sj=qj.front();
    while(!qi.empty())
    {

        int xi,yj;
        xi = qi.front();
        yj = qj.front();
        qi.pop();
        qj.pop();
        visited[xi][yj]=1;
        for(int i=0;i<4;i++)
        {
            ii = xi + x[i];
            jj = yj + y[i];

            if(ii>=n||jj>=m||ii<0||jj<0||visited[ii][jj])
            {

                continue;
            }

            si = ii;
            sj = jj;
            qi.push(ii);
            qj.push(jj);
        }
    }

    cout<<si+1<<" "<<sj+1;
    return 0;
}


#include <iostream>
#include <iomanip>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <vector>
#include <queue>
using namespace std;

bool visited[2000][2000];
int x[4]={1,-1,0,0};
int y[4]={0,0,-1,1};

int bfs(int src_i ,int src_j)
{

}

int main()
{
    int n,m,k;
    cin>>m>>n>>k;

    queue<int> qi;
    queue<int> qj;
    for(int i=0;i<k;i++)
    {
        int x,y;
        cin>>x>>y;
        qi.push(x-1);
        qj.push(y-1);
        visited[x-1][y-1]=1;
    }

    int ii,jj,si,sj;
    while(!qi.empty())
    {

        int xi,yj;
        xi = qi.front();
        yj = qj.front();
        qi.pop();
        qj.pop();
        visited[xi][yj]=1;
        for(int i=0;i<4;i++)
        {
            ii = xi + x[i];
            jj = yj + y[i];

            if(ii>=n||jj>=m||ii<0||jj<0||visited[ii][jj])
            {

                continue;
            }

            si = ii;
            sj = jj;
            qi.push(ii);
            qj.push(jj);
        }
    }

    cout<<si+1<<" "<<sj+1;
    return 0;
}


#include<cstdio>
#include<algorithm>
using namespace std;
int main()
{
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    int n,m,p,x[10],y[10],xT,yT,S=-1;
    scanf("%d%d%d",&n,&m,&p);
    for(int i=0;i<p;i++)scanf("%d%d",x+i,y+i);
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
        {
            int T=n+m;
            for(int k=0;k<p;k++)T=min(T,abs(i-x[k])+abs(j-y[k]));
            if(T>S)S=T,xT=i,yT=j;
        }
    printf("%d %d\n",xT,yT);
    return 0;
}


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

const int MAXN = 2005;
const int INF = 1e9;
bool mark[MAXN][MAXN];
int gx, gy;
int lastx, lasty;
queue<pair<int,int>> que;

void bfs() {
  while (!que.empty()) {
    auto p = que.front();
    que.pop();
    int x = p.first;
    int y = p.second;
    mark[x][y] = true;
    //cerr << x << ' ' << y << endl;
    lastx = x; lasty = y;

    int dx[] = {0, 1, 0, -1};
    int dy[] = {1, 0, -1, 0};

    for (int i = 0; i < 4; i++) {
      int xx = x + dx[i];
      int yy = y + dy[i];
      if (xx <= gx && xx >= 1 && yy <= gy && yy >= 1)
      if (!mark[xx][yy]) {
        que.push({xx, yy});
      }
    }
  }
}

int main() {
  cin >> gx >> gy;
  ifstream cin("input.txt");
  ofstream cout("output.txt");

  int n; cin >> n;

  for (int i = 0; i < n; i++) {
    int x, y; cin >> x >> y;
    que.push({x, y});
  }

  bfs();

  cout << lastx << ' ' << lasty << endl;
  return 0;
}


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

const int MAXN = 2005;
const int INF = 1e9;
bool mark[MAXN][MAXN];
int gx, gy;
int lastx, lasty;
queue<pair<int,int>> que;

void bfs() {
  for (auto p: pairs) que.push(p);

  while (!que.empty()) {
    auto p = que.front();
    que.pop();
    int x = p.first, y = p.second;
    mark[x][y] = true;
    //cerr << x << ' ' << y << endl;
    lastx = x; lasty = y;

    int dx[] = {0, 1, 0, -1};
    int dy[] = {1, 0, -1, 0};

    for (int i = 0; i < 4; i++) {
      int xx = x + dx[i], yy = y + dy[i];
      if (xx <= gx && xx >= 1 && yy <= gy && yy >= 1)
      if (!mark[xx][yy]) {
        que.push({xx, yy});
      }
    }
  }
}

int main() {
  cin >> gx >> gy;
  ifstream cin("input.txt");
  ofstream cout("output.txt");

  int n; cin >> n;

  for (int i = 0; i < n; i++) {
    int x, y; cin >> x >> y;
    que.push({x, y});
  }

  bfs();

  cout << lastx << ' ' << lasty << endl;
  return 0;
}


By Huber, contest: Codeforces Beta Round #35 (Div. 2), problem: (C) Fire Again, Compilation error, #

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

const int MAXN = 2005;
const int INF = 1e9;
bool mark[MAXN][MAXN];
int gx, gy;
int lastx, lasty;
queue<pair<int,int>> que;

void bfs() {
  while (!que.empty()) {
    auto p = que.front();
    que.pop();
    int x = p.first, y = p.second;
    mark[x][y] = true;
    //cerr << x << ' ' << y << endl;
    lastx = x; lasty = y;

    int dx[] = {0, 1, 0, -1};
    int dy[] = {1, 0, -1, 0};

    for (int i = 0; i < 4; i++) {
      int xx = x + dx[i], yy = y + dy[i];
      if (xx <= gx && xx >= 1 && yy <= gy && yy >= 1)
      if (!mark[xx][yy]) {
        que.push({xx, yy});
      }
    }
  }
}

int main() {
  cin >> gx >> gy;
  ifstream cin("input.txt");
  ofstream cout("output.txt");

  int n; cin >> n;

  for (int i = 0; i < n; i++) {
    int x, y; cin >> x >> y;
    que.push({x, y});
  }

  bfs();

  cout << lastx << ' ' << lasty << endl;
  return 0;
}


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

const int MAXN = 2005;
const int INF = 1e9;
bool mark[MAXN][MAXN];
int gx, gy;
int lastx, lasty;
queue<pair<int,int>> que;

void bfs() {
  while (!que.empty()) {
    auto p = que.front();
    que.pop();
    int x = p.first, y = p.second;
    mark[x][y] = true;
    //cerr << x << ' ' << y << endl;
    lastx = x; lasty = y;

    int dx[] = {0, 1, 0, -1};
    int dy[] = {1, 0, -1, 0};

    for (int i = 0; i < 4; i++) {
      int xx = x + dx[i], yy = y + dy[i];
      if (xx <= gx && xx >= 1 && yy <= gy && yy >= 1)
      if (!mark[xx][yy]) {
        que.push({xx, yy});
      }
    }
  }
}

int main() {
  cin >> gx >> gy;
  ifstream cin("input.txt");
  ofstream cout("output.txt");

  int n; cin >> n;

  for (int i = 0; i < n; i++) {
    int x, y; cin >> x >> y;
    que.push({x, y});
  }

  bfs();

  cout << lastx << ' ' << lasty << endl;
  return 0;
}


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

const int MAXN = 2005;
const int INF = 1e9;
bool mark[MAXN][MAXN];
int gx, gy;
int lastx, lasty;

void bfs(vector<pair<int, int>> pairs) {
  queue<pair<int,int>> que;
  for (auto p: pairs) que.push(p);

  while (!que.empty()) {
    auto p = que.front();
    que.pop();
    int x = p.first, y = p.second;
    mark[x][y] = true;
    //cerr << x << ' ' << y << endl;
    lastx = x; lasty = y;

    int dx[] = {0, 1, 0, -1};
    int dy[] = {1, 0, -1, 0};

    for (int i = 0; i < 4; i++) {
      int xx = x + dx[i], yy = y + dy[i];
      if (xx <= gx && xx >= 1 && yy <= gy && yy >= 1)
      if (!mark[xx][yy]) {
        que.push({xx, yy});
      }
    }
  }
}

int main() {
  cin >> gx >> gy;
  int n; cin >> n;
  vector<pair<int, int>> pairs;

  for (int i = 0; i < n; i++) {
    int x, y; cin >> x >> y;
    pairs.push_back({x, y});
  }

  bfs(pairs);

  cout << lastx << ' ' << lasty << endl;
  return 0;
}


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

const int MAXN = 2005;
const int INF = 1e9;
bool mark[MAXN][MAXN];
int gx, gy;
int lastx, lasty;

void bfs(vector<pair<int, int>> pairs) {
  queue<pair<int,int>> que;
  for (auto p: pairs) que.push(p);

  while (!que.empty()) {
    auto p = que.front();
    que.pop();
    int x = p.first, y = p.second;
    mark[x][y] = true;
    //cerr << x << ' ' << y << endl;
    lastx = x; lasty = y;

    int dx[] = {0, 1, 0, -1};
    int dy[] = {1, 0, -1, 0};

    for (int i = 0; i < 4; i++) {
      int xx = x + dx[i], yy = y + dy[i];
      if (xx <= gx && xx >= 1 && yy <= gy && yy >= 1)
      if (!mark[xx][yy]) {
        que.push({xx, yy});
      }
    }
  }
}

int main() {
  cin >> gx >> gy;
  ifstream cin("input.txt");
  ofstream cout("output.txt");

  int n; cin >> n;
  vector<pair<int, int>> pairs;

  for (int i = 0; i < n; i++) {
    int x, y; cin >> x >> y;
    pairs.push_back({x, y});
  }

  bfs(pairs);

  cout << lastx << ' ' << lasty << endl;
  return 0;
}


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

const int MAXN = 2005;
const int INF = 1e9;
bool mark[MAXN][MAXN];
int gx, gy;
int lastx, lasty;
queue<pair<int,int>> que;

void bfs() {
  while (!que.empty()) {
    auto p = que.front();
    que.pop();
    int x = p.first;
    int y = p.second;
    mark[x][y] = true;
    //cerr << x << ' ' << y << endl;
    lastx = x; lasty = y;

    int dx[] = {0, 1, 0, -1};
    int dy[] = {1, 0, -1, 0};

    for (int i = 0; i < 4; i++) {
      int xx = x + dx[i], yy = y + dy[i];
      if (xx <= gx && xx >= 1 && yy <= gy && yy >= 1)
      if (!mark[xx][yy]) {
        que.push({xx, yy});
      }
    }
  }
}

int main() {
  cin >> gx >> gy;
  ifstream cin("input.txt");
  ofstream cout("output.txt");

  int n; cin >> n;

  for (int i = 0; i < n; i++) {
    int x, y; cin >> x >> y;
    que.push({x, y});
  }

  bfs();

  cout << lastx << ' ' << lasty << endl;
  return 0;
}


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

const int MAXN = 2005;
const int INF = 1e9;
bool mark[MAXN][MAXN];
int gx, gy;
int lastx, lasty;

void bfs(vector<pair<int, int>> pairs) {
  queue<pair<int,int>> que;
  for (auto p: pairs) que.push(p);

  while (!que.empty()) {
    auto p = que.front();
    que.pop();
    int x = p.first, y = p.second;
    mark[x][y] = true;
    //cerr << x << ' ' << y << endl;
    lastx = x; lasty = y;

    int dx[] = {0, 1, 0, -1};
    int dy[] = {1, 0, -1, 0};

    for (int i = 0; i < 4; i++) {
      int xx = x + dx[i], yy = y + dy[i];
      if (xx <= gx && xx >= 1 && yy <= gy && yy >= 1)
      if (!mark[xx][yy]) {
        que.push({xx, yy});
      }
    }
  }
}

int main() {
  cin >> gx >> gy;
  ifstream cin("input.txt");
  ofstream cout("output.txt");

  int n; cin >> n;
  vector<pair<int, int>> pairs;

  for (int i = 0; i < n; i++) {
    int x, y; cin >> x >> y;
    pairs.push_back({x, y});
  }

  bfs(pairs);

  cout << lastx << ' ' << lasty << endl;
  return 0;
}


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

const int MAXN = 2005;
const int INF = 1e9;
bool mark[MAXN][MAXN];
int gx, gy;
int lastx, lasty;
queue<pair<int,int>> que;

void bfs() {
  while (!que.empty()) {
    auto p = que.front();
    que.pop();
    int x = p.first;
    int y = p.second;
    mark[x][y] = true;
    //cerr << x << ' ' << y << endl;
    lastx = x; lasty = y;

    int dx[] = {0, 1, 0, -1};
    int dy[] = {1, 0, -1, 0};

    for (int i = 0; i < 4; i++) {
      int xx = x + dx[i];
      int yy = y + dy[i];
      if (xx <= gx && xx >= 1 && yy <= gy && yy >= 1) {
          if (!mark[xx][yy]) {
            que.push({xx, yy});
          }
      }
    }
  }
}

int main() {
  cin >> gx >> gy;
  ifstream cin("input.txt");
  ofstream cout("output.txt");

  int n; cin >> n;

  for (int i = 0; i < n; i++) {
    int x, y; cin >> x >> y;
    que.push({x, y});
  }

  bfs();

  cout << lastx << ' ' << lasty << endl;
  return 0;
}


#include <stdio.h>
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    ll n,m,k;
    freopen("input.txt", "rt", stdin);
    freopen("output.txt", "wt", stdout);
    cin >> n >> m >> k;

    map<pair<ll,ll>,ll> vis;
    queue<pair<ll,ll> > q;
    for(ll i=0;i<k;i++)
    {
        ll x,y;
        cin >> x >> y;
        q.push(make_pair(x,y));
        vis[make_pair(x,y)]=1;

    }
    ll x,y,cnt=k;
    while(!q.empty())
    {
         pair<ll,ll> p=q.front();

         x=p.first;
         y=p.second;
         if(cnt==n*m){ cout << x << " " << y; return 0;}
         if(x-1>0 && vis[make_pair(x-1,y)]!=1)
         { q.push(make_pair(x-1,y)); vis[make_pair(x-1,y)]=1; cnt++; if(cnt==n*m){ cout << x-1 << " " << y; return 0;}}
         if(x+1<=m && vis[make_pair(x+1,y)]!=1)
         { q.push(make_pair(x+1,y)); vis[make_pair(x+1,y)]=1; cnt++; if(cnt==n*m){ cout << x+1 << " " << y; return 0;}}
         if(y-1>0 && vis[make_pair(x,y-1)]!=1)
         { q.push(make_pair(x,y-1)); vis[make_pair(x,y-1)]=1; cnt++; if(cnt==n*m){ cout << x << " " << y-1; return 0;}}
         if(y+1<=n && vis[make_pair(x,y+1)]!=1)
         { q.push(make_pair(x,y+1)); vis[make_pair(x,y+1)]=1; cnt++; if(cnt==n*m){ cout << x << " " << y+1; return 0;}}
         q.pop();

    }

}


#include <stdio.h>
#include<bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));
typedef long long int ll;
const int N=2005;
bool vis[N][N];
int main()
{
    FAST;
    ll n,m,k;

    freopen("input.txt", "rt", stdin);
    freopen("output.txt", "wt", stdout);
    cin >> n >> m >> k;
   pair<int, int> last;
    queue<pair<ll,ll> > q;
    for(ll i=0;i<k;i++)
    {
        ll x,y;
        cin >> x >> y;
        q.push(make_pair(x,y));
        vis[x][y]=true;
        last=make_pair(x,y);

    }
    ll x,y,cnt=k;
    while(!q.empty())
    {
         pair<ll,ll> p=q.front();
                  q.pop();

         last=p;
         x=p.first;
         y=p.second;

        // cout << x << " " << y << endl;
         if(cnt==n*m){ cout << x << " " << y; return 0;}
         if(x-1>0 && vis[x-1][y]!=true )
         { q.push(make_pair(x-1,y)); vis[x-1][y]=true;  }
         if(x+1<=m && vis[x+1][y]!=true )
         { q.push(make_pair(x+1,y)); vis[x+1][y]=true; }
         if(y-1>0 && vis[x][y-1]!=true)
         { q.push(make_pair(x,y-1)); vis[x][y-1]=true; }
         if(y+1<=n && vis[x][y+1]!=true)
         { q.push(make_pair(x,y+1)); vis[x][y+1]=true; }

    }
    cout << last.first << " " << last.second;

}


#include <stdio.h>
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    ll n,m,k;
    cin >> n >> m >> k;

    map<pair<ll,ll>,ll> vis;
    queue<pair<ll,ll> > q;
    for(ll i=0;i<k;i++)
    {
        ll x,y;
        cin >> x >> y;
        q.push(make_pair(x,y));
        vis[make_pair(x,y)]=1;
    }
    ll x,y,cnt=k;
    while(!q.empty())
    {
         pair<ll,ll> p=q.front();
         x=p.first;
         y=p.second;
         if(x-1>0 && vis[make_pair(x-1,y)]!=1)
         { q.push(make_pair(x-1,y)); vis[make_pair(x-1,y)]=1; cnt++; if(cnt==n*m){ cout << x-1 << " " << y; return 0;}}
         if(x+1<=m && vis[make_pair(x+1,y)]!=1)
         { q.push(make_pair(x+1,y)); vis[make_pair(x+1,y)]=1; cnt++; if(cnt==n*m){ cout << x+1 << " " << y; return 0;}}
         if(y-1>0 && vis[make_pair(x,y-1)]!=1)
         { q.push(make_pair(x,y-1)); vis[make_pair(x,y-1)]=1; cnt++; if(cnt==n*m){ cout << x << " " << y-1; return 0;}}
         if(y+1<=n && vis[make_pair(x,y+1)]!=1)
         { q.push(make_pair(x,y+1)); vis[make_pair(x,y+1)]=1; cnt++; if(cnt==n*m){ cout << x << " " << y+1; return 0;}}
         q.pop();

    }

}


#include <stdio.h>
#include<bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));
typedef long long int ll;
const int N=2005;
bool vis[N][N];
int main()
{
    FAST;
    ll n,m,k;

    freopen("input.txt", "rt", stdin);
    freopen("output.txt", "wt", stdout);
    cin >> n >> m >> k;

    queue<pair<ll,ll> > q;
    for(ll i=0;i<k;i++)
    {
        ll x,y;
        cin >> x >> y;
        q.push(make_pair(x,y));
        vis[x][y]=true;

    }
    ll x,y,cnt=k;
    while(!q.empty())
    {
         pair<ll,ll> p=q.front();

         x=p.first;
         y=p.second;
         if(cnt==n*m){ cout << x << " " << y; return 0;}
         if(x-1>0 && vis[x-1][y]!=true)
         { q.push(make_pair(x-1,y)); vis[x-1][y]=true; cnt++; if(cnt==n*m){ cout << x-1 << " " << y; return 0;}}
         if(x+1<=m && vis[x+1][y]!=true)
         { q.push(make_pair(x+1,y)); vis[x+1][y]=true; cnt++; if(cnt==n*m){ cout << x+1 << " " << y; return 0;}}
         if(y-1>0 && vis[x][y-1]!=true)
         { q.push(make_pair(x,y-1)); vis[x][y-1]=true; cnt++; if(cnt==n*m){ cout << x << " " << y-1; return 0;}}
         if(y+1<=n && vis[x][y+1]!=true)
         { q.push(make_pair(x,y+1)); vis[x][y+1]=true; cnt++; if(cnt==n*m){ cout << x << " " << y+1; return 0;}}
         q.pop();

    }

}


#include <stdio.h>
#include<bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));
typedef long long int ll;
int main()
{
    FAST;
    ll n,m,k;

    freopen("input.txt", "rt", stdin);
    freopen("output.txt", "wt", stdout);
    cin >> n >> m >> k;

    map<pair<ll,ll>,ll> vis;
    queue<pair<ll,ll> > q;
    for(ll i=0;i<k;i++)
    {
        ll x,y;
        cin >> x >> y;
        q.push(make_pair(x,y));
        vis[make_pair(x,y)]=1;

    }
    ll x,y,cnt=k;
    while(!q.empty())
    {
         pair<ll,ll> p=q.front();

         x=p.first;
         y=p.second;
         if(cnt==n*m){ cout << x << " " << y; return 0;}
         if(x-1>0 && vis[make_pair(x-1,y)]!=1)
         { q.push(make_pair(x-1,y)); vis[make_pair(x-1,y)]=1; cnt++; if(cnt==n*m){ cout << x-1 << " " << y; return 0;}}
         if(x+1<=m && vis[make_pair(x+1,y)]!=1)
         { q.push(make_pair(x+1,y)); vis[make_pair(x+1,y)]=1; cnt++; if(cnt==n*m){ cout << x+1 << " " << y; return 0;}}
         if(y-1>0 && vis[make_pair(x,y-1)]!=1)
         { q.push(make_pair(x,y-1)); vis[make_pair(x,y-1)]=1; cnt++; if(cnt==n*m){ cout << x << " " << y-1; return 0;}}
         if(y+1<=n && vis[make_pair(x,y+1)]!=1)
         { q.push(make_pair(x,y+1)); vis[make_pair(x,y+1)]=1; cnt++; if(cnt==n*m){ cout << x << " " << y+1; return 0;}}
         q.pop();

    }

}


#include <stdio.h>
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    ll n,m,k;
     freopen("input.txt", "rt", stdin);
    freopen("output.txt", "wt", stdout);
    cin >> n >> m >> k;

    map<pair<ll,ll>,ll> vis;
    queue<pair<ll,ll> > q;
    for(ll i=0;i<k;i++)
    {
        ll x,y;
        cin >> x >> y;
        q.push(make_pair(x,y));
        vis[make_pair(x,y)]=1;
    }
    ll x,y,cnt=k;
    while(!q.empty())
    {
         pair<ll,ll> p=q.front();
         x=p.first;
         y=p.second;
         if(x-1>0 && vis[make_pair(x-1,y)]!=1)
         { q.push(make_pair(x-1,y)); vis[make_pair(x-1,y)]=1; cnt++; if(cnt==n*m){ cout << x-1 << " " << y; return 0;}}
         if(x+1<=m && vis[make_pair(x+1,y)]!=1)
         { q.push(make_pair(x+1,y)); vis[make_pair(x+1,y)]=1; cnt++; if(cnt==n*m){ cout << x+1 << " " << y; return 0;}}
         if(y-1>0 && vis[make_pair(x,y-1)]!=1)
         { q.push(make_pair(x,y-1)); vis[make_pair(x,y-1)]=1; cnt++; if(cnt==n*m){ cout << x << " " << y-1; return 0;}}
         if(y+1<=n && vis[make_pair(x,y+1)]!=1)
         { q.push(make_pair(x,y+1)); vis[make_pair(x,y+1)]=1; cnt++; if(cnt==n*m){ cout << x << " " << y+1; return 0;}}
         q.pop();

    }

}


#include <stdio.h>
#include<bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));
typedef long long int ll;
const int N=2005;
bool vis[N][N];
int main()
{
    FAST;
    ll n,m,k;

    freopen("input.txt", "rt", stdin);
    freopen("output.txt", "wt", stdout);
    cin >> n >> m >> k;
   pair<int, int> last;
    queue<pair<ll,ll> > q;
    for(ll i=0;i<k;i++)
    {
        ll x,y;
        cin >> x >> y;
        q.push(make_pair(x,y));
        vis[x][y]=true;

    }
    ll x,y,cnt=k;
    while(!q.empty())
    {
         pair<ll,ll> p=q.front();
                  q.pop();

         last=p;
         x=p.first;
         y=p.second;

        // cout << x << " " << y << endl;
         //if(cnt==n*m){ cout << x << " " << y; return 0;}
         if(x>=1&&x<=n&&y+1>=1&&y+1<=m && vis[x][y+1]!=true )
         { q.push(make_pair(x,y+1)); vis[x][y+1]=true;  }
         if(x>=1&&x<=n&&y-1>=1&&y-1<=m && vis[x][y-1]!=true )
         { q.push(make_pair(x,y-1)); vis[x][y-1]=true; }
         if(x+1>=1&&x+1<=n&&y>=1&&y<=m && vis[x+1][y]!=true)
         { q.push(make_pair(x+1,y)); vis[x+1][y]=true; }
         if(x-1>=1&&x-1<=n&&y>=1&&y<=m && vis[x-1][y]!=true)
         { q.push(make_pair(x-1,y)); vis[x-1][y]=true; }

    }
    cout << last.first << " " << last.second;

}


#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <unordered_map>
using namespace std;
#define ll long long
const int N = 1e5 + 7;

int n, m, k, cnt;
unordered_map<pair<int, int>, int> vis;
queue<pair<int, int>> q;
int r[] = { 0, -1, 0, 1 };
int c[] = { -1, 0, 1, 0 };
bool ok(int r, int c) {
    return r > 0 && r <= n && c > 0 && c <= m;
}

void print() {
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= m; ++j) {
            if (!vis[{i, j}]) {
                printf("%d %d\n", i, j);
            }
        }
    }
}

int main() {
    cin.sync_with_stdio(false);
    cin.tie(0);
    freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    cin >> n >> m >> k;
    for (int i = 0; i < k; ++i) {
        if (cnt == n * m - 1) {
            print();
            return 0;
        }
        int a, b; cin >> a >> b;
        vis[{a, b}] ++;
        cnt++;
        q.push({ a, b });
    }
    while (q.size()) {
        auto v = q.front();
        q.pop();
        if (cnt == n * m - 1) {
            print();
            return 0;
        }
        for (int i = 0; i < 4; i++) {
            int nr = v.first + r[i], nc = v.second + c[i];
            //printf("%d %d\n", nr, nc);
            if (!vis[{nr, nc}] && ok(nr, nc)) {
                q.push({ nr, nc });
                vis[{nr, nc}]++;
                ++cnt;
            }
        }
    }
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 1e5 + 7;

int n, m, k, cnt;
map<pair<int,int>, int> vis;
queue<pair<int, int>> q;
int r[] = { 0, -1, 0, 1 };
int c[] = { -1, 0, 1, 0 };
bool ok(int r, int c) {
    return r >= 0 && r < n && c >= 0 && c < m;
}

int main() {
    cin.sync_with_stdio(false);
    cin.tie(0);
    freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    cin >> n >> m >> k;
    for (int i = 0; i < k; ++i) {
        int a, b; cin >> a >> b;
        vis[{a, b}] ++;
        cnt++;
        q.push({ a, b });
    }
    while (q.size()) {
        auto v = q.front();
        q.pop();
        for (int i = 0; i < 4; i++) {
            int nr = v.first + r[i], nc = v.second + c[i];
            if (!vis[{nr, nc}] && ok(nr, nc)) {
                q.push({ nr, nc });
                vis[{nr, nc}]++;
                ++cnt;
                if (cnt == n*m - 1) {
                    for (int i = 1; i <= n; ++i) {
                        for (int j = 1; j <= m; ++j) {
                            if (!vis[{i, j}]) {
                                printf("%d %d\n", i, j);
                                return 0;
                            }
                        }
                    }
                }
            }
        }
    }
    /*for (auto it : vis) {
        printf("%d %d %d\n", it.first.first, it.first.second, it.second);
        if (!it.second) {
            printf("%d %d", it.first.first, it.first.second);
            break;
        }
    }*/
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 2e3 + 7;

int n, m, k, x, y, node;
int vis[N][N];
int r[] = {0, -1, -1, -1, 0, 1, 1, 1};
int c[] = {-1, -1, 0, 1, 1, 1, 0, -1};

bool ok(int r, int c) {
    return r>=0 && c >=0 && r<n && c<m && !vis[r][c];
}
void ans() {
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            if (!vis[i][j]) {
                cout << i+1 << ' ' << j+1;
                return;
            }
        }
    }
}
vector<pair<int, int>> v;
void mark() {
    for (int i = 0; i < v.size(); i++) {
        vis[v[i].first][v[i].second] = 1;
    }
    v.clear();
}
int main() {
    cin.sync_with_stdio(false);
    freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    cin >> n >> m >> k;
    for (int i = 0; i < k; i++) {
        cin >> x >> y;
        vis[x][y] = 1;
    }
    if (node == n * m - 1) {
        ans();
        return 0;
    }
    while (1) {
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if (vis[i][j] == 1) {
                    for (int x = 0; x < 8; x++) {
                        int nr = i + r[x], nc = j + c[x];
                        if (ok(nr, nc))v.push_back({ nr, nc });
                        if (node == n * m - 1) {
                            mark();
                            ans();
                            return 0;
                        }
                        node++;
                    }
                }
            }
        }
        mark();
    }
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 2e3 + 7;

int n, m, k, cnt;
int vis[N][N];
queue<pair<int, int>> q;
int r[] = { 0, -1, 0, 1 };
int c[] = { -1, 0, 1, 0 };
bool ok(int r, int c) {
    return r > 0 && r <= n && c > 0 && c <= m;
}

void print() {
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= m; ++j) {
            if (!vis[i][j]) {
                printf("%d %d\n", i, j);
            }
        }
    }
}

int main() {
    cin.sync_with_stdio(false);
    cin.tie(0);
    freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    cin >> n >> m >> k;
    for (int i = 0; i < k; ++i) {
        if (cnt == n * m - 1) {
            print();
            return 0;
        }
        int a, b; cin >> a >> b;
        vis[a][b] ++;
        cnt++;
        q.push({ a, b });
    }
    while (q.size()) {
        auto v = q.front();
        q.pop();
        if (cnt == n * m - 1) {
            print();
            return 0;
        }
        for (int i = 0; i < 4; i++) {
            int nr = v.first + r[i], nc = v.second + c[i];
            if (!vis[nr][nc] && ok(nr, nc)) {
                //printf("%d %d\n", nr, nc);
                q.push({ nr, nc });
                vis[nr][nc]++;
                ++cnt;
            }
        }
    }
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main()
{
    int n,a[100010],i,sum=0,s;
    cin>>n;
    for(i=1; i<n; i++)
    {
        cin>>a[i];
        sum=sum+a[i];
    }
    s=(n*(n+1))/2;
    cout<<s-sum<<endl;
    return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;
int main(){
	int n;
	cin >> n;
	int a[n];
	for( int i = 1 ; i < n ; i++ ){
		cin >> a[i];
	}
	sort(a+1, a+n+1);
	for( int i = 1; i < n; i++ ){
		if(a[i] != i){
			cout << i ;
			break;
		}
		else if(a[i] < i){
			return 0;
		}
	}
}


#include <iostream>
#include <algorithm>
using namespace std;
int main(){
	int n;
	cin >> n;
	int a[n];
	for( int i = 1 ; i < n ; i++ ){
		cin >> a[i];
	}
	sort(a+1, a+n+1);
	for( int i = 1; i < n; i++ ){
		if(a[i] != i){
			cout << i ;
			break;
		}
	}
}


#include <iostream>
#include <algorithm>
using namespace std;
int main(){
	int n ;
	cin >> n;
	int a[n];
	for(int i = 1; i < n; i++)
	{
		cin >> a[i];
	}
	sort(a+1, a+n);
	bool is = false;
	for(int i = 1 ; i < n; i++){
		if(a[i] == n){
			is = true;
			break;
		}
	}
	if(is == true){
		for( int i = 1; i < n; i++ ){
			if(a[i] != i){
				cout << i;
				break;
			}
		}
	}
	else{
		cout << n;
	}
}


#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
    int n;
    cin>>n;
    int arr[n+1];
    for(int i=0; i<n-1; i++)cin>>arr[i];
    int forgottenEpisode =0;
    sort(arr, arr + n);
    for(int i=1; i<n; i++){
        if(arr[i] - 2 == arr[i - 1]){
            forgottenEpisode = arr[i] -1 ;
            break;
        }
    }
    cout<<forgottenEpisode<<endl;
   return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int main()
{
    int n;
    cin>>n;
    vector<int>v;
    for(int i=1; i<=n; i++){
        v.push_back(i);
    }

    int broj;
    vector<int> broevi;
    for(int i = 1; i<n; i++){
    cin>>broj;
    broevi.push_back(broj);

    }
    for(int i=0; i<n; i++){
        if(find(broevi.begin(), broevi.end(), v[i]) == broevi.end()){
            cout<<v[i]<<endl;
            return 0;
        }
    }

   return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(int argc, const char * argv[]) {
    int n;
    cin >> n;
    int arr[n];
    for(int i=0; i<n-1; i++)
    {
        cin>>arr[i];
    }
    int num = -1;
    sort(arr, arr+ n);
    for(int i=0; i<n-1; i++){
        if(arr[i] +2 == arr[i + 1] && i < n-1){
            num = arr[i+1] - 1;
        }
    }
    int sz = n - 1;
    if(num != -1){
        cout<<num<<endl;
        return 0;
    }
    if(num == -1){
        num = arr[0] -1

        ;
        if(num == 0){
            cout<<arr[sz-1] + 1<<endl;
        }
        else cout<<num<<endl;
    }
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
using namespace std;

int main(int argc, const char * argv[]) {
    ios_base::sync_with_stdio(false);
    int arr[100002]
    ;
    int n;
    cin>>n;
    int br;
    memset(arr, 0, sizeof arr);
    for(int i=0;i<n-1; i++){
        cin>>br;
        arr[br] ++;
    }
    for(int i=1; i<=n; i++){
        if(arr[i] ==0 ){
            cout<<i<<endl;
            return 0;
        }
    }
    return 0;
}


//
//  main.cpp
//  ForgottenEpisodeCodeForces
//
//  Created by Josif Tepegjozov on 8/28/15.
//  Copyright (c) 2015 Tepe. All rights reserved.
//

#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(int argc, const char * argv[]) {
    int n;
    cin >> n;
    vector<int> arr;
    for(int i =0; i<n-1; i++){
        int a;
        cin >> a;
        arr.push_back(a);
    }
    vector<int> nums;
    sort(arr.begin(), arr.end());
    for(int i=1; i<=n; i++){
        nums.push_back(i);
    }
    for(int i=0, j=0; i<=n-1, j<n; i++, j++){
        if(arr[i] == nums[j]){
            nums[j] = 0;
        }
    }
    nums.erase(remove(nums.begin(), nums.end(), 0), nums.end());
    cout << nums[0] << endl;

    return 0;
}


#include <iostream>
#include <vector>
// not done
using namespace std;

int main() {
    int n, x;
    cin >> n;
    vector<int> ep;
    for (int i=1; i < n; ++i) {
        cin >> x;
        ep.push_back(x);
    }
    int z = n;
    ++n;
    sort(ep.begin(), ep.end());
    while (--n) {
        unsigned a=0, b=z-2, m=(b-a)/2;
        while (b-a > 1) {
            if (n <= ep[m]) b=m;
            else a=m;
            m=(b+a)/2;
        }
        if (ep[a] != n && ep[b] != n) {
            cout << n << endl;
            n = 1;
        }
    }
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
// not done
using namespace std;

int main() {
    int n, x;
    cin >> n;
    vector<int> ep;
    for (int i=1; i < n; ++i) {
        cin >> x;
        ep.push_back(x);
    }
    int z = n;
    ++n;
    sort(ep.begin(), ep.end());
    while (--n) {
        unsigned a=0, b=z-2, m=(b-a)/2;
        while (b-a > 1) {
            if (n <= ep[m]) b=m;
            else a=m;
            m=(b+a)/2;
        }
        if (ep[a] != n && ep[b] != n) {
            cout << n << endl;
            n = 1;
        }
    }
    return 0;
}


#include<cstdio>
int n,ans;
int main()
{
    scanf("%d",&n);
    for(int i=1,tmp;i<n;i++)
    {
        scanf("%d",&tmp);
        ans^=tmp;
    }
    printf("%d\n",ans);
    return 0;
}


#include<cstdio>
int n,ans;
int main()
{
    scanf("%d",&n);
    for(int i=1,tmp;i<2*n;i++)
    {
        scanf("%d",&tmp);
        ans^=tmp;
    }
    printf("%d\n",ans);
    return 0;
}


#include<cstdio>
int n,ans;
int main()
{
    scanf("%d",&n);
    for(int i=1,tmp;i<n;i++)
    {
        scanf("%d",&tmp);
        ans^=tmp^i;
    }
    printf("%d\n",ans^n);
    return 0;
}


#include<iostream>
using namespace std;
int main()
{long long int m,i,n,sum=0;
cin>>m;
int a[m];
n=(m*(m+1))/2;
for(i=0;i<(m-1);i++)
{cin>>a[i];
sum=sum+a[i];}
cout<<n-sum;}


#include<iostream>
using namespace std;
int main()
{int m,i,n,sum=0;
cin>>m;
int a[m];
n=(m*(m+1))/2;
for(i=0;i<(m-1);i++)
{cin>>a[i];
sum=sum+a[i];}
cout<<n-sum;}


#include <bits/stdc++.h>

using namespace std;

int main()
{ int n;
cin>>n;
int a[n-1];
for(int i=0;i<n-1;i++)
    cin>>a[i];
sort(a,a+n-1);
//for(int i=0;i<n-1;i++) cout<<a[i];
for(int i=1;i<n-1;i++){
    if(a[i]!=a[i-1]+1){
        cout<<a[i]-1;
        break;
    }
}
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{ int n;
cin>>n;
int a[n-1];
for(int i=0;i<n-1;i++)
    cin>>a[i];
sort(a,a+n-1);
//for(int i=0;i<n-1;i++) cout<<a[i];
bool t=1;
if(n==2&&a[0]==2) cout<<1;
else{
for(int i=1;i<n-1;i++){
    if(a[i]!=a[i-1]+1){
         t=0;
        cout<<a[i]-1;
        break;
    }
}
if(t) cout<<n;}
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{ int n;
cin>>n;
int a[n-1];
for(int i=0;i<n-1;i++)
    cin>>a[i];
sort(a,a+n-1);
//for(int i=0;i<n-1;i++) cout<<a[i];
bool t=1;
if(n==2&&a[0]==2) cout<<1;
else{
 if(a[0]!=1) cout<<1;
else{
for(int i=1;i<n-1;i++){
    if(a[i]!=a[i-1]+1){
         t=0;
        cout<<a[i]-1;
        break;
    }
}
if(t) cout<<n;}
}
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{ int n;
cin>>n;
int a[n-1];
for(int i=0;i<n-1;i++)
    cin>>a[i];
sort(a,a+n-1);
//for(int i=0;i<n-1;i++) cout<<a[i];
bool t=1;
for(int i=1;i<n-1;i++){
    if(a[i]!=a[i-1]+1){
         t=0;
        cout<<a[i]-1;
        break;
    }
}
if(t) cout<<n;
    return 0;
}


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

int main()
{

int n;
cin >> n;
int a[n+5] ;
int sum = 0;
for(int i = 0 ; i<n-1 ; i++)
{
    cin >> a[i];
}
for(int i = 0 ; i<n-1 ; i++)
{
    sum = sum + a[i];
}
int x = ((1+n)*n)/2 ;
int y = x - sum;
cout << y << endl;
}


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

int main()
{

long long int n;
cin >> n;
int a[n+5] ;
long long int sum = 0;
for(int i = 0 ; i<n-1 ; i++)
{
    cin >> a[i];
}
for(int i = 0 ; i<n-1 ; i++)
{
    sum = sum + a[i];
}
long long int x = ((n+1)*n)/2;
long long int y = x - sum;
cout << y << endl;
}


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

int main()
{

int n;
cin >> n;
int a[n+5] ;
long long int sum = 0;
for(int i = 0 ; i<n-1 ; i++)
{
    cin >> a[i];
}
for(int i = 0 ; i<n-1 ; i++)
{
    sum = sum + a[i];
}
long long int x = ((n+1)*n)/2;
long long int y = x - sum;
cout << y << endl;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,episodes[100009],ch[100005];
    while(scanf("%d",&n)==1)
    {
        for(int i=0;i<n-1;i++)
        {
            scanf("%d",&episodes[i]);
        }
        int p=0;
         for(int i=0;i<=n;i++)
        {
            ch[p++]=i+1;
        }
        sort(episodes,episodes+(n-1));

         for(int i=0;i<n;i++)
        {
            if(episodes[i]!=ch[i])
            {
                printf("%d\n",ch[i]);
                break;
            }
        }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,episodes[100009];
    while(scanf("%d",&n)==1)
    {
        for(int i=0;i<n-1;i++)
        {
            scanf("%d",&episodes[i]);
        }
        sort(episodes,episodes+(n-1));

        int dif=0;
         for(int i=0;i<n-1;i++)
        {
            dif = episodes[i+1]-episodes[i];
            if(dif>1)
            {
                int e = episodes[i]+1;
                printf("%d\n",e);
                break;
            }

            if(i==n-2)
            {
                int e = episodes[i]+1;
                printf("%d\n",e);
                break;
            }
        }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,episodes[100009];
    while(scanf("%d",&n)==1)
    {
        for(int i=0;i<n-1;i++)
        {
            scanf("%d",&episodes[i]);
        }
        sort(episodes,episodes+(n-1));

        int dif=0;
         for(int i=0;i<n-1;i++)
        {
            dif = episodes[i+1]-episodes[i];
            if(dif>1)
            {
                int e = episodes[i]+1;
                printf("%d\n",e);
                break;
            }
        }
    }
    return 0;
}


#include<iostream>
#include<stdio.h>

using namespace std;

int main()
{//freopen("i.txt","r",stdin);
 long long n; cin>>n;
 long long s=n*(n+1)/2;
 long long s1=0;
 for(long long i=1;i<=n-1;i++)
  {long long x; cin>>x; s1+=x;}
 cout<<s-s1;
return 0;
}


#include<iostream>
#include<stdio.h>
using namespace std;
int main()
{//freopen("i.txt","r",stdin);
bool a[100005]={0};
 int n; cin>>n;
 for(int i=1;i<=n-1;i++)
  {int i0; cin>>i0; a[i0]=1;}
 for (int i=1;i<=n;i++)
  if (a[i]==0) {cout<<i; return 0;}

return 0;
}


#include<iostream>
#include<stdio.h>
using namespace std;
int main()
{ //freopen("i.txt","r",stdin);
int a[100005];
 int n; cin>>n;
 for(int i=1;i<=n-1;i++) cin>>a[i];
 for (int b=1;b<=n;b++)
 {bool f=0;
   for(int i=1;i<=n-1;i++)
   if (a[i]==b) {f=1; break;}
  if (f==0) {cout<<b; return 0;}
 }
return 0;
}


#include<iostream>
#include<stdio.h>
using namespace std;
int main()
{//freopen("i.txt","r",stdin);
 int n; cin>>n;
 int s=n*(n+1)/2;
 int s1=0;
 for(int i=1;i<=n-1;i++)
  {int x; cin>>x; s1+=x;}
 cout<<s-s1;
return 0;
}


#include<iostream>
#include<cstring>
using namespace std;
int a[100010];
bool flag[100010];
int main(){
	int n;
	cin>>n;
	memset(flag,false,sizeof(flag));
	for(int i=1;i<n;i++)
	{
		cin>>a[i];
		flag[a[i]]=true;
	}
	for(int i=1;i<=n;i++)
		if(flag[i]==false)
		{
			cout<<i;
			return 0;
		}
	return 0;
}


#include<iostream>
#include<cstring>
using namespace std;
int main(){
	int n;
	cin>>n;
	int a[n+2];
	bool flag[n+2];
	memset(flag,false,sizeof(flag));
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		flag[a[i]]=true;
	}
	for(int i=1;i<=n;i++)
		if(flag[i]==false)
		{
			cout<<i;
			return 0;
		}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int a[10000000],n,u;
int main(){
    cin>>n;
    for(int i=1;i<=n;i++)cin>>u,a[u]=1;
    for(int i=1;i<=n;i++){if(a[i]==0)cout<<i;return 0;}
}


#include<bits/stdc++.h>
using namespace std;//fucl
int n;
int main(){
    cin>>n;
    if(n%3==0) cout<<n/3+2;
    else cout<<n/3*2+1;
    return 0;
}


#include<bits/stdc++.h>//sssssas
using namespace std;
int n;
int main(){
    cin>>n;
    if(n%3==0) cout<<n/3+2;
    else cout<<n/3*2+1;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int a[10000000],n,u;
int main(){
    cin>>n;
    for(int i=1;i<=n;i++)cin>>u,a[u]=1;
    for(int i=1;i<=n;i++)if(a[i]==0){cout<<i;return 0;}
}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){

	int n; cin >> n;
	vector<int>vec;
	for (int i = 0; i<n - 1; i++){
		int x; cin >> x;
		vec.push_back(x);
	}
	sort(vec.begin(), vec.end());
	for (int i = n - 2; i - 1 >= 0; i--){
		if (vec[i] - vec[i - 1] != 1){
			cout << (vec[i - 1] + vec[i]) / 2 << endl; return 0;
		}
	}
	if (vec[n - 2] == n)cout << 1 << endl;
	else cout << n;
	return 0;
}
//#include <iostream>
//#include <algorithm>
//#include <iomanip>
//#include <vector>
//#include <string>
//using namespace std;
//int main(){
//
//	string s1, s2;
//	cin >> s1 >> s2;
//	int p1 = 0, n1 = 0, q2 = 0, p2 = 0, n2 = 0, res1 = 0, res2 = 0;
//	for (int i = 0; i < s1.size(); i++){
//		if (s1[i] == '+')p1++, res1++;
//		else if (s1[i] == '-')n1++, res1--;
//	}
//	for (int i = 0; i < s2.size(); i++){
//		if (s2[i] == '+')p2++, res2++;
//		else if (s2[i] == '-')n2++, res2--;
//		else q2++;
//	}
//	if (res2 == res1 && !q2){
//		cout << 1 << ".000000000000" << endl;
//		return 0;
//	}
//
//	return 0;
//}


#include <iostream>
#include <vector>
using namespace std;
int main(){

    int n;cin>>n;
    for(int i=0;i<n-1;i++){
        int x;cin>>x;
        vec.push_back(x);
    }
    sort(vec.begin(),vec.end());
    for(int i=n-2;i-1>=0;i--){
        if(vec[i]-vec[i-1]!=1){
            cout <<vec[i-1]+vec[i]/2<<endl; return 0;
        }
    }

    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){

	int n; cin >> n;
	for (int i = 0; i<n - 1; i++){
		int x; cin >> x;
		vec.push_back(x);
	}
	sort(vec.begin(), vec.end());
	for (int i = n - 2; i - 1 >= 0; i--){
		if (vec[i] - vec[i - 1] != 1){
			cout << vec[i - 1] + vec[i] / 2 << endl; return 0;
		}
	}

	return 0;
}
//#include <iostream>
//#include <algorithm>
//#include <iomanip>
//#include <vector>
//#include <string>
//using namespace std;
//int main(){
//
//	string s1, s2;
//	cin >> s1 >> s2;
//	int p1 = 0, n1 = 0, q2 = 0, p2 = 0, n2 = 0, res1 = 0, res2 = 0;
//	for (int i = 0; i < s1.size(); i++){
//		if (s1[i] == '+')p1++, res1++;
//		else if (s1[i] == '-')n1++, res1--;
//	}
//	for (int i = 0; i < s2.size(); i++){
//		if (s2[i] == '+')p2++, res2++;
//		else if (s2[i] == '-')n2++, res2--;
//		else q2++;
//	}
//	if (res2 == res1 && !q2){
//		cout << 1 << ".000000000000" << endl;
//		return 0;
//	}
//
//	return 0;
//}


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

 int main()
 {
    int n;
    cin >> n;
    int c[n + 10000];
    int ans=0;
    for ( int i = 1; i < n; ++i ) cin >> c[i],ans += c[i];
    cout << (n * (n + 1) / 2) - ans;
}


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

 int main()
 {
    long long n;
    cin >> n;
    long long c[n + 10000];
    long long ans=0;
    for ( int i = 1; i < n; ++i ) cin >> c[i],ans += c[i];
    cout << (n * (n + 1) / 2) - ans;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a[10000];
    int n,sum=0,total,i;
    cin>>n;
    for(i=0;i<n-1;i++)
    {
        scanf("%d",&a[i]);
        sum=sum+a[i];

    }
    total=(n*(n+1))/2;
    cout<<total-sum;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a[100000];
    int n,sum=0,total,i;
    cin>>n;
    for(i=0;i<n-1;i++)
    {
        scanf("%d",&a[i]);
        sum=sum+a[i];

    }
    total=(n*(n+1))/2;
    cout<<total-sum;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a[100000];
    long long int n,sum=0,total,i;
    cin>>n;
    for(i=0;i<n-1;i++)
    {
        scanf("%d",&a[i]);
        sum=sum+a[i];

    }
    total=(n*(n+1))/2;
    cout<<total-sum;
}


#include <iostream>
#include <cstring>
#include <vector>
#include <cmath>
#include <algorithm>

/*Macros para mayor facilidad*/
#define gl(cad) getline(cin,cad)
#define debug(X) cout<<#X<<" = "<<X<<endl
#define forn(X,i) for(int i=0; i<X;i++)
#define sz(cad) (int) cad.size()
#define str(cad) (int) strlen(cad)

using namespace std;

typedef vector<int> veci;
typedef vector<int,int> vecii;
typedef long long ll;

int main(){
	ll n;
	cin>>n;
	ll num;
	veci myv;
	for(int i=1;i<n;i++){
		cin>>num;
		myv.push_back(num);
	}
	veci::iterator it;
	for(int i=1;i<=n;i++){
		it=find(myv.begin(),myv.end(),i);
		if(it==myv.end()){
			cout<<i;
			return 0;
		}
	}
	//system("PAUSE");system("cls");main();
	return 0;
}