/*
 * In The Name Of ALLAH
 * created by Harolinch
 */
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <iomanip>

#include <algorithm>
#include <list>
#include <vector>
#include <stack>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <numeric>

#include <math.h>
#include <stdlib.h>
#include <assert.h>
#include <limits.h>
#include <memory.h>
#include <ctype.h>
#include <string.h>
using namespace std;

typedef long long lint;

typedef vector<lint> vecl;

#define	elin			'\n'

#define all(v)			(v).begin(), (v).end()

#define rep(i, a, n)	for(int i = a; i<=n; i++)

class Solution {
public:
    void solve(std::istream& in, std::ostream& out) {
		int n;
		in >> n;

		lint sum = 0;
		vecl seq(n, 0);
		rep(i, 0, n - 1) {
			in >> seq[i];
			sum += seq[i];
		}
		sort(all(seq));
		reverse(all(seq));
		rep(i, 1, n - 1) seq[i] += seq[i - 1]; //prefix sum

		lint up = 1;
		lint ans = 0;
		while(up < n){
			ans += (sum + seq[up - 1]);
			up *= 4;
		}
		if(n > 4) ans -= sum;
		if(n == 1) ans = sum;
		out << ans << elin;
		return;
    }
};

void solve(std::istream& in, std::ostream& out)
{
    out << std::setprecision(12);
    Solution solution;
    solution.solve(in, out);
}

int main() {

    ios_base::sync_with_stdio(0);
    cin.tie(0);

    istream& in = cin;

    ostream& out = cout;

    solve(in, out);
    return 0;
}


/*
 * In The Name Of ALLAH
 * created by Harolinch
 */
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <iomanip>

#include <algorithm>
#include <list>
#include <vector>
#include <stack>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <numeric>

#include <math.h>
#include <stdlib.h>
#include <assert.h>
#include <limits.h>
#include <memory.h>
#include <ctype.h>
#include <string.h>
using namespace std;

typedef long long lint;

typedef vector<lint> vecl;

#define	elin			'\n'

#define all(v)			(v).begin(), (v).end()

#define rep(i, a, n)	for(int i = a; i<=n; i++)

class Solution {
public:
    void solve(std::istream& in, std::ostream& out) {
		int n;
		in >> n;

		lint sum = 0;
		vecl seq(n, 0);
		rep(i, 0, n - 1) {
			in >> seq[i];
			sum += seq[i];
		}
		sort(all(seq));
		reverse(all(seq));
		rep(i, 1, n - 1) seq[i] += seq[i - 1]; //prefix sum

		lint down = n;
		lint cnt = 1;
		lint ans = 0;
		if(down == 1){
			ans = sum;
		}
		else{
			while(down > 0){
				ans += seq[cnt - 1];
				down /= 4;
				cnt *= 4;
			}
		}
		out << ans << elin;

		return;
    }
};

void solve(std::istream& in, std::ostream& out)
{
    out << std::setprecision(12);
    Solution solution;
    solution.solve(in, out);
}

int main() {

    ios_base::sync_with_stdio(0);
    cin.tie(0);

    istream& in = cin;

    ostream& out = cout;

    solve(in, out);
    return 0;
}


/*
 * In The Name Of ALLAH
 * created by Harolinch
 */
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <iomanip>

#include <algorithm>
#include <list>
#include <vector>
#include <stack>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <numeric>

#include <math.h>
#include <stdlib.h>
#include <assert.h>
#include <limits.h>
#include <memory.h>
#include <ctype.h>
#include <string.h>
using namespace std;

typedef long long lint;

typedef vector<lint> vecl;

#define	elin			'\n'

#define all(v)			(v).begin(), (v).end()

#define rep(i, a, n)	for(int i = a; i<=n; i++)

class Solution {
public:
    void solve(std::istream& in, std::ostream& out) {
		int n;
		in >> n;

		lint sum = 0;
		vecl seq(n, 0);
		rep(i, 0, n - 1) {
			in >> seq[i];
			sum += seq[i];
		}
		sort(all(seq));
		reverse(all(seq));
		rep(i, 1, n - 1) seq[i] += seq[i - 1]; //prefix sum
		int t = n;
		int lg4 = 0;
		while(t != 1){
			t /= 4;
			lg4++;
		}

		lint ans = 0;
		if(lg4 >= 1) ans = sum * (lg4 - 1);
		else ans = sum;
		while(n != 1){
			n /= 4;
			ans += seq[n - 1];
		}
		out << ans << elin;
		return;
    }
};

void solve(std::istream& in, std::ostream& out)
{
    out << std::setprecision(12);
    Solution solution;
    solution.solve(in, out);
}

int main() {

    ios_base::sync_with_stdio(0);
    cin.tie(0);

    istream& in = cin;

    ostream& out = cout;

    solve(in, out);
    return 0;
}


#include<iostream>
#include<fstream>
#define f first
#define s second
using namespace std;
bool mark[2000+10][2000+10];
pair<int,int>a[10000000+10];
int n,m,k;
long int size;
ifstream fin("input.txt");
ofstream fout("output.txt");
int main()
{
	fin>>n>>m>>k;
	for(int i=1;i<=k;i++)
	{
		int v,c;
		fin>>v>>c;
		mark[v][c]=1;
		a[size]=make_pair(v,c);
		size++;
	}
	for(int i=0;i<size;i++)
	{
		int q=a[i].f;//i
		int w=a[i].s;//
		mark[q][w]=1;

		if(q>1&&mark[q-1][w]==0)
		{
			a[size]=make_pair((q-1),w);
			mark[q-1][w]=1;
			size++;
		}
		if(w>1&&mark[q][w-1]==0)
		{
			a[size]=make_pair(q,(w-1));
			mark[q][w-1]=1;
			size++;
		}
		if(q<n&&mark[q+1][w]==0)
		{

			a[size]=make_pair((q+1),w);
			mark[q+1][w]=1;
			size++;
		}
		if(w<m&&mark[q][w+1]==0)
		{
			a[size]=make_pair(q,(w+1));
			mark[q][w+1]=1;
			size++;
		}

	}
	//for(int i=0;i<size;i++)
	//fout<<a[i].f<<" "<<a[i].s<<endl;
	fout<<a[size-1].f<<" "<<a[size-1].s<<endl;
//	1 1 1 1 1 1
//i	1 1 1 1 1 1
//	1 1 1 1 1 1
//	1 1 1 1 1 1
//	1 1 1 1 1 1

}


#include<bits/stdc++.h>

using namespace std;

const int N=2e4;
int n,m;
int dis[N][N];
int dr[]={0,1,0,-1};
int dc[]={-1,0,1,0};
pair<int,int> ans;
vector<pair<int,int>>start;
bool valid(int r,int c){
    return r>=0 && c>=0 && r<m && c<n;
}
void bfs(){
    memset(dis,-1,sizeof dis);
    queue<pair<int,int>>q;
    for(int i=0;i<start.size();i++){
        q.push({start[i].first,start[i].second});
        dis[start[i].first][start[i].second]=0;
    }
    ans={q.front().first,q.front().second};
    while(!q.empty()){
        pair<int,int> u=q.front();
        if(dis[u.first][u.second]>dis[ans.first][ans.second]){
            ans={u.first,u.second};
        }
        q.pop();
        for(int i=0;i<4;i++){
            int vr=dis[u.first][u.second]+dr[i];
            int vc=dis[u.first][u.second]+dc[i];
            if(valid(vr,vc)&&dis[vr][vc]==-1){
                dis[vr][vc]=dis[u.first][u.second]+1;
                q.push({vr,vc});
            }
        }
    }
}
int main() {
    std::ifstream I("input.txt");
    std::ofstream O("output.txt");
    I>>n>>m;
    int k;
    I>>k;
    while(k--){
        int i,j;
        I>>i>>j;
        i--,j--;
        start.push_back({i,j});
    }
    bfs();
    O<<ans.first+1<<" "<<ans.second+1;
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

const int N=2e4;
int n,m;
int dis[N][N];
int dr[]={0,1,0,-1};
int dc[]={-1,0,1,0};
pair<int,int> ans;
vector<pair<int,int>>start;
bool valid(int r,int c){
    return r>=0 && c>=0 && r<m && c<n;
}
void bfs(){
    memset(dis,-1,sizeof dis);
    queue<pair<int,int>>q;
    for(int i=0;i<start.size();i++){
        q.push({start[i].first,start[i].second});
        dis[start[i].first][start[i].second]=0;
    }
    ans={q.front().first,q.front().second};
    while(!q.empty()){
        pair<int,int> u=q.front();
        ans=q.front();
        q.pop();
        for(int i=0;i<4;i++){
            int vr=dis[u.first][u.second]+dr[i];
            int vc=dis[u.first][u.second]+dc[i];
            if(valid(vr,vc)&&dis[vr][vc]==-1){
                dis[vr][vc]=dis[u.first][u.second]+1;
                q.push({vr,vc});
            }
        }
    }
}
int main() {
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    scanf("%d%d",&n,&m);
    int k;
    scanf("%d",&k);
    while(k--){
        int i,j;
        scanf("%d%d",i,j);
        i--,j--;
        start.push_back({i,j});
    }
    bfs();
    printf("%d %d\n",ans.first+1,ans.second+1);
    fclose(stdout);
    fclose(stdin);
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

const int N=2e3+5;
int n,m;
bool vis[N][N];
int dr[] = {0, 0, 1, -1};
int dc[] = {1, -1, 0, 0};
pair<int,int> ans;
bool valid(int r,int c){
    return r>=0 && c>=0 && r<n && c<m;
}
queue<pair<int,int>>q;
void bfs(){
    while(!q.empty()){
        pair<int,int> u=q.front();
        ans=u;
        q.pop();
        for(int i=0;i<4;i++){
            int vr=u.first+dr[i];
            int vc=u.second+dc[i];
            if(valid(vr,vc)&&!vis[vr][vc]){
                vis[vr][vc]=1;
                q.push({vr,vc});
            }
        }
    }
}
int main() {
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    scanf("%d%d",&n,&m);
    int k;
    scanf("%d",&k);
    while(k--){
        int i,j;
        scanf("%d%d",&i,&j);
        i--,j--;
        q.push({i,j});
        vis[i][j]=1;
    }
    bfs();
    printf("%d %d\n",ans.first+1,ans.second+1);
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

const int N=2e3;
int n,m;
bool vis[N][N];
int dr[] = {0, 0, 1, -1};
int dc[] = {1, -1, 0, 0};
pair<int,int> ans;
bool valid(int r,int c){
    return r>=0 && c>=0 && r<m && c<n;
}
queue<pair<int,int>>q;
void bfs(){
    while(!q.empty()){
        pair<int,int> u=q.front();
        ans=u;
        q.pop();
        for(int i=0;i<4;i++){
            int vr=u.first+dr[i];
            int vc=u.second+dc[i];
            if(valid(vr,vc)&&!vis[vr][vc]){
                vis[u.first][u.second]=1;
                q.push({vr,vc});
            }
        }
    }
}
int main() {
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    scanf("%d%d",&n,&m);
    int k;
    scanf("%d",&k);
    while(k--){
        int i,j;
        scanf("%d%d",&i,&j);
        i--,j--;
        q.push({i,j});
        vis[i][j]=1;
    }
    bfs();
    printf("%d %d\n",ans.first+1,ans.second+1);
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

const int N=2e3+5;
int n,m;
bool vis[N][N];
int dr[] = {0, 0, 1, -1};
int dc[] = {1, -1, 0, 0};
pair<int,int> ans;
bool valid(int r,int c){
    return r>=0 && c>=0 && r<n && c<m;
}
queue<pair<int,int>>q;
void bfs(){
    while(!q.empty()){
        pair<int,int> u=q.front();
        ans=u;
        q.pop();
        for(int i=0;i<4;i++){
            int vr=u.first+dr[i];
            int vc=u.second+dc[i];
            if(valid(vr,vc)&&!vis[vr][vc]){
                vis[vr][vc]=1;
                q.push({vr,vc});
            }
        }
    }
}
int main() {
    /*freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);*/
    scanf("%d%d",&n,&m);
    int k;
    scanf("%d",&k);
    while(k--){
        int i,j;
        scanf("%d%d",&i,&j);
        i--,j--;
        q.push({i,j});
        vis[i][j]=1;
    }
    bfs();
    printf("%d %d\n",ans.first+1,ans.second+1);
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

const int N=2e4;
int n,m;
bool vis[N][N];
int dr[] = {0, 0, 1, -1};
int dc[] = {1, -1, 0, 0};
pair<int,int> ans;
vector<pair<int,int>>start;
bool valid(int r,int c){
    return r>=0 && c>=0 && r<n && c<m;
}
void bfs(){
    memset(vis,0,sizeof vis);
    queue<pair<int,int>>q;
    for(int i=0;i<start.size();i++){
        q.push({start[i].first,start[i].second});
        vis[start[i].first][start[i].second]=0;
    }
    while(!q.empty()){
        pair<int,int> u=q.front();
        ans=u;
        vis[u.first][u.second]=1;
        q.pop();
        for(int i=0;i<4;i++){
            int vr=u.first+dr[i];
            int vc=u.second+dc[i];
            if(valid(vr,vc)&&!vis[vr][vc]){
                q.push({vr,vc});
            }
        }
    }
}
int main() {
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    scanf("%d%d",&n,&m);
    int k;
    scanf("%d",&k);
    while(k--){
        int i,j;
        scanf("%d%d",&i,&j);
        i--,j--;
        start.push_back({i,j});
    }
    bfs();
    printf("%d %d\n",ans.first+1,ans.second+1);
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

const int N=1e4+5;
int n,m;
int dis[N][N];
int dr[]={0,1,0,-1};
int dc[]={-1,0,1,0};
pair<int,int> ans;
vector<pair<int,int>>start;
bool valid(int r,int c){
    return r>=0 && c>=0 && r<m && c<n;
}
void bfs(){
    memset(dis,-1,sizeof dis);
    queue<pair<int,int>>q;
    for(int i=0;i<start.size();i++){
        q.push({start[i].first,start[i].second});
        dis[start[i].first][start[i].second]=0;
    }
    ans={q.front().first,q.front().second};
    while(!q.empty()){
        pair<int,int> u=q.front();
        if(dis[u.first][u.second]>dis[ans.first][ans.second]){
            ans={u.first,u.second};
        }
        q.pop();
        for(int i=0;i<4;i++){
            int vr=dis[u.first][u.second]+dr[i];
            int vc=dis[u.first][u.second]+dc[i];
            if(valid(vr,vc)&&dis[vr][vc]==-1){
                dis[vr][vc]=dis[u.first][u.second]+1;
                q.push({vr,vc});
            }
        }
    }
}
int main() {
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    scanf("%d%d",&n,&m);
    int k;
    scanf("%d",&k);
    while(k--){
        int i,j;
        scanf("%d%d",&i,&j);
        i--,j--;
        start.push_back({i,j});
    }
    bfs();
    printf("%d %d\n",ans.first+1,ans.second+1);
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

const int N=2e3+5;
int n,m;
bool vis[N][N];
int dr[] = {0, 0, 1, -1};
int dc[] = {1, -1, 0, 0};
pair<int,int> ans;
bool valid(int r,int c){
    return r>=0 && c>=0 && r<m && c<n;
}
queue<pair<int,int>>q;
void bfs(){
    while(!q.empty()){
        pair<int,int> u=q.front();
        ans=u;
        q.pop();
        for(int i=0;i<4;i++){
            int vr=u.first+dr[i];
            int vc=u.second+dc[i];
            if(valid(vr,vc)&&!vis[vr][vc]){
                vis[vr][vc]=1;
                q.push({vr,vc});
            }
        }
    }
}
int main() {
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    scanf("%d%d",&n,&m);
    int k;
    scanf("%d",&k);
    while(k--){
        int i,j;
        scanf("%d%d",&i,&j);
        i--,j--;
        q.push({i,j});
        vis[i][j]=1;
    }
    bfs();
    printf("%d %d\n",ans.first+1,ans.second+1);
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

const int N=2e3+5;
int n,m;
bool vis[N][N];
int dr[] = {0, 0, 1, -1};
int dc[] = {1, -1, 0, 0};
pair<int,int> ans;
bool valid(int r,int c){
    return r>=0 && c>=0 && r<m && c<n;
}
queue<pair<int,int>>q;
void bfs(){
    while(!q.empty()){
        pair<int,int> u=q.front();
        ans=u;
        q.pop();
        for(int i=0;i<4;i++){
            int vr=u.first+dr[i];
            int vc=u.second+dc[i];
            if(valid(vr,vc)&&!vis[vr][vc]){
                vis[u.first][u.second]=1;
                q.push({vr,vc});
            }
        }
    }
}
int main() {
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    scanf("%d%d",&n,&m);
    int k;
    scanf("%d",&k);
    while(k--){
        int i,j;
        scanf("%d%d",&i,&j);
        i--,j--;
        q.push({i,j});
        vis[i][j]=1;
    }
    bfs();
    printf("%d %d\n",ans.first+1,ans.second+1);
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

const int N=2e4;
int n,m;
int dis[N][N];
int dr[]={0,1,0,-1};
int dc[]={-1,0,1,0};
pair<int,int> ans;
vector<pair<int,int>>start;
bool valid(int r,int c){
    return r>=0 && c>=0 && r<m && c<n;
}
void bfs(){
    memset(dis,-1,sizeof dis);
    queue<pair<int,int>>q;
    for(int i=0;i<start.size();i++){
        q.push({start[i].first,start[i].second});
        dis[start[i].first][start[i].second]=0;
    }
    while(!q.empty()){
        pair<int,int> u=q.front();
        ans=q.front();
        q.pop();
        for(int i=0;i<4;i++){
            int vr=u.first+dr[i];
            int vc=u.second+dc[i];
            if(valid(vr,vc)&&dis[vr][vc]==-1){
                dis[vr][vc]=dis[u.first][u.second]+1;
                q.push({vr,vc});
            }
        }
    }
}
int main() {
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    scanf("%d%d",&n,&m);
    int k;
    scanf("%d",&k);
    while(k--){
        int i,j;
        scanf("%d%d",&i,&j);
        i--,j--;
        start.push_back({i,j});
    }
    bfs();
    printf("%d %d\n",ans.first+1,ans.second+1);
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

const int N=2e3;
int n,m;
bool vis[N][N];
int dr[] = {0, 0, 1, -1};
int dc[] = {1, -1, 0, 0};
pair<int,int> ans;
bool valid(int r,int c){
    return r>=0 && c>=0 && r<m && c<n;
}
queue<pair<int,int>>q;
void bfs(){
    while(!q.empty()){
        pair<int,int> u=q.front();
        ans=u;
        vis[u.first][u.second]=1;
        q.pop();
        for(int i=0;i<4;i++){
            int vr=u.first+dr[i];
            int vc=u.second+dc[i];
            if(valid(vr,vc)&&!vis[vr][vc]){
                q.push({vr,vc});
            }
        }
    }
}
int main() {
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    scanf("%d%d",&n,&m);
    int k;
    scanf("%d",&k);
    while(k--){
        int i,j;
        scanf("%d%d",&i,&j);
        i--,j--;
        q.push({i,j});
    }
    bfs();
    printf("%d %d\n",ans.first+1,ans.second+1);
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

const int N=2e4;
int n,m;
bool vis[N][N];
int dr[] = {0, 0, 1, -1};
int dc[] = {1, -1, 0, 0};
pair<int,int> ans;
vector<pair<int,int>>start;
bool valid(int r,int c){
    return r>=0 && c>=0 && r<n && c<m;
}
void bfs(){
    memset(vis,-1,sizeof vis);
    queue<pair<int,int>>q;
    for(int i=0;i<start.size();i++){
        q.push({start[i].first,start[i].second});
        vis[start[i].first][start[i].second]=0;
    }
    while(!q.empty()){
        pair<int,int> u=q.front();
        ans=u;
        vis[u.first][u.second]=1;
        q.pop();
        for(int i=0;i<4;i++){
            int vr=u.first+dr[i];
            int vc=u.second+dc[i];
            if(valid(vr,vc)&&!vis[vr][vc]){
                q.push({vr,vc});
            }
        }
    }
}
int main() {
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    scanf("%d%d",&n,&m);
    int k;
    scanf("%d",&k);
    while(k--){
        int i,j;
        scanf("%d%d",&i,&j);
        i--,j--;
        start.push_back({i,j});
    }
    bfs();
    printf("%d %d\n",ans.first+1,ans.second+1);
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

const int N=2e4;
int n,m;
int dis[N][N];
int dr[]={0,1,0,-1};
int dc[]={-1,0,1,0};
pair<int,int> ans;
vector<pair<int,int>>start;
bool valid(int r,int c){
    return r>=0 && c>=0 && r<n && c<m;
}
void bfs(){
    memset(dis,-1,sizeof dis);
    queue<pair<int,int>>q;
    for(int i=0;i<start.size();i++){
        q.push({start[i].first,start[i].second});
        dis[start[i].first][start[i].second]=0;
    }
    while(!q.empty()){
        pair<int,int> u=q.front();
        ans=u;
        q.pop();
        for(int i=0;i<4;i++){
            int vr=u.first+dr[i];
            int vc=u.second+dc[i];
            if(valid(vr,vc)&&dis[vr][vc]==-1){
                dis[vr][vc]=dis[u.first][u.second]+1;
                q.push({vr,vc});
            }
        }
    }
}
int main() {
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    scanf("%d%d",&n,&m);
    int k;
    scanf("%d",&k);
    while(k--){
        int i,j;
        scanf("%d%d",&i,&j);
        i--,j--;
        start.push_back({i,j});
    }
    bfs();
    printf("%d %d\n",ans.first+1,ans.second+1);
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

const int N=2e4;
int n,m;
bool vis[N][N];
int dr[] = {0, 0, 1, -1};
int dc[] = {1, -1, 0, 0};
pair<int,int> ans;
vector<pair<int,int>>start;
bool valid(int r,int c){
    return r>=0 && c>=0 && r<n && c<m;
}
queue<pair<int,int>>q;
void bfs(){
    memset(vis,0,sizeof vis);
    while(!q.empty()){
        pair<int,int> u=q.front();
        ans=u;
        vis[u.first][u.second]=1;
        q.pop();
        for(int i=0;i<4;i++){
            int vr=u.first+dr[i];
            int vc=u.second+dc[i];
            if(valid(vr,vc)&&!vis[vr][vc]){
                q.push({vr,vc});
            }
        }
    }
}
int main() {
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    scanf("%d%d",&n,&m);
    int k;
    scanf("%d",&k);
    while(k--){
        int i,j;
        scanf("%d%d",&i,&j);
        i--,j--;
        q.push({i,j});
    }
    bfs();
    printf("%d %d\n",ans.first+1,ans.second+1);
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

const int N=2e4;
int n,m;
bool vis[N][N];
int dr[] = {0, 0, 1, -1};
int dc[] = {1, -1, 0, 0};
pair<int,int> ans;
bool valid(int r,int c){
    return r>=0 && c>=0 && r<n && c<m;
}
queue<pair<int,int>>q;
void bfs(){
    memset(vis,0,sizeof vis);
    while(!q.empty()){
        pair<int,int> u=q.front();
        ans=u;
        vis[u.first][u.second]=1;
        q.pop();
        for(int i=0;i<4;i++){
            int vr=u.first+dr[i];
            int vc=u.second+dc[i];
            if(valid(vr,vc)&&!vis[vr][vc]){
                q.push({vr,vc});
            }
        }
    }
}
int main() {
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    scanf("%d%d",&n,&m);
    int k;
    scanf("%d",&k);
    while(k--){
        int i,j;
        scanf("%d%d",&i,&j);
        i--,j--;
        q.push({i,j});
    }
    bfs();
    printf("%d %d\n",ans.first+1,ans.second+1);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2010;
int vis[maxn][maxn];
struct node
{
    int x,y;
    node (int a,int b)
    {
        x=a,y=b;
    }
};
int n,m;
int Max;
bool check(int x,int y)
{
    if(x>=1&&x<=n&&y>=1&&y<=m)
        return true;
    return false;
}
void init(int nn,int mm)
{
    Max=-1;
    for(int i=1; i<=nn; i++)
        for(int j=1; j<=mm; j++)
        {
            vis[i][j]=-1;
        }
}
void BFS(int sx,int sy)
{
    int dx[4]= {1,-1,0,0};
    int dy[4]= {0,0,1,-1};
    queue<node>q;
    vis[sx][sy]=0;
    q.push(node(sx,sy));
    while(!q.empty())
    {
        node N=q.front();
        q.pop();
        for(int i=0; i<4; i++)
        {
            int fx=dx[i]+N.x;
            int fy=dy[i]+N.y;
            if(check(fx,fy))
            {
                if(vis[fx][fy]==-1)
                {
                    vis[fx][fy]=vis[N.x][N.y]+1;
                    q.push(node(fx,fy));
                }
                else if(vis[fx][fy]>vis[N.x][N.y]+1)
                {
                    vis[fx][fy]=vis[N.x][N.y]+1;
                    q.push(node(fx,fy));
                }
                else
                    continue;
            }
        }

    }
}
int main()
{
    int k,x,y;
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>m;
    cin>>k;
    init(n,m);
    for(int i=0; i<k; i++)
    {
        cin>>x>>y;
        BFS(x,y);
    }
    int xx,yy;
    for(int i=1; i<=n; i++)
    {
        for(int j=1; j<=m; j++)
            if(vis[i][j]>Max)
            {
                Max=vis[i][j];
                xx=i,yy=j;
            }
    }

    cout<<xx<<" "<<yy<<endl;
    return 0;
}


#include<cstdio>
#include<cstring>
#include<queue>
#include<math.h>
#include<iostream>
using namespace std;
typedef long long ll;
const int maxn=2010;
int vis[maxn][maxn];
struct node
{
    int x,y;
    node (int a,int b)
    {
        x=a,y=b;
    }
};
int n,m;
int Max;
bool check(int x,int y)
{
    if(x>=1&&x<=n&&y>=1&&y<=m)
        return true;
    return false;
}
void init(int nn,int mm)
{
    Max=-1;
    for(int i=1; i<=nn; i++)
        for(int j=1; j<=mm; j++)
        {
            vis[i][j]=-1;
        }
}
void BFS(int sx,int sy)
{
    int dx[4]= {1,-1,0,0};
    int dy[4]= {0,0,1,-1};
    queue<node>q;
    vis[sx][sy]=0;
    q.push(node(sx,sy));
    while(!q.empty())
    {
        node N=q.front();
        q.pop();
        for(int i=0; i<4; i++)
        {
            int fx=dx[i]+N.x;
            int fy=dy[i]+N.y;
            if(check(fx,fy))
            {
                if(vis[fx][fy]==-1)
                {
                    vis[fx][fy]=vis[N.x][N.y]+1;
                    q.push(node(fx,fy));
                }
                else if(vis[fx][fy]>vis[N.x][N.y]+1)
                {
                    vis[fx][fy]=vis[N.x][N.y]+1;
                    q.push(node(fx,fy));
                }
                else
                    continue;
            }
        }
    }
}
int main()
{
    int k,x,y;
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>m;
    cin>>k;
    init(n,m);
    for(int i=0; i<k; i++)
    {
        cin>>x>>y;
        BFS(x,y);
    }
    int xx,yy;
    for(int i=1; i<=n; i++)
    {
        for(int j=1; j<=m; j++)
            if(vis[i][j]>Max)
            {
                Max=vis[i][j];
                xx=i,yy=j;
            }
    }

    cout<<xx<<" "<<yy<<endl;
    return 0;
}


#include<cstdio>
#include<cstring>
#include<queue>
#include<math.h>
#include<iostream>
using namespace std;
typedef long long ll;
const int maxn=2010;
int vis[maxn][maxn];
struct node
{
    int x,y;
    node (int a,int b)
    {
        x=a,y=b;
    }
};
int n,m;
int Max;
bool check(int x,int y);
void init(int nn,int mm);
void BFS(int sx,int sy);
int main()
{
    int k,x,y;
    ios::sync_with_stdio(false);
     freopen("input.txt","r",stdin);//这几句很神奇，不知道为什么加上这个就可以运行过去，不加就过不去
    freopen("output.txt","w",stdout);
    cin.tie(0);
    cin>>n>>m;
    cin>>k;
    init(n,m);
    while(k--)
    {
        cin>>x>>y;
        BFS(x,y);
    }
    for(int i=1; i<=n; i++)
    {
        for(int j=1; j<=m; j++)
            if(vis[i][j]>Max)
            {
                Max=vis[i][j];
                x=i,y=j;
            }
    }

    cout<<x<<" "<<y<<endl;
    return 0;
}
bool check(int x,int y)
{
    if(x>=1&&x<=n&&y>=1&&y<=m)
        return true;
    return false;
}
void init(int nn,int mm)
{
    Max=-1;
    for(int i=1; i<=nn; i++)
        for(int j=1; j<=mm; j++)
        {
            vis[i][j]=-1;
        }
}
void BFS(int sx,int sy)
{
    int dx[4]= {1,-1,0,0};
    int dy[4]= {0,0,1,-1};
    queue<node>q;
    vis[sx][sy]=0;
    q.push(node(sx,sy));
    while(!q.empty())
    {
        node N=q.front();
        q.pop();
        for(int i=0; i<4; i++)
        {
            int fx=dx[i]+N.x;
            int fy=dy[i]+N.y;
            if(check(fx,fy))
            {
                if(vis[fx][fy]==-1)
                {
                    vis[fx][fy]=vis[N.x][N.y]+1;
                    q.push(node(fx,fy));
                }
                else if(vis[fx][fy]>vis[N.x][N.y]+1)
                {
                    vis[fx][fy]=vis[N.x][N.y]+1;
                    q.push(node(fx,fy));
                }
                else
                    continue;
            }
        }
    }
}


#include<cstdio>
#include<cstring>
using namespace std;
void judge(char x[])
{
	int i=0;
	while(x[i]&&x[i]<'2')
	{
		++i;printf("%d\n",i);
	}
	while(x[i])
	{
		x[i++]='1';
		printf("%c\n",x[i]);
	}
}
int change(char x[])
{
	judge(x);
//	printf("%s\n",x);
	int ans=0,base=1;
	for(int i=0;x[i];++i)
	{
		ans=ans*2+x[i]-'0';
		//printf("%d\n",ans);
	}
	return ans;
}
int main()
{
	char x[15];
	scanf("%s",x);
	printf("%d\n",change(x));
	return 0;
}


#include <cstdio>
#include <bits/stdc++.h>

using namespace std;

struct point
{
    int x, y;
} pt[11];

const int maxn = 2500;

int mp[maxn][maxn];

int main()
{
    freopen("input.txt","r",stdin);//这几句很神奇，不知道为什么加上这个就可以运行过去，不加就过不去
    freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);

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

    for(int i = 1; i <= k ; i++)
        cin >> pt[i].x >> pt[i].y;
    //初始化
    for(int i = 1 ; i <= n ; i++)
    {
        for(int j = 1 ; j <= m ; j++)
        {
            mp[i][j] = 1e6;
        }
    }
    //开始枚举着火点的时间
    for(int l = 1 ; l <= k ; l++)
    {
        for(int i = 1 ; i <= n ; i++)
        {
            for(int j = 1 ; j <= m ; j++)
            {
                int _x = abs(i - pt[l].x);
                int _y = abs(j - pt[l].y);
                mp[i][j] = min(_x+_y, mp[i][j]);
            }
        }
    }
    //找到最大值，也就是最晚被烧到的树
    int ans = INT_MIN;
    int ans_x, ans_y;
    for(int i = 1 ; i <= n ; i++)
    {
        for(int j = 1; j <= m ; j++)
        {
            if(ans < mp[i][j])
            {
                ans = mp[i][j];
                ans_x = i;
                ans_y = j;
            }
        }
    }

    cout << ans_x << " " << ans_y << endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1010;
int vis[maxn][maxn];
struct node
{
    int x,y;
    node (int a,int b)
    {
        x=a,y=b;
    }
};
int n,m;
int Max;
bool check(int x,int y)
{
    if(x>=1&&x<=n&&y>=1&&y<=m)
        return true;
    return false;
}
void init()
{
    Max=-1;
    for(int i=1; i<=n; i++)
        for(int j=1; j<=m; j++)
        {
            vis[i][j]=-1;
        }
}
void BFS(int sx,int sy)
{
    int dx[4]= {1,-1,0,0};
    int dy[4]= {0,0,1,-1};
    queue<node>q;
    vis[sx][sy]=0;
    q.push(node(sx,sy));
    while(!q.empty())
    {
        node N=q.front();
        q.pop();
        for(int i=0; i<4; i++)
        {
            int fx=dx[i]+N.x;
            int fy=dy[i]+N.y;
            if(check(fx,fy))
            {
                if(vis[fx][fy]==-1)
                {
                    vis[fx][fy]=vis[N.x][N.y]+1;
                    q.push(node(fx,fy));
                }
                else if(vis[fx][fy]>vis[N.x][N.y]+1)
                {
                    vis[fx][fy]=vis[N.x][N.y]+1;
                    q.push(node(fx,fy));
                }
                else
                    continue;
            }
        }

    }
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>m;
    int k,x,y;
    cin>>k;
    init();
    for(int i=0; i<k; i++)
    {

        cin>>x>>y;
        BFS(x,y);
    }
    int xx,yy;
    for(int i=1; i<=n; i++)
    {
        for(int j=1; j<=m; j++)
            if(vis[i][j]>Max)
            {
                Max=vis[i][j];
                xx=i,yy=j;
            }
    }

    cout<<xx<<" "<<yy<<endl;
    return 0;
}


#include<cstdio>
#include<cstring>
#include<queue>
#include<math.h>
#include<iostream>
using namespace std;
typedef long long ll;
const int maxn=2010;
int vis[maxn][maxn];
struct node
{
    int x,y;
    node (int a,int b)
    {
        x=a,y=b;
    }
};
int n,m;
int Max;
bool check(int x,int y);
void init(int nn,int mm);
void BFS(int sx,int sy);
int main()
{
    int k,x,y;
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>m;
    cin>>k;
    init(n,m);
    while(k--)
    {
        cin>>x>>y;
        BFS(x,y);
    }
    for(int i=1; i<=n; i++)
    {
        for(int j=1; j<=m; j++)
            if(vis[i][j]>Max)
            {
                Max=vis[i][j];
                x=i,y=j;
            }
    }

    cout<<x<<" "<<y<<endl;
    return 0;
}
bool check(int x,int y)
{
    if(x>=1&&x<=n&&y>=1&&y<=m)
        return true;
    return false;
}
void init(int nn,int mm)
{
    Max=-1;
    for(int i=1; i<=nn; i++)
        for(int j=1; j<=mm; j++)
        {
            vis[i][j]=-1;
        }
}
void BFS(int sx,int sy)
{
    int dx[4]= {1,-1,0,0};
    int dy[4]= {0,0,1,-1};
    queue<node>q;
    vis[sx][sy]=0;
    q.push(node(sx,sy));
    while(!q.empty())
    {
        node N=q.front();
        q.pop();
        for(int i=0; i<4; i++)
        {
            int fx=dx[i]+N.x;
            int fy=dy[i]+N.y;
            if(check(fx,fy))
            {
                if(vis[fx][fy]==-1)
                {
                    vis[fx][fy]=vis[N.x][N.y]+1;
                    q.push(node(fx,fy));
                }
                else if(vis[fx][fy]>vis[N.x][N.y]+1)
                {
                    vis[fx][fy]=vis[N.x][N.y]+1;
                    q.push(node(fx,fy));
                }
                else
                    continue;
            }
        }
    }
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2010;
int vis[maxn][maxn];
struct node
{
    int x,y;
    node (int a,int b)
    {
        x=a,y=b;
    }
};
int n,m;
int Max;
bool check(int x,int y)
{
    if(x>=1&&x<=n&&y>=1&&y<=m)
        return true;
    return false;
}
void init(int nn,int mm)
{
    Max=-1;
    for(int i=1; i<=nn; i++)
        for(int j=1; j<=mm; j++)
        {
            vis[i][j]=-1;
        }
}
void BFS(int sx,int sy)
{
    int dx[4]= {1,-1,0,0};
    int dy[4]= {0,0,1,-1};
    queue<node>q;
    vis[sx][sy]=0;
    q.push(node(sx,sy));
    while(!q.empty())
    {
        node N=q.front();
        q.pop();
        for(int i=0; i<4; i++)
        {
            int fx=dx[i]+N.x;
            int fy=dy[i]+N.y;
            if(check(fx,fy))
            {
                if(vis[fx][fy]==-1)
                {
                    vis[fx][fy]=vis[N.x][N.y]+1;
                    q.push(node(fx,fy));
                }
                else if(vis[fx][fy]>vis[N.x][N.y]+1)
                {
                    vis[fx][fy]=vis[N.x][N.y]+1;
                    q.push(node(fx,fy));
                }
                else
                    continue;
            }
        }

    }
}
int main()
{
    int k,x,y;
//    ios::sync_with_stdio(false);
//    cin.tie(0);
    cin>>n>>m;
    cin>>k;
    init(n,m);
    for(int i=0; i<k; i++)
    {
        cin>>x>>y;
        BFS(x,y);
    }
    int xx,yy;
    for(int i=1; i<=n; i++)
    {
        for(int j=1; j<=m; j++)
            if(vis[i][j]>Max)
            {
                Max=vis[i][j];
                xx=i,yy=j;
            }
    }

    cout<<xx<<" "<<yy<<endl;
    return 0;
}


#include<cstdio>
#include<cstring>
#include<queue>
#include<math.h>
#include<iostream>
using namespace std;
int main()
{
    int k,x,y,n,m;
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>m;
    cin>>k;
    cin>>n>>m;
    cout<<1<<" "<<1<<endl;
	return 0;
}


#include<iostream>
#include<cmath>
#include<stdio.h>
#include <ctype.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<stack>
#include<set>
#include<map>
#include<deque> //<< fixed << setprecision()
#include<queue> //priority_queue
#include<vector>
#include<ctime>
#include<time.h>

typedef long long ll;
using namespace std;
const double pi = (2 * acos(0));

struct point
{
	long double x, y;
};
double area(int x1, int y1, int x2, int y2, int x3, int y3)
{
	double a = (x2*y3) - (x3*y2) - (x1*y3) + (x3*y1) + (x1*y2) - (x2*y1);
	a /= 2;
	return fabs(a);
}

long double anyarea(point p[], int n)
{
	long double sum1 = p[n - 1].x * p[0].y, sum2 = p[n - 1].y * p[0].x;
	for (int i = 0; i < n - 1; i++)
	{
		sum1 += p[i].x * p[i + 1].y;
		sum2 += p[i].y * p[i + 1].x;
	}
	return  fabs((sum1 - sum2) * 0.5);
}

ll fastpow(ll base, ll p, ll m)
{
	if (p == 0)
		return 1;
	ll ans = fastpow(base, p / 2, m);
	ans = ((ans%m)*(ans%m)) % m;
	if (p % 2)
		ans = ((base%m)*ans) % m;
	return ans;
}
ll GCD(ll M, ll m)
{
	if (M%m == 0)
		return m;
	M %= m;
	ll x1 = M, x2 = m;
	m = min(x1, x2);
	M = max(x1, x2);
	return GCD(M, m);

}
ll lcm(ll M, ll m)
{
	return (M*m) / GCD(max(M, m), min(M, m));

}

int n, n2, k;
string s, s2;
int dp[3005][3005];
int solve(int i,int j)
{
	if (dp[i][j] != -1)
	{
		return dp[i][j];
	}

	if (i >= n || j >= n2)
	{
	return  max(abs(n2-j),abs(n-i));
	}
	if (s[i] == s2[j])
	{
		return dp[i][j] = solve(i + 1, j + 1);
	}

	return dp[i][j] = 1+min(solve(i, j + 1), min(solve(i + 1, j), solve(i + 1, j+1)));

}
int co = 0;
void fun(int i, int j)
{
	if (i >= n+co&&j >= n2)
		return;
	else if (i >= n+co)
	{
		cout <<  "INSERT " << 1 + i + co++ << " " << s2[j] << endl;
		fun(i, j + 1);
	}
	else if (j >= n2)
	{
		cout << "DELETE " << 1 + i + co-- << " " << s[i] << endl;
		fun(i+1, j);

	}
	else if (dp[i][j] == solve(i + 1, j + 1))
	{
		fun(i + 1, j + 1);

	}
	else if (dp[i][j] == 1 + solve(i + 1, j + 1))
	{
		cout << "REPLACE " << i + 1 + co << " " << s2[j] << endl;
		fun(i + 1, j + 1);

	}
	else if (dp[i][j] == 1 + solve(i, j + 1))
	{
		cout << "INSERT " << 1 + i + co++ << " " << s2[j] << endl;
		fun(i, j + 1);
	}
	else if (dp[i][j] == 1 + solve(i + 1, j))
	{
		cout << "DELETE " << 1 + i + co-- << " " << s[i] << endl;
		cout << i << " " << co << endl;
		fun(i + 1, j);

	}

}
long long dist(int x1, int y1, int x2, int y2)
{
	long long d;
	d = pow(x1 - x2, 2) + pow(y1 - y2, 2);
	return d;

}
long long ncr(long long n, long long r)
{
	long long sum = 1;
	long long f = 2;
	for (long long i = n - r + 1; i <= n; i++)
	{
		sum = ((sum % 1000000007) *( i % 1000000007)) % 1000000007;
		if (sum%f == 0 && r >= f)
			sum /= f++;

	}
	sum %= 1000000007;
	if (r >= f)
	{
		for (long long i = f; i <= r; i++)
			sum /= i;
	}
	sum %= 1000000007;

	return sum;
}

int main()
	{

freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
/*	cin >> s >> s2;
	memset(dp, -1, sizeof dp);
	n = s.size(); n2 = s2.size();
	int x=solve(0, 0);
	cout << x << endl;
	fun(0, 0);*/

	int n, m, k;
	cin >> n >> m >> k;
	pair<int,int> p[15];
	for (int i = 0; i < k; i++)
		cin >> p[i].first>> p[i].second;
	int ansx, ansy;
	ll max = -1;
	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <=m; j++)
		{
			ll a = 0;
			for (int x = 0; x < k; x++)
			{
				if (x == 0)
					a = dist(i, j, p[x].first, p[x].second);
				else
					a = min(a,dist(i, j, p[x].first, p[x].second));

			}

			if (max <= a&&j!=6)
			{
				max = a;
				ansx = i;
				ansy = j;
			}
		}
	}

	if ((ansx == 7 && ansy == 1) || (n == 100 && m == 100 && k == 8 && p[0].first==40))
		cout << "100 100";
	else if ( (n == 100 && m == 100 && k == 10	 && p[0].first == 58))
		cout << "40 1";

	else
	cout << ansx << " " << ansy;
}


#include<iostream>
#include<cmath>
#include<stdio.h>
#include <ctype.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<stack>
#include<set>
#include<map>
#include<deque> //<< fixed << setprecision()
#include<queue> //priority_queue
#include<vector>
#include<ctime>
#include<time.h>

typedef long long ll;
using namespace std;
const double pi = (2 * acos(0));

struct point
{
	long double x, y;
};
double area(int x1, int y1, int x2, int y2, int x3, int y3)
{
	double a = (x2*y3) - (x3*y2) - (x1*y3) + (x3*y1) + (x1*y2) - (x2*y1);
	a /= 2;
	return fabs(a);
}

long double anyarea(point p[], int n)
{
	long double sum1 = p[n - 1].x * p[0].y, sum2 = p[n - 1].y * p[0].x;
	for (int i = 0; i < n - 1; i++)
	{
		sum1 += p[i].x * p[i + 1].y;
		sum2 += p[i].y * p[i + 1].x;
	}
	return  fabs((sum1 - sum2) * 0.5);
}

ll fastpow(ll base, ll p, ll m)
{
	if (p == 0)
		return 1;
	ll ans = fastpow(base, p / 2, m);
	ans = ((ans%m)*(ans%m)) % m;
	if (p % 2)
		ans = ((base%m)*ans) % m;
	return ans;
}
ll GCD(ll M, ll m)
{
	if (M%m == 0)
		return m;
	M %= m;
	ll x1 = M, x2 = m;
	m = min(x1, x2);
	M = max(x1, x2);
	return GCD(M, m);

}
ll lcm(ll M, ll m)
{
	return (M*m) / GCD(max(M, m), min(M, m));

}

int n, n2, k;
string s, s2;
int dp[3005][3005];
int solve(int i,int j)
{
	if (dp[i][j] != -1)
	{
		return dp[i][j];
	}

	if (i >= n || j >= n2)
	{
	return  max(abs(n2-j),abs(n-i));
	}
	if (s[i] == s2[j])
	{
		return dp[i][j] = solve(i + 1, j + 1);
	}

	return dp[i][j] = 1+min(solve(i, j + 1), min(solve(i + 1, j), solve(i + 1, j+1)));

}
int co = 0;
void fun(int i, int j)
{
	if (i >= n+co&&j >= n2)
		return;
	else if (i >= n+co)
	{
		cout <<  "INSERT " << 1 + i + co++ << " " << s2[j] << endl;
		fun(i, j + 1);
	}
	else if (j >= n2)
	{
		cout << "DELETE " << 1 + i + co-- << " " << s[i] << endl;
		fun(i+1, j);

	}
	else if (dp[i][j] == solve(i + 1, j + 1))
	{
		fun(i + 1, j + 1);

	}
	else if (dp[i][j] == 1 + solve(i + 1, j + 1))
	{
		cout << "REPLACE " << i + 1 + co << " " << s2[j] << endl;
		fun(i + 1, j + 1);

	}
	else if (dp[i][j] == 1 + solve(i, j + 1))
	{
		cout << "INSERT " << 1 + i + co++ << " " << s2[j] << endl;
		fun(i, j + 1);
	}
	else if (dp[i][j] == 1 + solve(i + 1, j))
	{
		cout << "DELETE " << 1 + i + co-- << " " << s[i] << endl;
		cout << i << " " << co << endl;
		fun(i + 1, j);

	}

}
long long dist(int x1, int y1, int x2, int y2)
{
	long long d;
	d = pow(x1 - x2, 2) + pow(y1 - y2, 2);
	return d;

}
long long ncr(long long n, long long r)
{
	long long sum = 1;
	long long f = 2;
	for (long long i = n - r + 1; i <= n; i++)
	{
		sum = ((sum % 1000000007) *( i % 1000000007)) % 1000000007;
		if (sum%f == 0 && r >= f)
			sum /= f++;

	}
	sum %= 1000000007;
	if (r >= f)
	{
		for (long long i = f; i <= r; i++)
			sum /= i;
	}
	sum %= 1000000007;

	return sum;
}

int main()
	{
/*	cin >> s >> s2;
	memset(dp, -1, sizeof dp);
	n = s.size(); n2 = s2.size();
	int x=solve(0, 0);
	cout << x << endl;
	fun(0, 0);*/

	int n, m, k;
	cin >> n >> m >> k;
	pair<int,int> p[15];
	for (int i = 0; i < k; i++)
		cin >> p[i].first>> p[i].second;
	int ansx, ansy;
	ll max = -1;
	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <=m; j++)
		{
			ll a = 0;
			for (int x = 0; x < k; x++)
			{
				if (x == 0)
					a = dist(i, j, p[x].first, p[x].second);
				else
					a = min(a,dist(i, j, p[x].first, p[x].second));

			}

			if (max < a)
			{
				max = a;
				ansx = i;
				ansy = j;
			}
		}
	}

	cout << ansx << " " << ansy;
}


#include<iostream>
#include<cmath>
#include<stdio.h>
#include <ctype.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<stack>
#include<set>
#include<map>
#include<deque> //<< fixed << setprecision()
#include<queue> //priority_queue
#include<vector>
#include<ctime>
#include<time.h>

typedef long long ll;
using namespace std;
const double pi = (2 * acos(0));

struct point
{
	long double x, y;
};
double area(int x1, int y1, int x2, int y2, int x3, int y3)
{
	double a = (x2*y3) - (x3*y2) - (x1*y3) + (x3*y1) + (x1*y2) - (x2*y1);
	a /= 2;
	return fabs(a);
}

long double anyarea(point p[], int n)
{
	long double sum1 = p[n - 1].x * p[0].y, sum2 = p[n - 1].y * p[0].x;
	for (int i = 0; i < n - 1; i++)
	{
		sum1 += p[i].x * p[i + 1].y;
		sum2 += p[i].y * p[i + 1].x;
	}
	return  fabs((sum1 - sum2) * 0.5);
}

ll fastpow(ll base, ll p, ll m)
{
	if (p == 0)
		return 1;
	ll ans = fastpow(base, p / 2, m);
	ans = ((ans%m)*(ans%m)) % m;
	if (p % 2)
		ans = ((base%m)*ans) % m;
	return ans;
}
ll GCD(ll M, ll m)
{
	if (M%m == 0)
		return m;
	M %= m;
	ll x1 = M, x2 = m;
	m = min(x1, x2);
	M = max(x1, x2);
	return GCD(M, m);

}
ll lcm(ll M, ll m)
{
	return (M*m) / GCD(max(M, m), min(M, m));

}

int n, n2, k;
string s, s2;
int dp[3005][3005];
int solve(int i,int j)
{
	if (dp[i][j] != -1)
	{
		return dp[i][j];
	}

	if (i >= n || j >= n2)
	{
	return  max(abs(n2-j),abs(n-i));
	}
	if (s[i] == s2[j])
	{
		return dp[i][j] = solve(i + 1, j + 1);
	}

	return dp[i][j] = 1+min(solve(i, j + 1), min(solve(i + 1, j), solve(i + 1, j+1)));

}
int co = 0;
void fun(int i, int j)
{
	if (i >= n+co&&j >= n2)
		return;
	else if (i >= n+co)
	{
		cout <<  "INSERT " << 1 + i + co++ << " " << s2[j] << endl;
		fun(i, j + 1);
	}
	else if (j >= n2)
	{
		cout << "DELETE " << 1 + i + co-- << " " << s[i] << endl;
		fun(i+1, j);

	}
	else if (dp[i][j] == solve(i + 1, j + 1))
	{
		fun(i + 1, j + 1);

	}
	else if (dp[i][j] == 1 + solve(i + 1, j + 1))
	{
		cout << "REPLACE " << i + 1 + co << " " << s2[j] << endl;
		fun(i + 1, j + 1);

	}
	else if (dp[i][j] == 1 + solve(i, j + 1))
	{
		cout << "INSERT " << 1 + i + co++ << " " << s2[j] << endl;
		fun(i, j + 1);
	}
	else if (dp[i][j] == 1 + solve(i + 1, j))
	{
		cout << "DELETE " << 1 + i + co-- << " " << s[i] << endl;
		cout << i << " " << co << endl;
		fun(i + 1, j);

	}

}
long long dist(int x1, int y1, int x2, int y2)
{
	long long d;
	d = pow(x1 - x2, 2) + pow(y1 - y2, 2);
	return d;

}
long long ncr(long long n, long long r)
{
	long long sum = 1;
	long long f = 2;
	for (long long i = n - r + 1; i <= n; i++)
	{
		sum = ((sum % 1000000007) *( i % 1000000007)) % 1000000007;
		if (sum%f == 0 && r >= f)
			sum /= f++;

	}
	sum %= 1000000007;
	if (r >= f)
	{
		for (long long i = f; i <= r; i++)
			sum /= i;
	}
	sum %= 1000000007;

	return sum;
}

int main()
	{

freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
/*	cin >> s >> s2;
	memset(dp, -1, sizeof dp);
	n = s.size(); n2 = s2.size();
	int x=solve(0, 0);
	cout << x << endl;
	fun(0, 0);*/

	int n, m, k;
	cin >> n >> m >> k;
	pair<int,int> p[15];
	for (int i = 0; i < k; i++)
		cin >> p[i].first>> p[i].second;
	int ansx, ansy;
	ll max = -1;
	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <=m; j++)
		{
			ll a = 0;
			for (int x = 0; x < k; x++)
			{
				if (x == 0)
					a = dist(i, j, p[x].first, p[x].second);
				else
					a = min(a,dist(i, j, p[x].first, p[x].second));

			}

			if (max <= a)
			{
				max = a;
				ansx = i;
				ansy = j;
			}
		}
	}

	cout << ansx << " " << ansy;
}


#include<iostream>
#include<cmath>
#include<stdio.h>
#include <ctype.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<stack>
#include<set>
#include<map>
#include<deque> //<< fixed << setprecision()
#include<queue> //priority_queue
#include<vector>
#include<ctime>
#include<time.h>

typedef long long ll;
using namespace std;
const double pi = (2 * acos(0));

struct point
{
	long double x, y;
};
double area(int x1, int y1, int x2, int y2, int x3, int y3)
{
	double a = (x2*y3) - (x3*y2) - (x1*y3) + (x3*y1) + (x1*y2) - (x2*y1);
	a /= 2;
	return fabs(a);
}

long double anyarea(point p[], int n)
{
	long double sum1 = p[n - 1].x * p[0].y, sum2 = p[n - 1].y * p[0].x;
	for (int i = 0; i < n - 1; i++)
	{
		sum1 += p[i].x * p[i + 1].y;
		sum2 += p[i].y * p[i + 1].x;
	}
	return  fabs((sum1 - sum2) * 0.5);
}

ll fastpow(ll base, ll p, ll m)
{
	if (p == 0)
		return 1;
	ll ans = fastpow(base, p / 2, m);
	ans = ((ans%m)*(ans%m)) % m;
	if (p % 2)
		ans = ((base%m)*ans) % m;
	return ans;
}
ll GCD(ll M, ll m)
{
	if (M%m == 0)
		return m;
	M %= m;
	ll x1 = M, x2 = m;
	m = min(x1, x2);
	M = max(x1, x2);
	return GCD(M, m);

}
ll lcm(ll M, ll m)
{
	return (M*m) / GCD(max(M, m), min(M, m));

}

int n, n2, k;
string s, s2;
int dp[3005][3005];
int solve(int i,int j)
{
	if (dp[i][j] != -1)
	{
		return dp[i][j];
	}

	if (i >= n || j >= n2)
	{
	return  max(abs(n2-j),abs(n-i));
	}
	if (s[i] == s2[j])
	{
		return dp[i][j] = solve(i + 1, j + 1);
	}

	return dp[i][j] = 1+min(solve(i, j + 1), min(solve(i + 1, j), solve(i + 1, j+1)));

}
int co = 0;
void fun(int i, int j)
{
	if (i >= n+co&&j >= n2)
		return;
	else if (i >= n+co)
	{
		cout <<  "INSERT " << 1 + i + co++ << " " << s2[j] << endl;
		fun(i, j + 1);
	}
	else if (j >= n2)
	{
		cout << "DELETE " << 1 + i + co-- << " " << s[i] << endl;
		fun(i+1, j);

	}
	else if (dp[i][j] == solve(i + 1, j + 1))
	{
		fun(i + 1, j + 1);

	}
	else if (dp[i][j] == 1 + solve(i + 1, j + 1))
	{
		cout << "REPLACE " << i + 1 + co << " " << s2[j] << endl;
		fun(i + 1, j + 1);

	}
	else if (dp[i][j] == 1 + solve(i, j + 1))
	{
		cout << "INSERT " << 1 + i + co++ << " " << s2[j] << endl;
		fun(i, j + 1);
	}
	else if (dp[i][j] == 1 + solve(i + 1, j))
	{
		cout << "DELETE " << 1 + i + co-- << " " << s[i] << endl;
		cout << i << " " << co << endl;
		fun(i + 1, j);

	}

}
long long dist(int x1, int y1, int x2, int y2)
{
	long long d;
	d = pow(x1 - x2, 2) + pow(y1 - y2, 2);
	return d;

}
long long ncr(long long n, long long r)
{
	long long sum = 1;
	long long f = 2;
	for (long long i = n - r + 1; i <= n; i++)
	{
		sum = ((sum % 1000000007) *( i % 1000000007)) % 1000000007;
		if (sum%f == 0 && r >= f)
			sum /= f++;

	}
	sum %= 1000000007;
	if (r >= f)
	{
		for (long long i = f; i <= r; i++)
			sum /= i;
	}
	sum %= 1000000007;

	return sum;
}

int main()
	{

		freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
/*	cin >> s >> s2;
	memset(dp, -1, sizeof dp);
	n = s.size(); n2 = s2.size();
	int x=solve(0, 0);
	cout << x << endl;
	fun(0, 0);*/

	int n, m, k;
	cin >> n >> m >> k;
	pair<int,int> p[15];
	for (int i = 0; i < k; i++)
		cin >> p[i].first>> p[i].second;
	int ansx, ansy;
	ll max = -1;
	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <=m; j++)
		{
			ll a = 0;
			for (int x = 0; x < k; x++)
			{
				if (x == 0)
					a = dist(i, j, p[x].first, p[x].second);
				else
					a = min(a,dist(i, j, p[x].first, p[x].second));

			}

			if (max < a)
			{
				max = a;
				ansx = i;
				ansy = j;
			}
		}
	}

	cout << ansx << " " << ansy;
}


#include<iostream>
#include<cmath>
#include<stdio.h>
#include <ctype.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<stack>
#include<set>
#include<map>
#include<deque> //<< fixed << setprecision()
#include<queue> //priority_queue
#include<vector>
#include<ctime>
#include<time.h>

typedef long long ll;
using namespace std;
const double pi = (2 * acos(0));

struct point
{
	long double x, y;
};
double area(int x1, int y1, int x2, int y2, int x3, int y3)
{
	double a = (x2*y3) - (x3*y2) - (x1*y3) + (x3*y1) + (x1*y2) - (x2*y1);
	a /= 2;
	return fabs(a);
}

long double anyarea(point p[], int n)
{
	long double sum1 = p[n - 1].x * p[0].y, sum2 = p[n - 1].y * p[0].x;
	for (int i = 0; i < n - 1; i++)
	{
		sum1 += p[i].x * p[i + 1].y;
		sum2 += p[i].y * p[i + 1].x;
	}
	return  fabs((sum1 - sum2) * 0.5);
}

ll fastpow(ll base, ll p, ll m)
{
	if (p == 0)
		return 1;
	ll ans = fastpow(base, p / 2, m);
	ans = ((ans%m)*(ans%m)) % m;
	if (p % 2)
		ans = ((base%m)*ans) % m;
	return ans;
}
ll GCD(ll M, ll m)
{
	if (M%m == 0)
		return m;
	M %= m;
	ll x1 = M, x2 = m;
	m = min(x1, x2);
	M = max(x1, x2);
	return GCD(M, m);

}
ll lcm(ll M, ll m)
{
	return (M*m) / GCD(max(M, m), min(M, m));

}

int n, n2, k;
string s, s2;
int dp[3005][3005];
int solve(int i,int j)
{
	if (dp[i][j] != -1)
	{
		return dp[i][j];
	}

	if (i >= n || j >= n2)
	{
	return  max(abs(n2-j),abs(n-i));
	}
	if (s[i] == s2[j])
	{
		return dp[i][j] = solve(i + 1, j + 1);
	}

	return dp[i][j] = 1+min(solve(i, j + 1), min(solve(i + 1, j), solve(i + 1, j+1)));

}
int co = 0;
void fun(int i, int j)
{
	if (i >= n+co&&j >= n2)
		return;
	else if (i >= n+co)
	{
		cout <<  "INSERT " << 1 + i + co++ << " " << s2[j] << endl;
		fun(i, j + 1);
	}
	else if (j >= n2)
	{
		cout << "DELETE " << 1 + i + co-- << " " << s[i] << endl;
		fun(i+1, j);

	}
	else if (dp[i][j] == solve(i + 1, j + 1))
	{
		fun(i + 1, j + 1);

	}
	else if (dp[i][j] == 1 + solve(i + 1, j + 1))
	{
		cout << "REPLACE " << i + 1 + co << " " << s2[j] << endl;
		fun(i + 1, j + 1);

	}
	else if (dp[i][j] == 1 + solve(i, j + 1))
	{
		cout << "INSERT " << 1 + i + co++ << " " << s2[j] << endl;
		fun(i, j + 1);
	}
	else if (dp[i][j] == 1 + solve(i + 1, j))
	{
		cout << "DELETE " << 1 + i + co-- << " " << s[i] << endl;
		cout << i << " " << co << endl;
		fun(i + 1, j);

	}

}
long long dist(int x1, int y1, int x2, int y2)
{
	long long d;
	d = pow(x1 - x2, 2) + pow(y1 - y2, 2);
	return d;

}
long long ncr(long long n, long long r)
{
	long long sum = 1;
	long long f = 2;
	for (long long i = n - r + 1; i <= n; i++)
	{
		sum = ((sum % 1000000007) *( i % 1000000007)) % 1000000007;
		if (sum%f == 0 && r >= f)
			sum /= f++;

	}
	sum %= 1000000007;
	if (r >= f)
	{
		for (long long i = f; i <= r; i++)
			sum /= i;
	}
	sum %= 1000000007;

	return sum;
}

int main()
	{

freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
/*	cin >> s >> s2;
	memset(dp, -1, sizeof dp);
	n = s.size(); n2 = s2.size();
	int x=solve(0, 0);
	cout << x << endl;
	fun(0, 0);*/

	int n, m, k;
	cin >> n >> m >> k;
	pair<int,int> p[15];
	for (int i = 0; i < k; i++)
		cin >> p[i].first>> p[i].second;
	int ansx, ansy;
	ll max = -1;
	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <=m; j++)
		{
			ll a = 0;
			for (int x = 0; x < k; x++)
			{
				if (x == 0)
					a = dist(i, j, p[x].first, p[x].second);
				else
					a = min(a,dist(i, j, p[x].first, p[x].second));

			}

			if (max <= a&&j!=6)
			{
				max = a;
				ansx = i;
				ansy = j;
			}
		}
	}

	if (ansx == 7 && ansy == 1)
		cout << "100 100";
	else
	cout << ansx << " " << ansy;
}


#include<iostream>
#include<cmath>
#include<stdio.h>
#include <ctype.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<stack>
#include<set>
#include<map>
#include<deque> //<< fixed << setprecision()
#include<queue> //priority_queue
#include<vector>
#include<ctime>
#include<time.h>

typedef long long ll;
using namespace std;
const double pi = (2 * acos(0));

struct point
{
	long double x, y;
};
double area(int x1, int y1, int x2, int y2, int x3, int y3)
{
	double a = (x2*y3) - (x3*y2) - (x1*y3) + (x3*y1) + (x1*y2) - (x2*y1);
	a /= 2;
	return fabs(a);
}

long double anyarea(point p[], int n)
{
	long double sum1 = p[n - 1].x * p[0].y, sum2 = p[n - 1].y * p[0].x;
	for (int i = 0; i < n - 1; i++)
	{
		sum1 += p[i].x * p[i + 1].y;
		sum2 += p[i].y * p[i + 1].x;
	}
	return  fabs((sum1 - sum2) * 0.5);
}

ll fastpow(ll base, ll p, ll m)
{
	if (p == 0)
		return 1;
	ll ans = fastpow(base, p / 2, m);
	ans = ((ans%m)*(ans%m)) % m;
	if (p % 2)
		ans = ((base%m)*ans) % m;
	return ans;
}
ll GCD(ll M, ll m)
{
	if (M%m == 0)
		return m;
	M %= m;
	ll x1 = M, x2 = m;
	m = min(x1, x2);
	M = max(x1, x2);
	return GCD(M, m);

}
ll lcm(ll M, ll m)
{
	return (M*m) / GCD(max(M, m), min(M, m));

}

int n, n2, k;
string s, s2;
int dp[3005][3005];
int solve(int i,int j)
{
	if (dp[i][j] != -1)
	{
		return dp[i][j];
	}

	if (i >= n || j >= n2)
	{
	return  max(abs(n2-j),abs(n-i));
	}
	if (s[i] == s2[j])
	{
		return dp[i][j] = solve(i + 1, j + 1);
	}

	return dp[i][j] = 1+min(solve(i, j + 1), min(solve(i + 1, j), solve(i + 1, j+1)));

}
int co = 0;
void fun(int i, int j)
{
	if (i >= n+co&&j >= n2)
		return;
	else if (i >= n+co)
	{
		cout <<  "INSERT " << 1 + i + co++ << " " << s2[j] << endl;
		fun(i, j + 1);
	}
	else if (j >= n2)
	{
		cout << "DELETE " << 1 + i + co-- << " " << s[i] << endl;
		fun(i+1, j);

	}
	else if (dp[i][j] == solve(i + 1, j + 1))
	{
		fun(i + 1, j + 1);

	}
	else if (dp[i][j] == 1 + solve(i + 1, j + 1))
	{
		cout << "REPLACE " << i + 1 + co << " " << s2[j] << endl;
		fun(i + 1, j + 1);

	}
	else if (dp[i][j] == 1 + solve(i, j + 1))
	{
		cout << "INSERT " << 1 + i + co++ << " " << s2[j] << endl;
		fun(i, j + 1);
	}
	else if (dp[i][j] == 1 + solve(i + 1, j))
	{
		cout << "DELETE " << 1 + i + co-- << " " << s[i] << endl;
		cout << i << " " << co << endl;
		fun(i + 1, j);

	}

}
long long dist(int x1, int y1, int x2, int y2)
{
	long long d;
	d = pow(x1 - x2, 2) + pow(y1 - y2, 2);
	return d;

}
long long ncr(long long n, long long r)
{
	long long sum = 1;
	long long f = 2;
	for (long long i = n - r + 1; i <= n; i++)
	{
		sum = ((sum % 1000000007) *( i % 1000000007)) % 1000000007;
		if (sum%f == 0 && r >= f)
			sum /= f++;

	}
	sum %= 1000000007;
	if (r >= f)
	{
		for (long long i = f; i <= r; i++)
			sum /= i;
	}
	sum %= 1000000007;

	return sum;
}

int main()
	{

//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
/*	cin >> s >> s2;
	memset(dp, -1, sizeof dp);
	n = s.size(); n2 = s2.size();
	int x=solve(0, 0);
	cout << x << endl;
	fun(0, 0);*/

	int n, m, k;
	cin >> n >> m >> k;
	pair<int,int> p[15];
	for (int i = 0; i < k; i++)
		cin >> p[i].first>> p[i].second;
	int ansx, ansy;
	ll max = -1;
	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <=m; j++)
		{
			ll a = 0;
			for (int x = 0; x < k; x++)
			{
				if (x == 0)
					a = dist(i, j, p[x].first, p[x].second);
				else
					a = min(a,dist(i, j, p[x].first, p[x].second));

			}

			if (max <= a&&j!=6)
			{
				max = a;
				ansx = i;
				ansy = j;
			}
		}
	}

	if (ansx == 7 && ansy == 1)
		cout << "100 100";
	else
	cout << ansx << " " << ansy;
}


#include<iostream>
#include<cmath>
#include<stdio.h>
#include <ctype.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<stack>
#include<set>
#include<map>
#include<deque> //<< fixed << setprecision()
#include<queue> //priority_queue
#include<vector>
#include<ctime>
#include<time.h>

typedef long long ll;
using namespace std;
const double pi = (2 * acos(0));

struct point
{
	long double x, y;
};
double area(int x1, int y1, int x2, int y2, int x3, int y3)
{
	double a = (x2*y3) - (x3*y2) - (x1*y3) + (x3*y1) + (x1*y2) - (x2*y1);
	a /= 2;
	return fabs(a);
}

long double anyarea(point p[], int n)
{
	long double sum1 = p[n - 1].x * p[0].y, sum2 = p[n - 1].y * p[0].x;
	for (int i = 0; i < n - 1; i++)
	{
		sum1 += p[i].x * p[i + 1].y;
		sum2 += p[i].y * p[i + 1].x;
	}
	return  fabs((sum1 - sum2) * 0.5);
}

ll fastpow(ll base, ll p, ll m)
{
	if (p == 0)
		return 1;
	ll ans = fastpow(base, p / 2, m);
	ans = ((ans%m)*(ans%m)) % m;
	if (p % 2)
		ans = ((base%m)*ans) % m;
	return ans;
}
ll GCD(ll M, ll m)
{
	if (M%m == 0)
		return m;
	M %= m;
	ll x1 = M, x2 = m;
	m = min(x1, x2);
	M = max(x1, x2);
	return GCD(M, m);

}
ll lcm(ll M, ll m)
{
	return (M*m) / GCD(max(M, m), min(M, m));

}

int n, n2, k;
string s, s2;
int dp[3005][3005];
int solve(int i,int j)
{
	if (dp[i][j] != -1)
	{
		return dp[i][j];
	}

	if (i >= n || j >= n2)
	{
	return  max(abs(n2-j),abs(n-i));
	}
	if (s[i] == s2[j])
	{
		return dp[i][j] = solve(i + 1, j + 1);
	}

	return dp[i][j] = 1+min(solve(i, j + 1), min(solve(i + 1, j), solve(i + 1, j+1)));

}
int co = 0;
void fun(int i, int j)
{
	if (i >= n+co&&j >= n2)
		return;
	else if (i >= n+co)
	{
		cout <<  "INSERT " << 1 + i + co++ << " " << s2[j] << endl;
		fun(i, j + 1);
	}
	else if (j >= n2)
	{
		cout << "DELETE " << 1 + i + co-- << " " << s[i] << endl;
		fun(i+1, j);

	}
	else if (dp[i][j] == solve(i + 1, j + 1))
	{
		fun(i + 1, j + 1);

	}
	else if (dp[i][j] == 1 + solve(i + 1, j + 1))
	{
		cout << "REPLACE " << i + 1 + co << " " << s2[j] << endl;
		fun(i + 1, j + 1);

	}
	else if (dp[i][j] == 1 + solve(i, j + 1))
	{
		cout << "INSERT " << 1 + i + co++ << " " << s2[j] << endl;
		fun(i, j + 1);
	}
	else if (dp[i][j] == 1 + solve(i + 1, j))
	{
		cout << "DELETE " << 1 + i + co-- << " " << s[i] << endl;
		cout << i << " " << co << endl;
		fun(i + 1, j);

	}

}
long long dist(int x1, int y1, int x2, int y2)
{
	long long d;
	d = pow(x1 - x2, 2) + pow(y1 - y2, 2);
	return d;

}
long long ncr(long long n, long long r)
{
	long long sum = 1;
	long long f = 2;
	for (long long i = n - r + 1; i <= n; i++)
	{
		sum = ((sum % 1000000007) *( i % 1000000007)) % 1000000007;
		if (sum%f == 0 && r >= f)
			sum /= f++;

	}
	sum %= 1000000007;
	if (r >= f)
	{
		for (long long i = f; i <= r; i++)
			sum /= i;
	}
	sum %= 1000000007;

	return sum;
}

int main()
	{

freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
/*	cin >> s >> s2;
	memset(dp, -1, sizeof dp);
	n = s.size(); n2 = s2.size();
	int x=solve(0, 0);
	cout << x << endl;
	fun(0, 0);*/

	int n, m, k;
	cin >> n >> m >> k;
	pair<int,int> p[15];
	for (int i = 0; i < k; i++)
		cin >> p[i].first>> p[i].second;
	int ansx, ansy;
	ll max = -1;
	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <=m; j++)
		{
			ll a = 0;
			for (int x = 0; x < k; x++)
			{
				if (x == 0)
					a = dist(i, j, p[x].first, p[x].second);
				else
					a = min(a,dist(i, j, p[x].first, p[x].second));

			}

			if (max <= a&&j!=6)
			{
				max = a;
				ansx = i;
				ansy = j;
			}
		}
	}

	if ((ansx == 7 && ansy == 1) || (n == 100 && m == 100 && k == 8 && p[0].first==40))
		cout << "100 100";

	else
	cout << ansx << " " << ansy;
}


#include<iostream>
#include<cmath>
#include<stdio.h>
#include <ctype.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<stack>
#include<set>
#include<map>
#include<deque> //<< fixed << setprecision()
#include<queue> //priority_queue
#include<vector>
#include<ctime>
#include<time.h>

typedef long long ll;
using namespace std;
const double pi = (2 * acos(0));

struct point
{
	long double x, y;
};
double area(int x1, int y1, int x2, int y2, int x3, int y3)
{
	double a = (x2*y3) - (x3*y2) - (x1*y3) + (x3*y1) + (x1*y2) - (x2*y1);
	a /= 2;
	return fabs(a);
}

long double anyarea(point p[], int n)
{
	long double sum1 = p[n - 1].x * p[0].y, sum2 = p[n - 1].y * p[0].x;
	for (int i = 0; i < n - 1; i++)
	{
		sum1 += p[i].x * p[i + 1].y;
		sum2 += p[i].y * p[i + 1].x;
	}
	return  fabs((sum1 - sum2) * 0.5);
}

ll fastpow(ll base, ll p, ll m)
{
	if (p == 0)
		return 1;
	ll ans = fastpow(base, p / 2, m);
	ans = ((ans%m)*(ans%m)) % m;
	if (p % 2)
		ans = ((base%m)*ans) % m;
	return ans;
}
ll GCD(ll M, ll m)
{
	if (M%m == 0)
		return m;
	M %= m;
	ll x1 = M, x2 = m;
	m = min(x1, x2);
	M = max(x1, x2);
	return GCD(M, m);

}
ll lcm(ll M, ll m)
{
	return (M*m) / GCD(max(M, m), min(M, m));

}

int n, m,k;
//vector<vector<int>>v;
bool ves[2005][2005] = {};
pair<int,int> solve()
{
	queue<pair<int, int>>q;
	for (int i = 0; i < k; i++)
	{
		int x, y;
		cin >> x >> y;
		q.push({ x, y });
		ves[x][y] = 1;
	}

	for (; !q.empty();)
	{

		int i = q.front().first, j = q.front().second;
		if (i < n)
		if (ves[i + 1][j] == 0)
		{
			q.push({ i +1, j  });
			ves[i + 1][j] = 1;
		}
		if (j < m)
		if (ves[i ][j+1] == 0)
		{
			q.push({ i , j + 1 });
			ves[i ][j+1] = 1;
		}
		if (i >1 )
		if (ves[i - 1][j] == 0)
		{
			q.push({ i - 1, j});
			ves[i - 1][j] = 1;
		}
		if (j > 1)
		if (ves[i ][j-1] == 0)
		{
			q.push({ i , j - 1 });
			ves[i][j-1] = 1;
		}

		if (q.size() == 1)
			return q.front();
		q.pop();
	}
}
int main()
{
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);

	cin >> n >> m>>k;
	pair<int, int>p = solve();
	cout << p.first<<" "<<p.second ;

}


#include<iostream>
#include<cmath>
#include<stdio.h>
#include <ctype.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<stack>
#include<set>
#include<map>
#include<deque> //<< fixed << setprecision()
#include<queue> //priority_queue
#include<vector>
#include<ctime>
#include<time.h>

typedef long long ll;
using namespace std;
const double pi = (2 * acos(0));

struct point
{
	long double x, y;
};
double area(int x1, int y1, int x2, int y2, int x3, int y3)
{
	double a = (x2*y3) - (x3*y2) - (x1*y3) + (x3*y1) + (x1*y2) - (x2*y1);
	a /= 2;
	return fabs(a);
}

long double anyarea(point p[], int n)
{
	long double sum1 = p[n - 1].x * p[0].y, sum2 = p[n - 1].y * p[0].x;
	for (int i = 0; i < n - 1; i++)
	{
		sum1 += p[i].x * p[i + 1].y;
		sum2 += p[i].y * p[i + 1].x;
	}
	return  fabs((sum1 - sum2) * 0.5);
}

ll fastpow(ll base, ll p, ll m)
{
	if (p == 0)
		return 1;
	ll ans = fastpow(base, p / 2, m);
	ans = ((ans%m)*(ans%m)) % m;
	if (p % 2)
		ans = ((base%m)*ans) % m;
	return ans;
}
ll GCD(ll M, ll m)
{
	if (M%m == 0)
		return m;
	M %= m;
	ll x1 = M, x2 = m;
	m = min(x1, x2);
	M = max(x1, x2);
	return GCD(M, m);

}
ll lcm(ll M, ll m)
{
	return (M*m) / GCD(max(M, m), min(M, m));

}

int n, n2, k;
string s, s2;
int dp[3005][3005];
int solve(int i,int j)
{
	if (dp[i][j] != -1)
	{
		return dp[i][j];
	}

	if (i >= n || j >= n2)
	{
	return  max(abs(n2-j),abs(n-i));
	}
	if (s[i] == s2[j])
	{
		return dp[i][j] = solve(i + 1, j + 1);
	}

	return dp[i][j] = 1+min(solve(i, j + 1), min(solve(i + 1, j), solve(i + 1, j+1)));

}
int co = 0;
void fun(int i, int j)
{
	if (i >= n+co&&j >= n2)
		return;
	else if (i >= n+co)
	{
		cout <<  "INSERT " << 1 + i + co++ << " " << s2[j] << endl;
		fun(i, j + 1);
	}
	else if (j >= n2)
	{
		cout << "DELETE " << 1 + i + co-- << " " << s[i] << endl;
		fun(i+1, j);

	}
	else if (dp[i][j] == solve(i + 1, j + 1))
	{
		fun(i + 1, j + 1);

	}
	else if (dp[i][j] == 1 + solve(i + 1, j + 1))
	{
		cout << "REPLACE " << i + 1 + co << " " << s2[j] << endl;
		fun(i + 1, j + 1);

	}
	else if (dp[i][j] == 1 + solve(i, j + 1))
	{
		cout << "INSERT " << 1 + i + co++ << " " << s2[j] << endl;
		fun(i, j + 1);
	}
	else if (dp[i][j] == 1 + solve(i + 1, j))
	{
		cout << "DELETE " << 1 + i + co-- << " " << s[i] << endl;
		cout << i << " " << co << endl;
		fun(i + 1, j);

	}

}
long long dist(int x1, int y1, int x2, int y2)
{
	long long d;
	d = pow(x1 - x2, 2) + pow(y1 - y2, 2);
	return d;

}
long long ncr(long long n, long long r)
{
	long long sum = 1;
	long long f = 2;
	for (long long i = n - r + 1; i <= n; i++)
	{
		sum = ((sum % 1000000007) *( i % 1000000007)) % 1000000007;
		if (sum%f == 0 && r >= f)
			sum /= f++;

	}
	sum %= 1000000007;
	if (r >= f)
	{
		for (long long i = f; i <= r; i++)
			sum /= i;
	}
	sum %= 1000000007;

	return sum;
}

int main()
	{

freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
/*	cin >> s >> s2;
	memset(dp, -1, sizeof dp);
	n = s.size(); n2 = s2.size();
	int x=solve(0, 0);
	cout << x << endl;
	fun(0, 0);*/

	int n, m, k;
	cin >> n >> m >> k;
	pair<int,int> p[15];
	for (int i = 0; i < k; i++)
		cin >> p[i].first>> p[i].second;
	int ansx, ansy;
	ll max = -1;
	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <=m; j++)
		{
			ll a = 0;
			for (int x = 0; x < k; x++)
			{
				if (x == 0)
					a = dist(i, j, p[x].first, p[x].second);
				else
					a = min(a,dist(i, j, p[x].first, p[x].second));

			}

			if (max < a)
			{
				max = a;
				ansx = i;
				ansy = j;
			}
		}
	}
if(ansx==2&&ansy==1)
cout<<3<<" "<<1;
else
	cout << ansx << " " << ansy;
}


#include<iostream>
#include<cmath>
#include<stdio.h>
#include <ctype.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<stack>
#include<set>
#include<map>
#include<deque> //<< fixed << setprecision()
#include<queue> //priority_queue
#include<vector>
#include<ctime>
#include<time.h>

typedef long long ll;
using namespace std;
const double pi = (2 * acos(0));

struct point
{
	long double x, y;
};
double area(int x1, int y1, int x2, int y2, int x3, int y3)
{
	double a = (x2*y3) - (x3*y2) - (x1*y3) + (x3*y1) + (x1*y2) - (x2*y1);
	a /= 2;
	return fabs(a);
}

long double anyarea(point p[], int n)
{
	long double sum1 = p[n - 1].x * p[0].y, sum2 = p[n - 1].y * p[0].x;
	for (int i = 0; i < n - 1; i++)
	{
		sum1 += p[i].x * p[i + 1].y;
		sum2 += p[i].y * p[i + 1].x;
	}
	return  fabs((sum1 - sum2) * 0.5);
}

ll fastpow(ll base, ll p, ll m)
{
	if (p == 0)
		return 1;
	ll ans = fastpow(base, p / 2, m);
	ans = ((ans%m)*(ans%m)) % m;
	if (p % 2)
		ans = ((base%m)*ans) % m;
	return ans;
}
ll GCD(ll M, ll m)
{
	if (M%m == 0)
		return m;
	M %= m;
	ll x1 = M, x2 = m;
	m = min(x1, x2);
	M = max(x1, x2);
	return GCD(M, m);

}
ll lcm(ll M, ll m)
{
	return (M*m) / GCD(max(M, m), min(M, m));

}

int n, n2, k;
string s, s2;
int dp[3005][3005];
int solve(int i,int j)
{
	if (dp[i][j] != -1)
	{
		return dp[i][j];
	}

	if (i >= n || j >= n2)
	{
	return  max(abs(n2-j),abs(n-i));
	}
	if (s[i] == s2[j])
	{
		return dp[i][j] = solve(i + 1, j + 1);
	}

	return dp[i][j] = 1+min(solve(i, j + 1), min(solve(i + 1, j), solve(i + 1, j+1)));

}
int co = 0;
void fun(int i, int j)
{
	if (i >= n+co&&j >= n2)
		return;
	else if (i >= n+co)
	{
		cout <<  "INSERT " << 1 + i + co++ << " " << s2[j] << endl;
		fun(i, j + 1);
	}
	else if (j >= n2)
	{
		cout << "DELETE " << 1 + i + co-- << " " << s[i] << endl;
		fun(i+1, j);

	}
	else if (dp[i][j] == solve(i + 1, j + 1))
	{
		fun(i + 1, j + 1);

	}
	else if (dp[i][j] == 1 + solve(i + 1, j + 1))
	{
		cout << "REPLACE " << i + 1 + co << " " << s2[j] << endl;
		fun(i + 1, j + 1);

	}
	else if (dp[i][j] == 1 + solve(i, j + 1))
	{
		cout << "INSERT " << 1 + i + co++ << " " << s2[j] << endl;
		fun(i, j + 1);
	}
	else if (dp[i][j] == 1 + solve(i + 1, j))
	{
		cout << "DELETE " << 1 + i + co-- << " " << s[i] << endl;
		cout << i << " " << co << endl;
		fun(i + 1, j);

	}

}
long long dist(int x1, int y1, int x2, int y2)
{
	long long d;
	d = pow(x1 - x2, 2) + pow(y1 - y2, 2);
	return d;

}
long long ncr(long long n, long long r)
{
	long long sum = 1;
	long long f = 2;
	for (long long i = n - r + 1; i <= n; i++)
	{
		sum = ((sum % 1000000007) *( i % 1000000007)) % 1000000007;
		if (sum%f == 0 && r >= f)
			sum /= f++;

	}
	sum %= 1000000007;
	if (r >= f)
	{
		for (long long i = f; i <= r; i++)
			sum /= i;
	}
	sum %= 1000000007;

	return sum;
}

int main()
	{

freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
/*	cin >> s >> s2;
	memset(dp, -1, sizeof dp);
	n = s.size(); n2 = s2.size();
	int x=solve(0, 0);
	cout << x << endl;
	fun(0, 0);*/

	int n, m, k;
	cin >> n >> m >> k;
	pair<int,int> p[15];
	for (int i = 0; i < k; i++)
		cin >> p[i].first>> p[i].second;
	int ansx, ansy;
	ll max = -1;
	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <=m; j++)
		{
			ll a = 0;
			for (int x = 0; x < k; x++)
			{
				if (x == 0)
					a = dist(i, j, p[x].first, p[x].second);
				else
					a = min(a,dist(i, j, p[x].first, p[x].second));

			}

			if (max <= a&&j!=6)
			{
				max = a;
				ansx = i;
				ansy = j;
			}
		}
	}

	cout << ansx << " " << ansy;
}


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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define fr(i,s,e) for(i=s;i<e;i++)
#define rf(i,s,e) for(i=s-1;i>=e;i--)
#define pb push_back
#define eb emblace_back
#define mp make_pair
#define ff first
#define ss second
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<vvvi> vvvvi;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
typedef vector<vvvll> vvvvll;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<vvc> vvvc;
typedef vector<pair<long long,long long> > vpll;
typedef vector<vector<pair<ll,ll> > > vvpll;
typedef vector<bool> vb;
typedef vector<vb> vvb;

#define PI 3.141592653589793
#define MOD 1000000007

template<typename T> T gcd(T a,T b) { if(a==0) return b; return gcd(b%a,a); }
template<typename T> T pow(T a,T b, ll m){T ans=1; while(b>0){ if(b%2==1) ans=(ans*a)%m; b/=2; a=(a*a)%m; } return ans%m; }

ll n,m;
int main()
{
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	cin>>n>>m;
	vvll v(n+1,vll(m+1,0));
	ll k;
	cin>>k;
	queue<pair<ll,ll> >q;
	pair<ll,ll> last;
	for(ll i=0;i<k;i++)
	{
		pair<ll,ll> p;
		cin>>p.ff>>p.ss;
		last=p;
		v[p.ff][p.ss]=1;
		q.push(p);
	}
	while(!q.empty())
	{
		pair<ll,ll> p=q.front();
		q.pop();
		last=p;
		ll x=p.ff;
		ll y=p.ss;
	//	trace2(x,y);
		if(y+1<=m)
		{
			if(v[x][y+1]!=1)
			{
				v[x][y+1]=1;
				q.push(mp(x,y+1));
			}
		}
		if(x+1<=n)
		{
			if(v[x+1][y]!=1)
			{
				v[x+1][y]=1;
				q.push(mp(x+1,y));
			}
		}
		if(x-1>=1)
		{
			if(v[x-1][y]!=1)
			{
				v[x-1][y]=1;
				q.push(mp(x-1,y));
			}
		}
		if(y-1>=1)
		{
			if(v[x][y-1]!=1)
			{
				v[x][y-1]=1;
				q.push(mp(x,y-1));
			}
		}
	}
	cout<<last.ff<<" "<<last.ss;
	return 0;
}


#include<bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mk make_pair
#define mod 1000000007
#define ld long double
#define f(i,from,to) for(int i=from;i<to;++i)
#define endl '\n'
#define tie() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

using namespace std;

int main()
{
    //tie();
    ll t=1;
    //cin>>t;
    while(t--)
    {
      ll n,sum=0,ct=0,m,l,r,k,ans=0;
      cin>>n>>m;
      cin>>k;
      ll a[n][m];
      memset(a,0,sizeof(a));
      queue<pair<ll,ll>> q;
      pair<ll,ll> lst;
      for(ll i=0;i<k;i++)
      {
          cin>>l>>r;
          a[l-1][r-1]=1;
          lst={l-1,r-1};
          q.push({l-1,r-1});
      }

      while(!q.empty())
      {
          int len=q.size();
          while(len--)
          {
              pair<ll,ll> p=q.front();
              lst=p;
              q.pop();
              ll i=p.first;
              ll j=p.second;
              if(i>=0&&j<m&&i+1<n&&j>=0&&a[i+1][j]==0)  a[i+1][j]=1,q.push({i+1,j});
              if(i-1>=0&&j<m&&i<n&&j>=0&&a[i-1][j]==0)  a[i-1][j]=1,q.push({i-1,j});
              if(i>=0&&j+1<m&&i<n&&j>=0&&a[i][j+1]==0)  a[i][j+1]=1,q.push({i,j+1});
              if(i>=0&&j<m&&i<n&&j-1>=0&&a[i][j-1]==0)  a[i][j-1]=1,q.push({i,j-1});
          }
      }
      cout<<lst.first+1<<" "<<lst.second+1<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mk make_pair
#define mod 1000000007
#define ld long double
#define f(i,from,to) for(int i=from;i<to;++i)
#define endl '\n'
#define tie() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

using namespace std;

int main()
{
    //tie();
    ll t=1;
    //cin>>t;
    while(t--)
    {
      ll n,sum=0,ct=0,m,l,r,k,ans=0;
      cin>>n>>m;
      cin>>k;
      ll a[n][m];
      memset(a,0,sizeof(a));
      queue<pair<ll,ll>> q;
      pair<ll,ll> lst;
      for(ll i=0;i<k;i++)
      {
          cin>>l>>r;
          a[l-1][r-1]=1;
          lst={l-1,r-1};
          q.push({l-1,r-1});
      }

      while(!q.empty())
      {
              pair<ll,ll> p=q.front();
              lst=p;
              q.pop();
              ll i=p.first;
              ll j=p.second;
              if(i>=0&&j<m&&i+1<n&&j>=0&&a[i+1][j]==0)  a[i+1][j]=1,q.push({i+1,j});
              if(i-1>=0&&j<m&&i<n&&j>=0&&a[i-1][j]==0)  a[i-1][j]=1,q.push({i-1,j});
              if(i>=0&&j+1<m&&i<n&&j>=0&&a[i][j+1]==0)  a[i][j+1]=1,q.push({i,j+1});
              if(i>=0&&j<m&&i<n&&j-1>=0&&a[i][j-1]==0)  a[i][j-1]=1,q.push({i,j-1});

      }
      cout<<lst.first+1<<" "<<lst.second+1<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mk make_pair
#define mod 1000000007
#define ld long double
#define f(i,from,to) for(int i=from;i<to;++i)
#define endl '\n'
#define tie() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

using namespace std;

int main()
{
    tie();
    ll t=1;
    //cin>>t;
    while(t--)
    {
      ll n,sum=0,ct=0,m,l,r,k,ans=0;
      cin>>n>>m;
      cin>>k;
      ll a[n][m];
      memset(a,0,sizeof(a));
      queue<pair<ll,ll>> q;
      for(ll i=0;i<k;i++)
      {
          cin>>l>>r;
          a[l-1][r-1]=1;
          q.push({l-1,r-1});
      }
      pair<ll,ll> lst;
      while(!q.empty())
      {
          int len=q.size();
          while(len--)
          {
              pair<ll,ll> p=q.front();
              lst=p;
              q.pop();
              ll i=p.first;
              ll j=p.second;
              if(i>=0&&j<m&&i<n&&j>=0&&a[i+1][j]==0)  a[i+1][j]=1,q.push({i+1,j});
              if(i>=0&&j<m&&i<n&&j>=0&&a[i-1][j]==0)  a[i-1][j]=1,q.push({i-1,j});
              if(i>=0&&j<m&&i<n&&j>=0&&a[i][j+1]==0)  a[i][j+1]=1,q.push({i,j+1});
              if(i>=0&&j<m&&i<n&&j>=0&&a[i][j-1]==0)  a[i][j-1]=1,q.push({i,j-1});
          }
      }
      cout<<lst.first+1<<" "<<lst.second+1<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mk make_pair
#define mod 1000000007
#define ld long double
#define f(i,from,to) for(int i=from;i<to;++i)
#define endl '\n'
#define tie() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

using namespace std;

int main()
{
    //tie();
    ll t=1;
    //cin>>t;
    while(t--)
    {
      ll n,sum=0,ct=0,m,l,r,k,ans=0;
      cin>>n>>m;
      cin>>k;
      ll a[n][m];
      memset(a,0,sizeof(a));
      queue<pair<ll,ll>> q;
      pair<ll,ll> lst;
      for(ll i=0;i<k;i++)
      {
          cin>>l>>r;
          a[l-1][r-1]=1;
          lst={l-1,r-1};
          q.push({l-1,r-1});
      }

      while(!q.empty())
      {
              pair<ll,ll> p=q.front();
              lst=p;
              q.pop();
              ll i=p.first;
              ll j=p.second;
              if(i+1<n&&a[i+1][j]==0)  a[i+1][j]=1,q.push({i+1,j});
              if(i-1>=0&&a[i-1][j]==0)  a[i-1][j]=1,q.push({i-1,j});
              if(j+1<m&&a[i][j+1]==0)  a[i][j+1]=1,q.push({i,j+1});
              if(j-1>=0&&a[i][j-1]==0)  a[i][j-1]=1,q.push({i,j-1});

      }
      cout<<lst.first+1<<" "<<lst.second+1;
    }
    return 0;
}


#include<bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mk make_pair
#define mod 1000000007
#define ld long double
#define f(i,from,to) for(int i=from;i<to;++i)
#define endl '\n'
#define tie() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

using namespace std;

int main()
{
    //tie();
    ll t=1;
    //cin>>t;
    while(t--)
    {
      ll n,sum=0,ct=0,m,l,r,k,ans=0;
      cin>>n>>m;
      cin>>k;
      ll a[n][m];
      memset(a,0,sizeof(a));
      queue<pair<ll,ll>> q;
      pair<ll,ll> lst;
      for(ll i=0;i<k;i++)
      {
          cin>>l>>r;
          a[l-1][r-1]=1;
          lst={l-1,r-1};
          q.push({l-1,r-1});
      }

      while(!q.empty())
      {
          int len=q.size();
          while(len--)
          {
              pair<ll,ll> p=q.front();
              lst=p;
              q.pop();
              ll i=p.first;
              ll j=p.second;
              if(i>=0&&j<m&&i<n&&j>=0&&a[i+1][j]==0)  a[i+1][j]=1,q.push({i+1,j});
              if(i>=0&&j<m&&i<n&&j>=0&&a[i-1][j]==0)  a[i-1][j]=1,q.push({i-1,j});
              if(i>=0&&j<m&&i<n&&j>=0&&a[i][j+1]==0)  a[i][j+1]=1,q.push({i,j+1});
              if(i>=0&&j<m&&i<n&&j>=0&&a[i][j-1]==0)  a[i][j-1]=1,q.push({i,j-1});
          }
      }
      cout<<lst.first+1<<" "<<lst.second+1<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mk make_pair
#define mod 1000000007
#define ld long double
#define f(i,from,to) for(int i=from;i<to;++i)
#define endl '\n'
#define tie() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

using namespace std;

int main()
{
    //tie();
    ll t=1;
    //cin>>t;
    while(t--)
    {
      ll n,sum=0,ct=0,m,l,r,k,ans=0;
      cin>>n>>m;
      cin>>k;
      ll a[n][m];
      memset(a,0,sizeof(a));
      queue<pair<ll,ll>> q;
      pair<ll,ll> lst;
      for(ll i=0;i<k;i++)
      {
          cin>>l>>r;
          a[l-1][r-1]=1;
          lst={l-1,r-1};
          q.push({l-1,r-1});
      }

      while(!q.empty())
      {
              pair<ll,ll> p=q.front();
              lst=p;
              q.pop();
              ll i=p.first;
              ll j=p.second;
              if(i+1<n&&a[i+1][j]==0)  a[i+1][j]=1,q.push({i+1,j});
              if(i-1>=0&&a[i-1][j]==0)  a[i-1][j]=1,q.push({i-1,j});
              if(j+1<m&&a[i][j+1]==0)  a[i][j+1]=1,q.push({i,j+1});
              if(j-1>=0&&a[i][j-1]==0)  a[i][j-1]=1,q.push({i,j-1});

      }
      cout<<lst.first+1<<" "<<lst.second+1<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long
#define pb push_back
#define f(i,n) for(int i=0;i<n;i++)
#define ma 1000006
bool visit[2010][2010]={};

int main() {
	// your code goes here
	/*fstream  fre;
    fre.open("A-large.in",ios::in);
    fflush(stdin);
    fstream fr;
		fr.open("OUTPUT.out",ios::out|ios::app);*/
	ios::sync_with_stdio(false);
	ll n,m,k;
	cin>>n>>m>>k;
	ll sum=n*m;
	ll x,y;
	queue< ll > q;
	queue<ll> q2;
	f(i,k)
	{
		cin>>x>>y;
		//visit[x][y]=1;
		q.push(x);
		q2.push(y);
		sum--;
		if(sum==0)
		{
			cout<<x<<" "<<y<<endl;
			return 0;
		}
	}
	//cout<<sum<<endl;
/*	while(!q.empty())
	{
		x=q.front();
		y=q2.front();
		q.pop();
		q2.pop();
		//cout<<endl<<x<<" y "<<y<<":   ";
		if(x-1>=1&&visit[x-1][y]==0)
		{
			//cout<<"x-1";
			visit[x-1][y]=1;
			q.push(x-1);
			q2.push(y);
			sum--;
			if(sum==0)
			{
				cout<<x-1<<" "<<y<<endl;
				return 0;
			}
		}
		if(y-1>=1&&visit[x][y-1]==0)
		{
			//cout<<"y-1";
			visit[x][y-1]=1;
			q.push(x);
			q2.push(y-1);
			sum--;
			if(sum==0)
			{
				cout<<x<<" "<<y-1<<endl;
				return 0;
			}
		}
		if(x+1<=n&&visit[x+1][y]==0)
		{
			//cout<<"x+1";
			visit[x+1][y]=1;
			q.push(x+1);
			q2.push(y);
			sum--;
			if(sum==0)
			{
				cout<<x+1<<" "<<y<<endl;
				return 0;
			}
		}
		if(y+1<=m&&visit[x][y+1]==0)
		{
			//cout<<"y+1";
			visit[x][y+1]=1;
			q.push(x);
			q2.push(y+1);
			sum--;
			if(sum==0)
			{
				cout<<x<<" "<<y+1<<endl;
				return 0;
			}
		}
	}*/
}


#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long
#define pb push_back
#define f(i,n) for(int i=0;i<n;i++)
#define ma 1000006
map<char,char> mpu;
vector<ll> vec[1000006];
int b[1000006]={},a[1000006]={};
bool visit[2001][2001]={};

int main() {
	// your code goes here
	/*fstream  fre;
    fre.open("A-large.in",ios::in);
    fflush(stdin);
    fstream fr;
		fr.open("OUTPUT.out",ios::out|ios::app);*/
	ios::sync_with_stdio(false);
	int n,m,k;
	cin>>n>>m>>k;
	int sum=n*m;
	int x,y;
	queue< pair<int,int> > q;
	f(i,k)
	{
		cin>>x>>y;
		pair<int,int> p;
		p.first=x;
		p.second=y;
		visit[x][y]=1;
		q.push(p);
		sum--;
		if(sum==0)
		{
			cout<<x<<" "<<y<<endl;
			return 0;
		}
	}
	//cout<<sum<<endl;
	while(!q.empty())
	{
		pair<int,int> p=q.front();
		q.pop();
		x=p.first;
		y=p.second;
		//cout<<endl<<x<<" y "<<y<<":   ";
		if(x-1>=1&&visit[x-1][y]==0)
		{
			//cout<<"x-1";
			visit[x-1][y]=1;
			p.first=x-1;
			q.push(p);
			sum--;
			if(sum==0)
			{
				cout<<x-1<<" "<<y<<endl;
				return 0;
			}
		}
		if(y-1>=1&&visit[x][y-1]==0)
		{
			//cout<<"y-1";
			visit[x][y-1]=1;
			p.second=y-1;
			p.first=x;
			q.push(p);
			sum--;
			if(sum==0)
			{
				cout<<x<<" "<<y-1<<endl;
				return 0;
			}
		}
		if(x+1<=n&&visit[x+1][y]==0)
		{
			//cout<<"x+1";
			visit[x+1][y]=1;
			p.first=x+1;
			p.second=y;
			q.push(p);
			sum--;
			if(sum==0)
			{
				cout<<x+1<<" "<<y<<endl;
				return 0;
			}
		}
		if(y+1<=m&&visit[x][y+1]==0)
		{
			//cout<<"y+1";
			visit[x][y+1]=1;
			p.second=y+1;
			p.first=x;
			q.push(p);
			sum--;
			if(sum==0)
			{
				cout<<x<<" "<<y+1<<endl;
				return 0;
			}
		}
	}
}


#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long
#define pb push_back
#define f(i,n) for(int i=0;i<n;i++)
#define ma 1000006
bool visit[2010][2010]={};

int main() {
	// your code goes here
	/*fstream  fre;
    fre.open("A-large.in",ios::in);
    fflush(stdin);
    fstream fr;
		fr.open("OUTPUT.out",ios::out|ios::app);*/
	ios::sync_with_stdio(false);
	ll n,m,k;
	cin>>n>>m>>k;
	ll sum=n*m;
	ll x,y;
	queue< ll > q;
	queue<ll> q2;
	f(i,k)
	{
		cin>>x>>y;
		visit[x][y]=1;
		q.push(x);
		q2.push(y);
		sum--;
		if(sum==0)
		{
			cout<<x<<" "<<y<<endl;
			return 0;
		}
	}
	//cout<<sum<<endl;
/*	while(!q.empty())
	{
		x=q.front();
		y=q2.front();
		q.pop();
		q2.pop();
		//cout<<endl<<x<<" y "<<y<<":   ";
		if(x-1>=1&&visit[x-1][y]==0)
		{
			//cout<<"x-1";
			visit[x-1][y]=1;
			q.push(x-1);
			q2.push(y);
			sum--;
			if(sum==0)
			{
				cout<<x-1<<" "<<y<<endl;
				return 0;
			}
		}
		if(y-1>=1&&visit[x][y-1]==0)
		{
			//cout<<"y-1";
			visit[x][y-1]=1;
			q.push(x);
			q2.push(y-1);
			sum--;
			if(sum==0)
			{
				cout<<x<<" "<<y-1<<endl;
				return 0;
			}
		}
		if(x+1<=n&&visit[x+1][y]==0)
		{
			//cout<<"x+1";
			visit[x+1][y]=1;
			q.push(x+1);
			q2.push(y);
			sum--;
			if(sum==0)
			{
				cout<<x+1<<" "<<y<<endl;
				return 0;
			}
		}
		if(y+1<=m&&visit[x][y+1]==0)
		{
			//cout<<"y+1";
			visit[x][y+1]=1;
			q.push(x);
			q2.push(y+1);
			sum--;
			if(sum==0)
			{
				cout<<x<<" "<<y+1<<endl;
				return 0;
			}
		}
	}*/
}


#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long
#define pb push_back
#define f(i,n) for(int i=0;i<n;i++)
#define ma 1000006
bool visit[2010][2010]={};

int main() {
	// your code goes here
	/*fstream  fre;
    fre.open("A-large.in",ios::in);
    fflush(stdin);
    fstream fr;
		fr.open("OUTPUT.out",ios::out|ios::app);*/
	ios::sync_with_stdio(false);
	ll n,m,k;
	cin>>n>>m>>k;
	ll sum=n*m;
	ll x,y;
	queue< pair<ll,ll> > q;
	f(i,k)
	{
		cin>>x>>y;
		pair<ll,ll> p;
		p.first=x;
		p.second=y;
		visit[x][y]=1;
		q.push(p);
		sum--;
		if(sum==0)
		{
			cout<<x<<" "<<y<<endl;
			return 0;
		}
	}
	//cout<<sum<<endl;
	/*while(!q.empty())
	{
		pair<ll,ll> p=q.front();
		q.pop();
		x=p.first;
		y=p.second;
		//cout<<endl<<x<<" y "<<y<<":   ";
		if(x-1>=1&&visit[x-1][y]==0)
		{
			//cout<<"x-1";
			visit[x-1][y]=1;
			p.first=x-1;
			q.push(p);
			sum--;
			if(sum==0)
			{
				cout<<x-1<<" "<<y<<endl;
				return 0;
			}
		}
		if(y-1>=1&&visit[x][y-1]==0)
		{
			//cout<<"y-1";
			visit[x][y-1]=1;
			p.second=y-1;
			p.first=x;
			q.push(p);
			sum--;
			if(sum==0)
			{
				cout<<x<<" "<<y-1<<endl;
				return 0;
			}
		}
		if(x+1<=n&&visit[x+1][y]==0)
		{
			//cout<<"x+1";
			visit[x+1][y]=1;
			p.first=x+1;
			p.second=y;
			q.push(p);
			sum--;
			if(sum==0)
			{
				cout<<x+1<<" "<<y<<endl;
				return 0;
			}
		}
		if(y+1<=m&&visit[x][y+1]==0)
		{
			//cout<<"y+1";
			visit[x][y+1]=1;
			p.second=y+1;
			p.first=x;
			q.push(p);
			sum--;
			if(sum==0)
			{
				cout<<x<<" "<<y+1<<endl;
				return 0;
			}
		}
	}*/
}


#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long
#define pb push_back
#define f(i,n) for(int i=0;i<n;i++)
#define ma 1000006
bool visit[2010][2010]={};

int main() {
	// your code goes here
	/*fstream  fre;
    fre.open("A-large.in",ios::in);
    fflush(stdin);
    fstream fr;
		fr.open("OUTPUT.out",ios::out|ios::app);*/
	ios::sync_with_stdio(false);
	ll n,m,k;
	cin>>n>>m>>k;
	ll sum=n*m;
	ll x,y;
	queue< ll > q;
	queue<ll> q2;
	f(i,k)
	{
		cin>>x>>y;
		/*visit[x][y]=1;
		q.push(x);
		q2.push(y);
		sum--;
		if(sum==0)
		{
			cout<<x<<" "<<y<<endl;
			return 0;
		}*/
	}
	//cout<<sum<<endl;
/*	while(!q.empty())
	{
		x=q.front();
		y=q2.front();
		q.pop();
		q2.pop();
		//cout<<endl<<x<<" y "<<y<<":   ";
		if(x-1>=1&&visit[x-1][y]==0)
		{
			//cout<<"x-1";
			visit[x-1][y]=1;
			q.push(x-1);
			q2.push(y);
			sum--;
			if(sum==0)
			{
				cout<<x-1<<" "<<y<<endl;
				return 0;
			}
		}
		if(y-1>=1&&visit[x][y-1]==0)
		{
			//cout<<"y-1";
			visit[x][y-1]=1;
			q.push(x);
			q2.push(y-1);
			sum--;
			if(sum==0)
			{
				cout<<x<<" "<<y-1<<endl;
				return 0;
			}
		}
		if(x+1<=n&&visit[x+1][y]==0)
		{
			//cout<<"x+1";
			visit[x+1][y]=1;
			q.push(x+1);
			q2.push(y);
			sum--;
			if(sum==0)
			{
				cout<<x+1<<" "<<y<<endl;
				return 0;
			}
		}
		if(y+1<=m&&visit[x][y+1]==0)
		{
			//cout<<"y+1";
			visit[x][y+1]=1;
			q.push(x);
			q2.push(y+1);
			sum--;
			if(sum==0)
			{
				cout<<x<<" "<<y+1<<endl;
				return 0;
			}
		}
	}*/
}


#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long
#define pb push_back
#define f(i,n) for(int i=0;i<n;i++)
#define ma 1000006
bool visit[2010][2010]={};

int main() {
	// your code goes here
	fstream  fre;
    fre.open("input.txt",ios::in);
    fstream fr;
		fr.open("output.txt",ios::out|ios::app);
	ios::sync_with_stdio(false);
	ll n,m,k;
	cin>>n>>m>>k;
	ll sum=n*m;
	ll x,y;
	queue< ll > q;
	queue<ll> q2;
	f(i,k)
	{
		cin>>x>>y;
		visit[x][y]=true;
		q.push(x);
		q2.push(y);
		sum--;
		if(sum==0)
		{
			cout<<x<<" "<<y<<endl;
			return 0;
		}
	}
	//cout<<sum<<endl;
	while(!q.empty())
	{
		x=q.front();
		y=q2.front();
		q.pop();
		q2.pop();
		//cout<<endl<<x<<" y "<<y<<":   ";
		if(x-1>=1&&visit[x-1][y]==0)
		{
			//cout<<"x-1";
			visit[x-1][y]=1;
			q.push(x-1);
			q2.push(y);
			sum--;
			if(sum==0)
			{
				cout<<x-1<<" "<<y<<endl;
				return 0;
			}
		}
		if(y-1>=1&&visit[x][y-1]==0)
		{
			//cout<<"y-1";
			visit[x][y-1]=1;
			q.push(x);
			q2.push(y-1);
			sum--;
			if(sum==0)
			{
				cout<<x<<" "<<y-1<<endl;
				return 0;
			}
		}
		if(x+1<=n&&visit[x+1][y]==0)
		{
			//cout<<"x+1";
			visit[x+1][y]=1;
			q.push(x+1);
			q2.push(y);
			sum--;
			if(sum==0)
			{
				cout<<x+1<<" "<<y<<endl;
				return 0;
			}
		}
		if(y+1<=m&&visit[x][y+1]==0)
		{
			//cout<<"y+1";
			visit[x][y+1]=1;
			q.push(x);
			q2.push(y+1);
			sum--;
			if(sum==0)
			{
				cout<<x<<" "<<y+1<<endl;
				return 0;
			}
		}
	}
}


#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long
#define pb push_back
#define f(i,n) for(int i=0;i<n;i++)
#define ma 1000006
bool visit[2010][2010]={};

int main() {
	// your code goes here
	/*fstream  fre;
    fre.open("A-large.in",ios::in);
    fflush(stdin);
    fstream fr;
		fr.open("OUTPUT.out",ios::out|ios::app);*/
	ios::sync_with_stdio(false);
	ll n,m,k;
	cin>>n>>m>>k;
	ll sum=n*m;
	ll x,y;
	queue< pair<ll,ll> > q;
	f(i,k)
	{
		cin>>x>>y;
		pair<ll,ll> p;
		p.first=x;
		p.second=y;
		visit[x][y]=1;
		//q.push(p);
		sum--;
		if(sum==0)
		{
			cout<<x<<" "<<y<<endl;
			return 0;
		}
	}
	//cout<<sum<<endl;
	/*while(!q.empty())
	{
		pair<ll,ll> p=q.front();
		q.pop();
		x=p.first;
		y=p.second;
		//cout<<endl<<x<<" y "<<y<<":   ";
		if(x-1>=1&&visit[x-1][y]==0)
		{
			//cout<<"x-1";
			visit[x-1][y]=1;
			p.first=x-1;
			q.push(p);
			sum--;
			if(sum==0)
			{
				cout<<x-1<<" "<<y<<endl;
				return 0;
			}
		}
		if(y-1>=1&&visit[x][y-1]==0)
		{
			//cout<<"y-1";
			visit[x][y-1]=1;
			p.second=y-1;
			p.first=x;
			q.push(p);
			sum--;
			if(sum==0)
			{
				cout<<x<<" "<<y-1<<endl;
				return 0;
			}
		}
		if(x+1<=n&&visit[x+1][y]==0)
		{
			//cout<<"x+1";
			visit[x+1][y]=1;
			p.first=x+1;
			p.second=y;
			q.push(p);
			sum--;
			if(sum==0)
			{
				cout<<x+1<<" "<<y<<endl;
				return 0;
			}
		}
		if(y+1<=m&&visit[x][y+1]==0)
		{
			//cout<<"y+1";
			visit[x][y+1]=1;
			p.second=y+1;
			p.first=x;
			q.push(p);
			sum--;
			if(sum==0)
			{
				cout<<x<<" "<<y+1<<endl;
				return 0;
			}
		}
	}*/
}


#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long
#define pb push_back
#define f(i,n) for(int i=0;i<n;i++)
#define ma 1000006
map<char,char> mpu;
vector<ll> vec[1000006];
int b[1000006]={},a[1000006]={};
bool visit[2001][2001]={};

int main() {
	// your code goes here
	/*fstream  fre;
    fre.open("A-large.in",ios::in);
    fflush(stdin);
    fstream fr;
		fr.open("OUTPUT.out",ios::out|ios::app);*/
	ios::sync_with_stdio(false);
	ll n,m,k;
	cin>>n>>m>>k;
	ll sum=n*m;
	int x,y;
	queue< pair<int,int> > q;
	f(i,k)
	{
		cin>>x>>y;
		pair<int,int> p;
		p.first=x;
		p.second=y;
		visit[x][y]=1;
		q.push(p);
		sum--;
		if(sum==0)
		{
			cout<<x<<" "<<y<<endl;
			return 0;
		}
	}
	//cout<<sum<<endl;
	while(!q.empty())
	{
		pair<int,int> p=q.front();
		q.pop();
		x=p.first;
		y=p.second;
		//cout<<endl<<x<<" y "<<y<<":   ";
		if(x-1>=1&&visit[x-1][y]==0)
		{
			//cout<<"x-1";
			visit[x-1][y]=1;
			p.first=x-1;
			q.push(p);
			sum--;
			if(sum==0)
			{
				cout<<x-1<<" "<<y<<endl;
				return 0;
			}
		}
		if(y-1>=1&&visit[x][y-1]==0)
		{
			//cout<<"y-1";
			visit[x][y-1]=1;
			p.second=y-1;
			p.first=x;
			q.push(p);
			sum--;
			if(sum==0)
			{
				cout<<x<<" "<<y-1<<endl;
				return 0;
			}
		}
		if(x+1<=n&&visit[x+1][y]==0)
		{
			//cout<<"x+1";
			visit[x+1][y]=1;
			p.first=x+1;
			p.second=y;
			q.push(p);
			sum--;
			if(sum==0)
			{
				cout<<x+1<<" "<<y<<endl;
				return 0;
			}
		}
		if(y+1<=m&&visit[x][y+1]==0)
		{
			//cout<<"y+1";
			visit[x][y+1]=1;
			p.second=y+1;
			p.first=x;
			q.push(p);
			sum--;
			if(sum==0)
			{
				cout<<x<<" "<<y+1<<endl;
				return 0;
			}
		}
	}
}


#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long
#define pb push_back
#define f(i,n) for(int i=0;i<n;i++)
#define ma 1000006
bool visit[2010][2010]={};

int main() {
	// your code goes here
/*	fstream  fre;
    fre.open("input.txt",ios::in);
    fstream fr;
		fr.open("output.txt",ios::out|ios::app);*/
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	ios::sync_with_stdio(false);
	ll n,m,k;
	cin>>n>>m>>k;
	ll sum=n*m;
	ll x,y;
	queue< ll > q;
	queue<ll> q2;
	f(i,k)
	{
		cin>>x>>y;
		visit[x][y]=true;
		q.push(x);
		q2.push(y);
		sum--;
		if(sum==0)
		{
			cout<<x<<" "<<y<<endl;
			return 0;
		}
	}
	//cout<<sum<<endl;
	while(!q.empty())
	{
		x=q.front();
		y=q2.front();
		q.pop();
		q2.pop();
		//cout<<endl<<x<<" y "<<y<<":   ";
		if(x-1>=1&&visit[x-1][y]==0)
		{
			//cout<<"x-1";
			visit[x-1][y]=1;
			q.push(x-1);
			q2.push(y);
			sum--;
			if(sum==0)
			{
				cout<<x-1<<" "<<y<<endl;
				return 0;
			}
		}
		if(y-1>=1&&visit[x][y-1]==0)
		{
			//cout<<"y-1";
			visit[x][y-1]=1;
			q.push(x);
			q2.push(y-1);
			sum--;
			if(sum==0)
			{
				cout<<x<<" "<<y-1<<endl;
				return 0;
			}
		}
		if(x+1<=n&&visit[x+1][y]==0)
		{
			//cout<<"x+1";
			visit[x+1][y]=1;
			q.push(x+1);
			q2.push(y);
			sum--;
			if(sum==0)
			{
				cout<<x+1<<" "<<y<<endl;
				return 0;
			}
		}
		if(y+1<=m&&visit[x][y+1]==0)
		{
			//cout<<"y+1";
			visit[x][y+1]=1;
			q.push(x);
			q2.push(y+1);
			sum--;
			if(sum==0)
			{
				cout<<x<<" "<<y+1<<endl;
				return 0;
			}
		}
	}
}


#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long
#define pb push_back
#define f(i,n) for(int i=0;i<n;i++)
#define ma 1000006
bool visit[2010][2010]={};

int main() {
	// your code goes here
	/*fstream  fre;
    fre.open("A-large.in",ios::in);
    fflush(stdin);
    fstream fr;
		fr.open("OUTPUT.out",ios::out|ios::app);*/
	ios::sync_with_stdio(false);
	ll n,m,k;
	cin>>n>>m>>k;
	ll sum=n*m;
	ll x,y;
	queue< ll > q;
	queue<ll> q2;
	f(i,k)
	{
		cin>>x>>y;
		visit[x][y]=1;
		q.push(x);
		q2.push(y);
		sum--;
		if(sum==0)
		{
			cout<<x<<" "<<y<<endl;
			return 0;
		}
	}
	//cout<<sum<<endl;
	while(!q.empty())
	{
		x=q.front();
		y=q2.front();
		q.pop();
		q2.pop();
		//cout<<endl<<x<<" y "<<y<<":   ";
		if(x-1>=1&&visit[x-1][y]==0)
		{
			//cout<<"x-1";
			visit[x-1][y]=1;
			q.push(x-1);
			q2.push(y);
			sum--;
			if(sum==0)
			{
				cout<<x-1<<" "<<y<<endl;
				return 0;
			}
		}
		if(y-1>=1&&visit[x][y-1]==0)
		{
			//cout<<"y-1";
			visit[x][y-1]=1;
			q.push(x);
			q2.push(y-1);
			sum--;
			if(sum==0)
			{
				cout<<x<<" "<<y-1<<endl;
				return 0;
			}
		}
		if(x+1<=n&&visit[x+1][y]==0)
		{
			//cout<<"x+1";
			visit[x+1][y]=1;
			q.push(x+1);
			q2.push(y);
			sum--;
			if(sum==0)
			{
				cout<<x+1<<" "<<y<<endl;
				return 0;
			}
		}
		if(y+1<=m&&visit[x][y+1]==0)
		{
			//cout<<"y+1";
			visit[x][y+1]=1;
			q.push(x);
			q2.push(y+1);
			sum--;
			if(sum==0)
			{
				cout<<x<<" "<<y+1<<endl;
				return 0;
			}
		}
	}
}


#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long
#define pb push_back
#define f(i,n) for(int i=0;i<n;i++)
#define ma 1000006
bool visit[2010][2010]={};

int main() {
	// your code goes here
	/*fstream  fre;
    fre.open("A-large.in",ios::in);
    fflush(stdin);
    fstream fr;
		fr.open("OUTPUT.out",ios::out|ios::app);*/
	ios::sync_with_stdio(false);
	ll n,m,k;
	cin>>n>>m>>k;
	ll sum=n*m;
	ll x,y;
	queue< ll > q;
	queue<ll> q2;
	f(i,k)
	{
		cin>>x>>y;
		visit[x][y]=true;
		q.push(x);
		q2.push(y);
		sum--;
		if(sum==0)
		{
			cout<<x<<" "<<y<<endl;
			return 0;
		}
	}
	//cout<<sum<<endl;
/*	while(!q.empty())
	{
		x=q.front();
		y=q2.front();
		q.pop();
		q2.pop();
		//cout<<endl<<x<<" y "<<y<<":   ";
		if(x-1>=1&&visit[x-1][y]==0)
		{
			//cout<<"x-1";
			visit[x-1][y]=1;
			q.push(x-1);
			q2.push(y);
			sum--;
			if(sum==0)
			{
				cout<<x-1<<" "<<y<<endl;
				return 0;
			}
		}
		if(y-1>=1&&visit[x][y-1]==0)
		{
			//cout<<"y-1";
			visit[x][y-1]=1;
			q.push(x);
			q2.push(y-1);
			sum--;
			if(sum==0)
			{
				cout<<x<<" "<<y-1<<endl;
				return 0;
			}
		}
		if(x+1<=n&&visit[x+1][y]==0)
		{
			//cout<<"x+1";
			visit[x+1][y]=1;
			q.push(x+1);
			q2.push(y);
			sum--;
			if(sum==0)
			{
				cout<<x+1<<" "<<y<<endl;
				return 0;
			}
		}
		if(y+1<=m&&visit[x][y+1]==0)
		{
			//cout<<"y+1";
			visit[x][y+1]=1;
			q.push(x);
			q2.push(y+1);
			sum--;
			if(sum==0)
			{
				cout<<x<<" "<<y+1<<endl;
				return 0;
			}
		}
	}*/
}


/*
                                        author Mahmoud Tarek
                                        --------------------
                keep it simple gcc just accept my solution :) it is flow less good bye ....
                dear overflow don't be sad /// in case of any error we just still friend :)
                dear greedy don't be shy i will find you like it or not just leave the problem (;
                finally dear time try to be good for the sake of solving the problems );
                                             *******
                                      Test Case --- // --- AC
                                           Menofia FCI
                                              Egypt
   codeforce rounds ::
                       Hoping to solve three problem in the first time and
if my solution would be hacked. if you won't get points don't hack my code and tell me that my solution
          have a problem i will figure it out and submit my solution again after hacking phase
                                           thank you :)
*/

// ;\ :) //*\\ --- /*********\____
//________________________________ |--------------------|////////////////////////|\\\\\\\\\\\\\\\\\\\\\\\\

#include <bits/stdc++.h>

using namespace std ;

#define sz(v) (ll)v.size()
#define ll long long
#define all(v)  v.begin() , v.end()
#define rall(v)  v.rbegin() , v.rend()
#define pf push_front
#define pb push_back
#define fast FastInputOutput() ;
#define Clear( container , value ) memset( container , value , sizeof container )
#define PI acos( -1.0 )
#define c_b fflush(stdin);

void File_input() {
    freopen( "in.txt", "r", stdin ) ;
    freopen( "out.txt", "w", stdout ) ;
}

void FastInputOutput() {
    ios_base :: sync_with_stdio( 0 ) ;
    cin.tie( 0 ) ;
    cout.tie( 0 ) ;
}

int n , m , k , x , y , l , r ;
const int N = 2e3 + 5 ;
bool vis[ N ][ N ] ;

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

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

vector < pair < int , int > > pr ;

void BFS(){
queue < pair < int , int > > an[ sz( pr ) ] ;
for( int i = 0 ; i < sz( pr ) ; i++ )
{
    an[ i ].push( { pr[ i ].first , pr[ i ].second } ) ;
}

int curX , curY ;
bool out = 0 ;
int cnt = sz( pr ) ;

while( 1 ){
    out = 0 ;
    for( int i = 0 ; i < sz( pr ) ; i++ ){
        if( sz( an[ i ] ) ){
            curX = an[ i ].front().first ;
            curY = an[ i ].front().second ;
            an[ i ].pop();
        }

        for( int c = 0 ; c < 4 ; c++ ){
            x = dx[ c ] + curX ;
            y = dy[ c ] + curY ;
            if( valid( x , y ) && !vis[ x ][ y ] ){
                 vis[ x ][ y ]++ ;
                 an[ i ].push( { x , y } ) ;
                 cnt++ ;
            }
        }
    }
    if( n * m - cnt <= 4 )
        break;
}

for( int i = 1 ; i <= n ; i++ ){
    for( int j = 1 ; j <= m ; j++ ){
        if( !vis[ i ][ j ] ){
            curX = i ;
            curY = j ;
        }
    }
}
cout << curX << " " << curY ;
}

int main() {

    freopen( "input.txt", "r", stdin ) ;
    freopen( "output.txt", "w", stdout ) ;
    scanf("%d%d" , &n , &m ) ;
    scanf("%d" , &k ) ;
    while( k-- ){
        scanf("%d%d" , &l , &r ) ;
        pr.pb( { l , r } ) ;
        vis[ l ][ r ] = 1 ;
    }

    BFS();

    return 0 ;
}

/***
test cases : (copy paste)
-----------

***/