/*
                                        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(){
priority_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 ;

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

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

    if( !out ){
        cout << curX << " " << curY ;
        break ;
    }
}

}

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)
-----------

***/


/*
                                        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 ] ){
            cout << i << " " << j << "\n" ;
            return ;
        }
    }
}

}

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)
-----------

***/


/*
                                        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 > > gr ;
for( int i = 0 ; i < sz( pr ) ; i++ ){
    gr.push( { pr[ i ].first , pr[ i ].second } ) ;
}

int curX , curY ;

while( sz( gr ) ){
    curX = gr.front().first ;
    curY = gr.front().second ;
    gr.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 ] = 1 ;
            gr.push( { x , y } ) ;
        }
    }

}
printf("%d %d" , 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 ;
    }
    sort( rall( pr ) ) ;
    BFS();

    return 0 ;
}

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

***/


/*
                                        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 ;

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();
            out = 1 ;
        }

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

    if( !out ){
        cout << curX << " " << curY ;
        break ;
    }
}

}

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)
-----------

***/


/*
                                        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 > > gr ;
for( int i = 0 ; i < sz( pr ) ; i++ ){
    gr.push( { pr[ i ].first , pr[ i ].second } ) ;
}

int curX , curY ;

while( sz( gr ) ){
    curX = gr.front().first ;
    curY = gr.front().second ;
    gr.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 ] = 1 ;
            gr.push( { x , y } ) ;
        }
    }

}
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)
-----------

***/


/*
                                        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 , id ;
const int N = 2e3 + 5 ;
int 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 ;
id = 1 ;

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();
            out = 1 ;
        }

        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 ] = id++ ;
                 an[ i ].push( { x , y } ) ;
            }
        }
    }

    if( !out ){
        break ;
    }
}

}

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 ] = id++ ;
    }

    BFS();
    int mx = 0 ;
    for( int i = 1 ; i <= n ; i++ ){
        for( int j = 1 ; j <= m ; j++ ){
           if( vis[ i ][ j ] > mx ){
            mx = max( mx , vis[ i ][ j ] ) ;
            x = i , y = j ;
           }
        }
    }

    cout << x << " " << y ;

    return 0 ;
}

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

***/


/*
                                        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 ;
int 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 ;

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();
            out = 1 ;
        }

        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 } ) ;
            } else if( valid( x , y ) ){
                 vis[ x ][ y ]++ ;
            }
        }
    }

    if( !out ){
        //cout << curX << " " << curY ;
        break ;
    }
}

}

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

    int mn = 1e9 , cx , cy ;

    BFS();
    for( int i = 1;  i <= n ; i++ ){
         for( int j = 1 ; j <= m ; j++ ){
             if( vis[ i ][ j ] < mn ){
                mn = vis[ i ][ j ] ;
                cx = i ;
                cy = j ;
             }
         }
    }

    cout << cx << " " << cy ;

    return 0 ;
}

/***
test cases : (copy paste)
-----------
3 3
8
1 2
1 3
2 1
2 2
2 3
3 1
3 2
3 3

***/


/*
                                        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 ;

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();
            out = 1 ;
        }

        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 } ) ;
                 break;
            }
        }
    }

    if( !out ){
        cout << curX << " " << curY ;
        break ;
    }
}

}

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)
-----------

***/


/*
                                        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 , id ;
const int N = 2e3 + 5 ;
int 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 ;
}

bool last = 0 ;
int curX , curY ;

void DFS( int i , int j ){

for( int c = 0 ; c < 4 ; c++ ){
    x = dx[ c ] + i ;
    y = dy[ c ] + j ;
    if( valid( x , y ) && !vis[ x ][ y ] ){
        vis[ x ][ y ] = id++ ;
        DFS( x , y ) ;
    }
}

}

int main() {

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

    scanf("%d%d" , &n , &m ) ;
    scanf("%d" , &k ) ;
    id = 1 ;
    while( k-- ){
        scanf("%d%d" , &l , &r ) ;
    }

    DFS( l , r ) ;
    int mx = 0 ;

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

    printf("%d %d" , curX , curY ) ;
    return 0 ;
}

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

***/


/*
                                        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 > > gr ;
for( int i = 0 ; i < sz( pr ) ; i++ ){
    gr.push( { pr[ i ].first , pr[ i ].second } ) ;
}

int curX , curY ;

while( sz( gr ) ){
    curX = gr.front().first ;
    curY = gr.front().second ;
    gr.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 ] = 1 ;
            gr.push( { x , y } ) ;
        }
    }

}
printf("%d %d" , 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)
-----------

***/


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mk make_pair
#define ub upper_bound
#define lb lower_bound
#define ff first
#define ss second
#define inf 1000000009
#define mod 1000000007
#define vll vector<ll>
#define for0(i,n) for(ll i=0;i<n;i++)
#define all(c) c.begin(),c.end()
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MAX 2005
#define pi 3.141592653589793238462643383279502884

ll n,m,z;
ll dx[4]={0,0,+1,-1};
ll dy[4]={+1,-1,0,0};
bool vis[MAX][MAX];

void solve()
{

   cin>>n>>m;
   memset(vis,false,sizeof(vis));
   pair<ll,ll>last;
   queue<pair<ll,ll>>q;

   cin>>z;
   while(z--)
   {
       ll x,y;
       cin>>x>>y;
       vis[x][y]=true;
       q.push({x,y});
   }
   while(!q.empty())
   {
       pair<ll,ll>p=q.front();
       q.pop();
       last=p;
       for(ll i=0;i<4;i++)
       {
           ll x=p.ff+dx[i];
           ll y=p.ss+dy[i];
           if(x>=1 && x<=n && y>=1 && y<=m)
           {
               if(vis[x][y]==false)
               {
                   vis[x][y]=true;
                   q.push({x,y});
               }
           }
       }
   }
   cout<<last.ff<<" "<<last.ss<<endl;

}
int main()
{
    fio;
    ll t;
    //cin>>t;
    t=1;
    while(t--)
    solve();
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mk make_pair
#define ub upper_bound
#define lb lower_bound
#define ff first
#define ss second
#define inf 1000000009
#define mod 1000000007
#define vll vector<ll>
#define for0(i,n) for(ll i=0;i<n;i++)
#define all(c) c.begin(),c.end()
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MAX 2005
#define pi 3.141592653589793238462643383279502884

ll n,m,z;
ll dx[4]={0,0,+1,-1};
ll dy[4]={+1,-1,0,0};
bool vis[MAX][MAX];

void solve()
{

   cin>>n>>m;

   pair<ll,ll>last;
   queue<pair<ll,ll>>q;

   cin>>z;
   while(z--)
   {
       ll x,y;
       cin>>x>>y;
       vis[x][y]=true;
       q.push({x,y});
   }
   while(!q.empty())
   {
       pair<ll,ll>p=q.front();
       q.pop();
       last=p;
       for(ll i=0;i<4;i++)
       {
           ll x=p.ff+dx[i];
           ll y=p.ss+dy[i];
           if(x>=1 && x<=n && y>=1 && y<=m)
           {
               if(vis[x][y]==false)
               {
                   vis[x][y]=true;
                   q.push({x,y});
               }
           }
       }
   }
   cout<<last.ff<<" "<<last.ss<<endl;

}
int main()
{
    fio;
    ll t;
    //cin>>t;
    t=1;
    while(t--)
    solve();
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mk make_pair
#define ub upper_bound
#define lb lower_bound
#define ff first
#define ss second
#define inf 1000000009
#define mod 1000000007
#define vll vector<ll>
#define for0(i,n) for(ll i=0;i<n;i++)
#define all(c) c.begin(),c.end()
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MAX 2005
#define pi 3.141592653589793238462643383279502884

ll n,m;
ll v[MAX][MAX];
ll res=0;
map<pair<pair<ll,ll>,ll>,ll>dp;
void fun(ll x,ll y,ll t)
{
    //cout<<x<<" "<<y<<endl;
    if(x>n || y>m || x<1 || y<1)
    return;

    if(t>v[x][y])
    return;

    v[x][y]=t;

    fun(x+1,y,t+1);
    fun(x-1,y,t+1);
    fun(x,y-1,t+1);
    fun(x,y+1,t+1);

    return;
}
void solve()
{
    cin>>n>>m;
    ll k;cin>>k;
    memset(v,inf,sizeof(v));

    for(ll i=0;i<k;i++)
    {
        ll x,y;
        cin>>x>>y;
        fun(x,y,0);
    }
    ll x1=0,y1=0;
    for(ll i=1;i<=n;i++)
    {
        for(ll j=1;j<=m;j++)
        {
            //cout<<v[i][j]<<" ";
            if(v[i][j]>res)
            {
                res=v[i][j];
                x1=i;y1=j;
            }
        }
        //cout<<endl;
    }

    cout<<x1<<" "<<y1<<endl;

    return;
}
int main()
{
    fio;
    ll t;
    //cin>>t;
    t=1;
    while(t--)
    solve();
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mk make_pair
#define ub upper_bound
#define lb lower_bound
#define ff first
#define ss second
#define inf 1000000009
#define mod 1000000007
#define vll vector<ll>
#define for0(i,n) for(ll i=0;i<n;i++)
#define all(c) c.begin(),c.end()
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MAX 2005
#define pi 3.141592653589793238462643383279502884

ll dx[4]={0,0,+1,-1};
ll dy[4]={+1,-1,0,0};
void solve()
{
   ll n,m;
   cin>>n>>m;
   ll v[n+1][m+1];
   bool vis[n+1][m+1];
   memset(vis,false,sizeof(vis));
   pair<ll,ll>last;
   queue<pair<ll,ll>>q;
   ll z;
   cin>>z;
   while(z--)
   {
       ll x,y;
       cin>>x>>y;
       v[x][y]=true;
       q.push({x,y});
   }
   while(!q.empty())
   {
       pair<ll,ll>p=q.front();
       q.pop();
       last=p;
       for(ll i=0;i<4;i++)
       {
           ll x=p.ff+dx[i];
           ll y=p.ss+dy[i];
           if(x>=1 && x<=n && y>=1 && y<=m)
           {
               if(vis[x][y]==false)
               {
                   vis[x][y]=true;
                   q.push({x,y});
               }
           }
       }
   }
   cout<<last.ff<<" "<<last.ss<<endl;

}
int main()
{
    fio;
    ll t;
    //cin>>t;
    t=1;
    while(t--)
    solve();
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mk make_pair
#define ub upper_bound
#define lb lower_bound
#define ff first
#define ss second
#define inf 1000000009
#define mod 1000000007
#define vll vector<ll>
#define for0(i,n) for(ll i=0;i<n;i++)
#define all(c) c.begin(),c.end()
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MAX 105
#define pi 3.141592653589793238462643383279502884

ll n,m;
ll v[MAX][MAX];
ll res=0;
map<pair<pair<ll,ll>,ll>,ll>dp;
void fun(ll x,ll y,ll t)
{
    //cout<<x<<" "<<y<<endl;
    if(t>v[x][y])
    return;

    if(x>n || y>m || x<1 || y<1)
    return;

    // pair<pair<ll,ll>,ll>p={{x,y},t};
    // if(dp.find)

    v[x][y]=t;

    fun(x+1,y,t+1);
    fun(x-1,y,t+1);
    fun(x,y-1,t+1);
    fun(x,y+1,t+1);

    // if(t>=res)
    // {
    //     res=t;
    //     x1=x;
    //     y2=y;
    // }
}
void solve()
{
    cin>>n>>m;
    ll k;cin>>k;
    memset(v,inf,sizeof(v));

    for(ll i=0;i<k;i++)
    {
        ll x,y;
        cin>>x>>y;
        fun(x,y,0);
    }
    ll x1=0,y1=0;
    for(ll i=1;i<=n;i++)
    {
        for(ll j=1;j<=m;j++)
        {
            //cout<<v[i][j]<<" ";
            if(v[i][j]>res)
            {
                res=v[i][j];
                x1=i;y1=j;
            }
        }
        //cout<<endl;
    }

    cout<<x1<<" "<<y1<<endl;
}
int main()
{

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


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mk make_pair
#define ub upper_bound
#define lb lower_bound
#define ff first
#define ss second
#define inf 1000000009
#define mod 1000000007
#define vll vector<ll>
#define for0(i,n) for(ll i=0;i<n;i++)
#define all(c) c.begin(),c.end()
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MAX 2005
#define pi 3.141592653589793238462643383279502884

ll n,m;
ll v[MAX][MAX];
ll res=0;
map<pair<pair<ll,ll>,ll>,ll>dp;
void fun(ll x,ll y,ll t)
{
    //cout<<x<<" "<<y<<endl;
    if(t>v[x][y])
    return;

    if(x>n || y>m || x<1 || y<1)
    return;

    // pair<pair<ll,ll>,ll>p={{x,y},t};
    // if(dp.find)

    v[x][y]=t;

    fun(x+1,y,t+1);
    fun(x-1,y,t+1);
    fun(x,y-1,t+1);
    fun(x,y+1,t+1);

    // if(t>=res)
    // {
    //     res=t;
    //     x1=x;
    //     y2=y;
    // }
}
void solve()
{
    cin>>n>>m;
    ll k;cin>>k;
    memset(v,inf,sizeof(v));

    for(ll i=0;i<k;i++)
    {
        ll x,y;
        cin>>x>>y;
        fun(x,y,0);
    }
    ll x1=0,y1=0;
    for(ll i=1;i<=n;i++)
    {
        for(ll j=1;j<=m;j++)
        {
            //cout<<v[i][j]<<" ";
            if(v[i][j]>res)
            {
                res=v[i][j];
                x1=i;y1=j;
            }
        }
        //cout<<endl;
    }

    cout<<x1<<" "<<y1<<endl;
}
int main()
{

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


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mk make_pair
#define ub upper_bound
#define lb lower_bound
#define ff first
#define ss second
#define inf 1000000009
#define mod 1000000007
#define vll vector<ll>
#define for0(i,n) for(ll i=0;i<n;i++)
#define all(c) c.begin(),c.end()
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MAX 2005
#define pi 3.141592653589793238462643383279502884

ll n,m;
ll v[MAX][MAX];
ll res=0;
map<pair<pair<ll,ll>,ll>,ll>dp;
void fun(ll x,ll y,ll t)
{
    //cout<<x<<" "<<y<<endl;
    if(x>n || y>m || x<1 || y<1)
    return;

    if(t>v[x][y])
    return;

    // pair<pair<ll,ll>,ll>p={{x,y},t};
    // if(dp.find)

    v[x][y]=t;

    fun(x+1,y,t+1);
    fun(x-1,y,t+1);
    fun(x,y-1,t+1);
    fun(x,y+1,t+1);

    // if(t>=res)
    // {
    //     res=t;
    //     x1=x;
    //     y2=y;
    // }
}
void solve()
{
    cin>>n>>m;
    ll k;cin>>k;
    memset(v,inf,sizeof(v));

    for(ll i=0;i<k;i++)
    {
        ll x,y;
        cin>>x>>y;
        fun(x,y,0);
    }
    ll x1=0,y1=0;
    for(ll i=1;i<=n;i++)
    {
        for(ll j=1;j<=m;j++)
        {
            //cout<<v[i][j]<<" ";
            if(v[i][j]>res)
            {
                res=v[i][j];
                x1=i;y1=j;
            }
        }
        //cout<<endl;
    }

    cout<<x1<<" "<<y1<<endl;
}
int main()
{

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


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mk make_pair
#define ub upper_bound
#define lb lower_bound
#define ff first
#define ss second
#define inf 1000000009
#define mod 1000000007
#define vll vector<ll>
#define for0(i,n) for(ll i=0;i<n;i++)
#define all(c) c.begin(),c.end()
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MAX 2005
#define pi 3.141592653589793238462643383279502884

ll dx[4]={0,0,+1,-1};
ll dy[4]={+1,-1,0,0};
bool vis[MAX][MAX];

void solve()
{
   ll n,m;
   cin>>n>>m;
   ll v[n+1][m+1];

   pair<ll,ll>last;
   queue<pair<ll,ll>>q;
   ll z;
   cin>>z;
   while(z--)
   {
       ll x,y;
       cin>>x>>y;
       v[x][y]=true;
       q.push({x,y});
   }
   while(!q.empty())
   {
       pair<ll,ll>p=q.front();
       q.pop();
       last=p;
       for(ll i=0;i<4;i++)
       {
           ll x=p.ff+dx[i];
           ll y=p.ss+dy[i];
           if(x>=1 && x<=n && y>=1 && y<=m)
           {
               if(vis[x][y]==false)
               {
                   vis[x][y]=true;
                   q.push({x,y});
               }
           }
       }
   }
   cout<<last.ff<<" "<<last.ss<<endl;

}
int main()
{
    fio;
    ll t;
    //cin>>t;
    t=1;
    while(t--)
    solve();
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mk make_pair
#define ub upper_bound
#define lb lower_bound
#define ff first
#define ss second
#define inf 1000000009
#define mod 1000000007
#define vll vector<ll>
#define for0(i,n) for(ll i=0;i<n;i++)
#define all(c) c.begin(),c.end()
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MAX 2005
#define pi 3.141592653589793238462643383279502884

ll n,m,z;
ll dx[4]={0,0,+1,-1};
ll dy[4]={+1,-1,0,0};
bool vis[MAX][MAX];

void solve()
{

   cin>>n>>m;
   memset(vis,false,sizeof(vis));
   pair<ll,ll>last;
   queue<pair<ll,ll>>q;

   cin>>z;
   while(z--)
   {
       ll x,y;
       cin>>x>>y;
       vis[x][y]=true;
       q.push({x,y});
   }
   while(!q.empty())
   {
       pair<ll,ll>p=q.front();
       q.pop();
       last=p;
       for(ll i=0;i<4;i++)
       {
           ll x=p.ff+dx[i];
           ll y=p.ss+dy[i];
           if(x>=1 && x<=n && y>=1 && y<=m)
           {
               if(vis[x][y]==false)
               {
                   vis[x][y]=true;
                   q.push({x,y});
               }
           }
       }
   }
   cout<<last.ff<<" "<<last.ss<<endl;

}
int main()
{
    fio;
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    ll t;
    //cin>>t;
    t=1;
    while(t--)
    solve();
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mk make_pair
#define ub upper_bound
#define lb lower_bound
#define ff first
#define ss second
#define inf 1000000009
#define mod 1000000007
#define vll vector<ll>
#define for0(i,n) for(ll i=0;i<n;i++)
#define all(c) c.begin(),c.end()
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MAX 2005
#define pi 3.141592653589793238462643383279502884

ll n,m;
ll v[MAX][MAX];
ll res=0;
map<pair<pair<ll,ll>,ll>,ll>dp;
void fun(ll x,ll y,ll t)
{
    //cout<<x<<" "<<y<<endl;
    if(x>n || y>m || x<1 || y<1)
    return;

    if(t>v[x][y])
    return;

    v[x][y]=t;

    fun(x+1,y,t+1);
    fun(x-1,y,t+1);
    fun(x,y-1,t+1);
    fun(x,y+1,t+1);

    return;
}
void solve()
{
    cin>>n>>m;
    ll k;cin>>k;
    memset(v,inf,sizeof(v));

    for(ll i=0;i<k;i++)
    {
        ll x,y;
        cin>>x>>y;
        fun(x,y,0);
    }
    ll x1=0,y1=0;
    for(ll i=1;i<=n;i++)
    {
        for(ll j=1;j<=m;j++)
        {
            //cout<<v[i][j]<<" ";
            if(v[i][j]>res)
            {
                res=v[i][j];
                x1=i;y1=j;
            }
        }
        //cout<<endl;
    }

    cout<<x1<<" "<<y1<<endl;
}
int main()
{

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


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mk make_pair
#define ub upper_bound
#define lb lower_bound
#define ff first
#define ss second
#define inf 1000000009
#define mod 1000000007
#define vll vector<ll>
#define for0(i,n) for(ll i=0;i<n;i++)
#define all(c) c.begin(),c.end()
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MAX 2005
#define pi 3.141592653589793238462643383279502884

ll n,m,z;
ll dx[4]={0,0,+1,-1};
ll dy[4]={+1,-1,0,0};
bool vis[MAX][MAX];

void solve()
{

   cin>>n>>m;

   pair<ll,ll>last;
   queue<pair<ll,ll>>q;

   cin>>z;
   while(z--)
   {
       ll x,y;
       cin>>x>>y;
       v[x][y]=true;
       q.push({x,y});
   }
   while(!q.empty())
   {
       pair<ll,ll>p=q.front();
       q.pop();
       last=p;
       for(ll i=0;i<4;i++)
       {
           ll x=p.ff+dx[i];
           ll y=p.ss+dy[i];
           if(x>=1 && x<=n && y>=1 && y<=m)
           {
               if(vis[x][y]==false)
               {
                   vis[x][y]=true;
                   q.push({x,y});
               }
           }
       }
   }
   cout<<last.ff<<" "<<last.ss<<endl;

}
int main()
{
    fio;
    ll t;
    //cin>>t;
    t=1;
    while(t--)
    solve();
}


/// إِنَّ مَعَ الْعُسْرِ يُسْرًا
/// لَا أَبْرَحُ حَتَّىٰ أَبْلُغَ

#include <bits/stdc++.h>
#define LL long long
#define LD long double
#define S second
#define IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define F first
#define PI acos(-1)
#define MAX 200005
#define file freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
using namespace std;
LL m,n;
LL mx=-1,ix=-1,iy=-1;
map< pair<LL,LL > ,LL>mp;

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

bool vaild(int x, int y)
{
    if(x<0 || x>=n || y<0 || y>=m)
        return 0;
    return 1;
}

void dfs(int x, int y , int c)
{
    if(c>=mp[{x,y}] && mp[{x,y}]!=0)
        return;
    mp[{x,y}]=c;
   // cout<<x<<" "<<y<<" "<<c<<endl;
    for(int i=0; i<4; i++)
    {
        if(vaild(x+dx[i],y+dy[i]))
        dfs(x+dx[i],y+dy[i],c+1);
       // cout<<i<<endl;
    }

}

int main()
{
    IO
    //file
    cin>>n>>m;
    LL v;
    cin>>v;

    while(v--)
    {
        LL a,b;
        cin>>a>>b;
        dfs(a-1,b-1,1);
    }
    for(int i=0 ; i<n ; i++){
        for(int j=0; j<m; j++)
        {
        if(mp[{i,j}]>mx)
        {
            mx=mp[{i,j}];
            ix=i+1;
            iy=j+1;
        }

       // cout<<mp[{i,j}]<<" ";

        }
        //cout<<endl;

    }

    cout<<ix<<" "<<iy;

    return 0;
}


/// إِنَّ مَعَ الْعُسْرِ يُسْرًا
/// لَا أَبْرَحُ حَتَّىٰ أَبْلُغَ

#include <bits/stdc++.h>
#define LL long long
#define LD long double
#define S second
#define IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define F first
#define PI acos(-1)
#define MAX 200005
#define file freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
using namespace std;
LL m,n;
LL mx=-1,ix=-1,iy=-1;
int dp[2005][2005];
queue< pair<LL,LL >   >Q;
LL dx[]={0,0,1,-1};
LL dy[]={1,-1,0,0};

bool vaild(int x, int y)
{
    if(x<0 || x>=n || y<0 || y>=m)
        return 0;
    return 1;
}

void bfs()
{
    LL c=0;

    while(!Q.empty())
    {

     LL x=Q.front().F;
     LL y=Q.front().S;
     Q.pop();
     if(dp[x][y])
        continue;
        dp[x][y]=1;
    for(int i=0; i<4; i++)
    {
        if(vaild(x+dx[i],y+dy[i]))
            {
                if( dp[x+dx[i]][y+dy[i]] ==0 )
                Q.push( {x+dx[i],y+dy[i] });
            }
    }
    ix=x+1;
    iy=y+1;

    }

}

int main()
{
    IO
   file
    cin>>n>>m;
    LL v;
    cin>>v;

    while(v--)
    {
        LL a,b;
        cin>>a>>b;
        Q.push({a-1,b-1});
    }
    bfs();

    cout<<ix<<" "<<iy;

    return 0;
}


/// إِنَّ مَعَ الْعُسْرِ يُسْرًا
/// لَا أَبْرَحُ حَتَّىٰ أَبْلُغَ

#include <bits/stdc++.h>
#define LL long long
#define LD long double
#define S second
#define IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define F first
#define PI acos(-1)
#define MAX 200005
using namespace std;
LL m,n;
LL mx=-1,ix=-1,iy=-1;
map< pair<LL,LL > ,LL>mp;

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

bool vaild(int x, int y)
{
    if(x<0 || x>=n || y<0 || y>=m)
        return 0;
    return 1;
}

void dfs(int x, int y , int c)
{
    if(c>=mp[{x,y}] && mp[{x,y}]!=0)
        return;
    mp[{x,y}]=c;
   // cout<<x<<" "<<y<<" "<<c<<endl;
    for(int i=0; i<8; i++)
    {
        if(vaild(x+dx[i],y+dy[i]))
        dfs(x+dx[i],y+dy[i],c+1);
       // cout<<i<<endl;
    }

}

int main()
{
    IO
    cin>>n>>m;
    LL v;
    cin>>v;

    while(v--)
    {
        LL a,b;
        cin>>a>>b;
        dfs(a-1,b-1,1);
    }
    for(int i=0 ; i<n ; i++)
        for(int j=0; j<m; j++)
        if(mp[{i,j}]>mx)
        {
            mx=mp[{i,j}];
            ix=i+1;
            iy=j+1;
        }

    cout<<ix<<" "<<iy;

    return 0;
}


/// إِنَّ مَعَ الْعُسْرِ يُسْرًا
/// لَا أَبْرَحُ حَتَّىٰ أَبْلُغَ

#include <bits/stdc++.h>
#define LL long long
#define LD long double
#define S second
#define IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define F first
#define PI acos(-1)
#define MAX 200005
#define file freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
using namespace std;
LL m,n;
LL mx=-1,ix=-1,iy=-1;
map< pair<LL,LL > ,LL>mp;

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

bool vaild(int x, int y)
{
    if(x<0 || x>=n || y<0 || y>=m)
        return 0;
    return 1;
}

void dfs(int x, int y , int c)
{
    if(c>=mp[{x,y}] && mp[{x,y}]!=0)
        return;
    mp[{x,y}]=c;
   // cout<<x<<" "<<y<<" "<<c<<endl;
    for(int i=0; i<8; i++)
    {
        if(vaild(x+dx[i],y+dy[i]))
        dfs(x+dx[i],y+dy[i],c+1);
       // cout<<i<<endl;
    }

}

int main()
{
    IO
    file
    cin>>n>>m;
    LL v;
    cin>>v;

    while(v--)
    {
        LL a,b;
        cin>>a>>b;
        dfs(a-1,b-1,1);
    }
    for(int i=0 ; i<n ; i++)
        for(int j=0; j<m; j++)
        if(mp[{i,j}]>mx)
        {
            mx=mp[{i,j}];
            ix=i+1;
            iy=j+1;
        }

    cout<<ix<<" "<<iy;

    return 0;
}


/// إِنَّ مَعَ الْعُسْرِ يُسْرًا
/// لَا أَبْرَحُ حَتَّىٰ أَبْلُغَ

#include <bits/stdc++.h>
#define LL long long
#define LD long double
#define S second
#define IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define F first
#define PI acos(-1)
#define MAX 200005
#define file freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
using namespace std;
LL m,n;
LL mx=-1,ix=-1,iy=-1;
int dp[2005][2005];
queue< pair<LL,LL >   >Q;
LL dx[]={0,0,1,-1};
LL dy[]={1,-1,0,0};

bool vaild(int x, int y)
{
    if(x<0 || x>=n || y<0 || y>=m)
        return 0;
    return 1;
}

void bfs()
{
    LL c=0;

    while(!Q.empty())
    {

     LL x=Q.front().F;
     LL y=Q.front().S;
     Q.pop();
     if(dp[x][y])
        continue;
        dp[x][y]=1;
    for(int i=0; i<4; i++)
    {
        if(vaild(x+dx[i],y+dy[i]))
            {

                Q.push( {x+dx[i],y+dy[i] });
            }
    }
    ix=x+1;
    iy=y+1;

    }

}

int main()
{
    IO
   file
    cin>>n>>m;
    LL v;
    cin>>v;

    while(v--)
    {
        LL a,b;
        cin>>a>>b;
        Q.push({a-1,b-1});
    }
    bfs();

    cout<<ix<<" "<<iy;

    return 0;
}


/// إِنَّ مَعَ الْعُسْرِ يُسْرًا
/// لَا أَبْرَحُ حَتَّىٰ أَبْلُغَ

#include <bits/stdc++.h>
#define LL long long
#define LD long double
#define S second
#define IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define F first
#define PI acos(-1)
#define MAX 200005
#define file freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
using namespace std;
LL m,n;
LL mx=-1,ix=-1,iy=-1;
map< pair<LL,LL > ,LL>mp;

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

bool vaild(int x, int y)
{
    if(x<0 || x>=n || y<0 || y>=m)
        return 0;
    return 1;
}

void dfs(int x, int y , int c)
{
    if(c>=mp[{x,y}] && mp[{x,y}]!=0)
        return;
    mp[{x,y}]=c;
   // cout<<x<<" "<<y<<" "<<c<<endl;
    for(int i=0; i<8; i++)
    {
        if(vaild(x+dx[i],y+dy[i]))
        dfs(x+dx[i],y+dy[i],c+1);
       // cout<<i<<endl;
    }

}

int main()
{
    IO
    file
    cin>>n>>m;
    LL v;
    cin>>v;

    while(v--)
    {
        LL a,b;
        cin>>a>>b;
        dfs(a-1,b-1,1);
    }
    for(int i=0 ; i<n ; i++)
        for(int j=0; j<m; j++)
        if(mp[{i,j}]>mx)
        {
            mx=mp[{i,j}];
            ix=i+1;
            iy=j+1;
        }

    cout<<ix<<" "<<iy;

    return 0;
}


/// إِنَّ مَعَ الْعُسْرِ يُسْرًا
/// لَا أَبْرَحُ حَتَّىٰ أَبْلُغَ

#include <bits/stdc++.h>
#define LL long long
#define LD long double
#define S second
#define IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define F first
#define PI acos(-1)
#define MAX 200005
#define file freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
using namespace std;
LL m,n;
LL mx=-1,ix=-1,iy=-1;
map< pair<LL,LL > ,LL>mp;
queue< pair< pair<LL,LL > ,LL > >Q;
LL dx[]={0,0,1,-1};
LL dy[]={1,-1,0,0};

bool vaild(int x, int y)
{
    if(x<0 || x>=n || y<0 || y>=m)
        return 0;
    return 1;
}

void bfs()
{

    while(!Q.empty())
    {
     LL x=Q.front().F.F;
     LL y=Q.front().F.S;
     LL c=Q.front().S;
     Q.pop();
    if( mp[{x,y}]!=0)
        continue;
    mp[{x,y}]=c;
    if(mp[{x,y}]>mx)
        {
            mx=mp[{x,y}];
            ix=x+1;
            iy=y+1;
        }
    for(int i=0; i<4; i++)
    {
        if(vaild(x+dx[i],y+dy[i]))
            {
                Q.push({ {x+dx[i],y+dy[i] },c+1});
            }

    }

    }

}

int main()
{
    IO
    file
    cin>>n>>m;
    LL v;
    cin>>v;

    while(v--)
    {
        LL a,b;
        cin>>a>>b;
        Q.push({{a-1,b-1},1});
    }
    bfs();

    cout<<ix<<" "<<iy;

    return 0;
}


/// إِنَّ مَعَ الْعُسْرِ يُسْرًا
/// لَا أَبْرَحُ حَتَّىٰ أَبْلُغَ

#include <bits/stdc++.h>
#define LL long long
#define LD long double
#define S second
#define IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define F first
#define PI acos(-1)
#define MAX 200005
#define file freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
using namespace std;
LL m,n;
LL mx=-1,ix=-1,iy=-1;
map< pair<LL,LL > ,LL>mp;

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

bool vaild(int x, int y)
{
    if(x<0 || x>=n || y<0 || y>=m)
        return 0;

    return 1;
}

void dfs(int x, int y , int c)
{
    if(c>=mp[{x,y}] && mp[{x,y}]!=0)
        return;
    mp[{x,y}]=c;
   // cout<<x<<" "<<y<<" "<<c<<endl;
    for(int i=0; i<8; i++)
    {
        if(vaild(x+dx[i],y+dy[i]))
        dfs(x+dx[i],y+dy[i],c+1);
       // cout<<i<<endl;
    }

}

int main()
{
    IO
    file
    cin>>n>>m;
    LL v;
    cin>>v;

    while(v--)
    {
        LL a,b;
        cin>>a>>b;
        dfs(a-1,b-1,1);
    }
    for(int i=0 ; i<n ; i++)
        for(int j=0; j<m; j++)
        if(mp[{i,j}]>mx)
        {
            mx=mp[{i,j}];
            ix=i+1;
            iy=j+1;
        }

    cout<<ix<<" "<<iy;

    return 0;
}


/// إِنَّ مَعَ الْعُسْرِ يُسْرًا
/// لَا أَبْرَحُ حَتَّىٰ أَبْلُغَ

#include <bits/stdc++.h>
#define LL long long
#define LD long double
#define S second
#define IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define F first
#define PI acos(-1)
#define MAX 200005
#define file freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
using namespace std;
LL m,n;
LL mx=-1,ix=-1,iy=-1;
map< pair<LL,LL > ,LL>mp;

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

bool vaild(int x, int y)
{
    if(x<0 || x>=n || y<0 || y>=m)
        return 0;
    return 1;
}

void dfs(int x, int y , int c)
{
    if(c>=mp[{x,y}] && mp[{x,y}]!=0)
        return;
    mp[{x,y}]=c;
   // cout<<x<<" "<<y<<" "<<c<<endl;
    for(int i=0; i<4; i++)
    {
        if(vaild(x+dx[i],y+dy[i]))
        dfs(x+dx[i],y+dy[i],c+1);
       // cout<<i<<endl;
    }

}

int main()
{
    IO
    file
    cin>>n>>m;
    LL v;
    cin>>v;

    while(v--)
    {
        LL a,b;
        cin>>a>>b;
        dfs(a-1,b-1,1);
    }
    for(int i=0 ; i<n ; i++){
        for(int j=0; j<m; j++)
        {
        if(mp[{i,j}]>mx)
        {
            mx=mp[{i,j}];
            ix=i+1;
            iy=j+1;
        }

       // cout<<mp[{i,j}]<<" ";

        }
        //cout<<endl;

    }

    cout<<ix<<" "<<iy;

    return 0;
}


/// إِنَّ مَعَ الْعُسْرِ يُسْرًا
/// لَا أَبْرَحُ حَتَّىٰ أَبْلُغَ

#include <bits/stdc++.h>
#define LL long long
#define LD long double
#define S second
#define IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define F first
#define PI acos(-1)
#define MAX 200005
#define file freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
using namespace std;
LL m,n;
LL mx=-1,ix=-1,iy=-1;
map< pair<LL,LL > ,LL>mp;
queue< pair< pair<LL,LL > ,LL > >Q;
LL dx[]={0,0,1,-1};
LL dy[]={1,-1,0,0};

bool vaild(int x, int y)
{
    if(x<0 || x>=n || y<0 || y>=m)
        return 0;
    return 1;
}

void bfs()
{

    while(!Q.empty())
    {
     LL x=Q.front().F.F;
     LL y=Q.front().F.S;
     LL c=Q.front().S;
     Q.pop();
    if( mp[{x,y}]!=0 && c>=mp[{x,y}])
        continue;
    mp[{x,y}]=c;
    if(mp[{x,y}]>mx)
        {
            mx=mp[{x,y}];
            ix=x+1;
            iy=y+1;
        }
    for(int i=0; i<4; i++)
    {
        if(vaild(x+dx[i],y+dy[i]))
            {
                Q.push({ {x+dx[i],y+dy[i] },c+1});
            }

    }

    }

}

int main()
{
    IO
    file
    cin>>n>>m;
    LL v;
    cin>>v;

    while(v--)
    {
        LL a,b;
        cin>>a>>b;
        Q.push({{a-1,b-1},0});
    }
    bfs();

    cout<<ix<<" "<<iy;

    return 0;
}


/// إِنَّ مَعَ الْعُسْرِ يُسْرًا
/// لَا أَبْرَحُ حَتَّىٰ أَبْلُغَ

#include <bits/stdc++.h>
#define LL long long
#define LD long double
#define S second
#define IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define F first
#define PI acos(-1)
#define MAX 200005
#define file freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
using namespace std;
LL m,n;
LL mx=-1,ix=-1,iy=-1;
map< pair<LL,LL > ,LL>mp;
queue< pair< pair<LL,LL > ,LL > >Q;
LL dx[]={0,0,1,-1};
LL dy[]={1,-1,0,0};

bool vaild(int x, int y)
{
    if(x<0 || x>=n || y<0 || y>=m)
        return 0;
    return 1;
}

void bfs()
{

    while(!Q.empty())
    {
     LL x=Q.front().F.F;
     LL y=Q.front().F.S;
     LL c=Q.front().S;
     Q.pop();
    if( mp[{x,y}]!=0 && c>=mp[{x,y}])
        continue;
    mp[{x,y}]=c;
    if(mp[{x,y}]>mx)
        {
            mx=mp[{x,y}];
            ix=x+1;
            iy=y+1;
        }
    for(int i=0; i<4; i++)
    {
        if(vaild(x+dx[i],y+dy[i]))
            {
                Q.push({ {x+dx[i],y+dy[i] },c+1});
            }

    }

    }

}

int main()
{
    IO
    file
    cin>>n>>m;
    LL v;
    cin>>v;

    while(v--)
    {
        LL a,b;
        cin>>a>>b;
        Q.push({{a-1,b-1},1});
    }
    bfs();

    cout<<ix<<" "<<iy;

    return 0;
}


/// إِنَّ مَعَ الْعُسْرِ يُسْرًا
/// لَا أَبْرَحُ حَتَّىٰ أَبْلُغَ

#include <bits/stdc++.h>
#define LL long long
#define LD long double
#define S second
#define IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define F first
#define PI acos(-1)
#define MAX 200005
#define file freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
using namespace std;
LL m,n;
LL mx=-1,ix=-1,iy=-1;
map< pair<LL,LL > ,LL>mp;
queue< pair< pair<LL,LL > ,LL > >Q;
LL dx[]={0,0,1,-1};
LL dy[]={1,-1,0,0};

bool vaild(int x, int y)
{
    if(x<0 || x>=n || y<0 || y>=m)
        return 0;
    return 1;
}

void bfs()
{

    while(!Q.empty())
    {
     LL x=Q.front().F.F;
     LL y=Q.front().F.S;
     LL c=Q.front().S;
     Q.pop();
    if( mp[{x,y}]!=0 && c>=mp[{x,y}])
        continue;
    mp[{x,y}]=c;
    if(mp[{x,y}]>mx)
        {
            mx=mp[{x,y}];
            ix=x+1;
            iy=y+1;
        }
    for(int i=0; i<4; i++)
    {
        if(vaild(x+dx[i],y+dy[i]))
            {
                Q.push({ {x+dx[i],y+dy[i] },c+1});
            }

    }

    }

}

int main()
{
    IO
    //file
    cin>>n>>m;
    LL v;
    cin>>v;

    while(v--)
    {
        LL a,b;
        cin>>a>>b;
        Q.push({{a-1,b-1},0});
    }
    bfs();

    cout<<ix<<" "<<iy;

    return 0;
}


/// إِنَّ مَعَ الْعُسْرِ يُسْرًا
/// لَا أَبْرَحُ حَتَّىٰ أَبْلُغَ

#include <bits/stdc++.h>
#define LL long long
#define LD long double
#define S second
#define IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define F first
#define PI acos(-1)
#define MAX 200005
#define file freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
using namespace std;
LL m,n;
LL mx=-1,ix=-1,iy=-1;
int dp[2005][2005];
queue< pair<LL,LL >   >Q;
LL dx[]={0,0,1,-1};
LL dy[]={1,-1,0,0};

bool vaild(int x, int y)
{
    if(x<0 || x>=n || y<0 || y>=m)
        return 0;
    return 1;
}

void bfs()
{
    LL c=0;

    while(!Q.empty())
    {

     LL x=Q.front().F;
     LL y=Q.front().S;
     Q.pop();

        dp[x][y]=1;
    for(int i=0; i<4; i++)
    {
        if(vaild(x+dx[i],y+dy[i]))
            {
                if( dp[x+dx[i]][y+dy[i]] ==0 )
                Q.push( {x+dx[i],y+dy[i] });
            }
    }
    ix=x+1;
    iy=y+1;

    }

}

int main()
{
    IO
   file
    cin>>n>>m;
    LL v;
    cin>>v;

    while(v--)
    {
        LL a,b;
        cin>>a>>b;
        Q.push({a-1,b-1});
    }
    bfs();

    cout<<ix<<" "<<iy;

    return 0;
}


//Wining is nothing But trying To win is Everything :)
//RTn_E
#include <bits/stdc++.h>
#define __Sync ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0) ;
#define __file freopen("input.txt", "r", stdin) ; freopen("output.txt", "w", stdout) ;
#define ll long long
#define pb push_back
#define mod 1e9 + 7
const int maxn = 1e4 + 100;

using namespace std;
pair <int , int> a[20];
int main() {
    __file;
    int n , m , k , ans1 , ans2 , i1 = 1 , j1 = 1 , ans;
    cin >> n >> m >> k;
    for (int i = 0; i < k; i++)
        cin >> a[i].first >> a[i].second , a[i].first-- , a[i].second--;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++){
            ans = abs(a[0].first - i) + abs(a[0].second - j);
            for (int u = 1; u < k; u++){
                ans1 = abs(a[u].first - i) + abs(a[u].second - j);
                ans = min(ans1 , ans);
            }
            if (ans2 < ans)
                ans2 = ans , i1 = i + 1 , j1 = j + 1;
        }
    }
    cout << i1 << " " << j1 << endl;
    return 0;
}


//Wining is nothing But trying To win is Everything :)
//RTn_E
#include <bits/stdc++.h>
#define __Sync ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0) ;
#define __file freopen("input.txt", "r", stdin) ; freopen("output.txt", "w", stdout) ;
#define ll long long
#define pb push_back
#define mod 1e9 + 7
const int maxn = 1e4 + 100;

using namespace std;
pair <int , int> a[15];
int main() {
    //__file;
    int n , m , k , ans1 , ans2 , i1 , j1;
    double ans = 0 , ans3 = 0;
    cin >> n >> m >> k;
    for (int i = 0; i < k; i++)
        cin >> a[i].first >> a[i].second , a[i].first-- , a[i].second-- ;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++){
            for (int u = 0; u < k; u++){
                ans = 0;
                if (ans < sqrt((a[u].first - i) * (a[u].first - i) + (a[u].second - j) * (a[u].second - j))){
                    ans = min(ans ,sqrt((a[u].first - i) * (a[u].first - i) + (a[u].second - j) * (a[u].second - j)));
                    ans1 = i;
                    ans2 = j;
                }
            }
            ans3 = max(ans , ans3);
            i1 = ans1 + 1;
            j1 = ans2 + 1;
        }
    }
    cout << i1 << " " << j1 << endl;
    return 0;
}


//Wining is nothing But trying To win is Everything :)
//RTn_E
#include <bits/stdc++.h>
#define __Sync ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0) ;
#define __file freopen("input.txt", "r", stdin) ; freopen("output.txt", "w", stdout) ;
#define ll long long
#define pb push_back
#define mod 1e9 + 7
const int maxn = 1e4 + 100;

using namespace std;
pair <int , int> a[20];
int main() {
    __file;
    int n , m , k , ans1 , ans2 = 0 , i1 = 1 , j1 = 1 , ans;
    cin >> n >> m >> k;
    for (int i = 0; i < k; i++)
        cin >> a[i].first >> a[i].second , a[i].first-- , a[i].second--;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++){
            ans = abs(a[0].first - i) + abs(a[0].second - j);
            for (int u = 1; u < k; u++){
                ans1 = abs(a[u].first - i) + abs(a[u].second - j);
                ans = min(ans1 , ans);
            }
            if (ans2 < ans)
                ans2 = ans , i1 = i + 1 , j1 = j + 1;
        }
    }
    cout << i1 << " " << j1 << endl;
    return 0;
}


//Wining is nothing But trying To win is Everything :)
//RTn_E
#include <bits/stdc++.h>
#define __Sync ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0) ;
#define __file freopen("input.txt", "r", stdin) ; freopen("output.txt", "w", stdout) ;
#define ll long long
#define pb push_back
#define mod 1e9 + 7
const int maxn = 1e4 + 100;

using namespace std;
pair <int , int> a[20];
int main() {
    __file;
    int n , m , k , ans1 , ans2 , i1 = 0 , j1 = 0 , ans;
    cin >> n >> m >> k;
    for (int i = 0; i < k; i++)
        cin >> a[i].first >> a[i].second , a[i].first-- , a[i].second--;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++){
            ans = abs(a[0].first - i) + abs(a[0].second - j);
            for (int u = 1; u < k; u++){
                ans1 = abs(a[u].first - i) + abs(a[u].second - j);
                ans = min(ans1 , ans);
            }
            if (ans2 < ans)
                ans2 = ans , i1 = i + 1 , j1 = j + 1;
    }
    cout << i1 << " " << j1 << endl;
    return 0;
}


//Wining is nothing But trying To win is Everything :)
//RTn_E
#include <bits/stdc++.h>
#define __Sync ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0) ;
#define __file freopen("input.txt", "r", stdin) ; freopen("output.txt", "w", stdout) ;
#define ll long long
#define pb push_back
#define mod 1e9 + 7
const int maxn = 1e4 + 100;

using namespace std;
pair <int , int> a[15];
int main() {
    __file;
    int n , m , k , ans1 , ans2 , i1 , j1;
    double ans = 0 , ans3 = 0;
    cin >> n >> m >> k;
    for (int i = 0; i < k; i++)
        cin >> a[i].first >> a[i].second , a[i].first-- , a[i].second-- ;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++){
            for (int u = 0; u < k; u++){
                ans = 0;
                if (ans < sqrt((a[u].first - i) * (a[u].first - i) + (a[u].second - j) * (a[u].second - j))){
                    ans = min(ans ,sqrt((a[u].first - i) * (a[u].first - i) + (a[u].second - j) * (a[u].second - j)));
                    ans1 = i;
                    ans2 = j;
                }
            }
            ans3 = max(ans , ans3);
            i1 = ans1 + 1;
            j1 = ans2 + 1;
        }
    }
    cout << i1 << " " << j1 << endl;
    return 0;
}


//Wining is nothing But trying To win is Everything :)
//RTn_E
#include <bits/stdc++.h>
#define __Sync ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0) ;
#define __file freopen("input.txt", "r", stdin) ; freopen("output.txt", "w", stdout) ;
#define ll long long
#define pb push_back
#define mod 1e9 + 7
const int maxn = 1e4 + 100;

using namespace std;
pair <int , int> a[15];
int main() {
    //__file;
    int n , m , k , ans1 , ans2 , i1 = 1 , j1 = 1;
    double ans = 100000 , ans3 = 0;
    cin >> n >> m >> k;
    for (int i = 0; i < k; i++)
        cin >> a[i].first >> a[i].second , a[i].first-- , a[i].second-- ;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++){
            ans = 100000;
            for (int u = 0; u < k; u++){
                if (ans > sqrt((a[u].first - i) * (a[u].first - i) + (a[u].second - j) * (a[u].second - j))){
                    ans = min(ans ,sqrt((a[u].first - i) * (a[u].first - i) + (a[u].second - j) * (a[u].second - j)));
                    ans1 = i;
                    ans2 = j;
                }
            }
            if (ans3 < ans)
                ans3 = ans , i1 = ans1 + 1 , j1 = ans2 + 1;
        }
    }
    cout << i1 << " " << j1 << endl;
    return 0;
}


import java.util.*;
import java.io.*;

public class Main{

  BufferedReader in;
  StringTokenizer str = null;
  PrintWriter out;

  private String next() throws Exception{
    while(str == null || !str.hasMoreElements())
      str = new StringTokenizer(in.readLine());
    return str.nextToken();
  }

  private int nextInt() throws Exception{
    return Integer.parseInt(next());
  }

  private long nextLong() throws Exception{
    return Long.parseLong(next());
  }

  int n, vtx = 1, root = 0;
  long []a, prefix;
  int tree[][];

  final static long oo = Long.MAX_VALUE/2;

  public void run() throws Exception{
    in = new BufferedReader(new InputStreamReader(System.in));
    out = new PrintWriter(System.out);
    n = nextInt();
    a = new long[n];
    for(int i=0;i<n;i++){
      a[i] = nextLong();
    }

    long ret = 0;
    prefix = new long[n+1];
    for(int i=1;i<=n;i++){
      prefix[i] = prefix[i-1] ^ a[i-1];
      ret = Math.max(ret, prefix[i]);
    }

    //System.out.println(Arrays.toString(prefix));

    tree = new int[4000000][2];
    for(int i=0;i<tree.length;i++){
      Arrays.fill(tree[i], -1);
    }
    add(0);

    long suffix = 0;
    for(int i=n-1;i>=0;i--){
      suffix^=a[i];
      ret = Math.max(ret, suffix);
      add(suffix);
      //System.out.println("suffix is " + suffix);
      long s = get(prefix[i]);
      //System.out.println("prefix is " + prefix[i] + "; s is " + s);
      ret = Math.max(ret, s);
    }

    out.println(ret);
    out.close();
  }

  private void add(long x){
    int v = root;

    for(int i=60;i>=0;i--){
      if ((x & (1L << i)) > 0){
        if(tree[v][1] == -1){
          tree[v][1] = vtx++;
        }
        v = tree[v][1];
      }else{
        if (tree[v][0] == -1){
          tree[v][0] = vtx++;
        }
        v = tree[v][0];
      }
    }
  }

  private long get(long x){
    long ret = 0;
    int v = root;

    for(int i=60;i>=0;i--){
      if((x & (1L << i)) > 0){
        if (tree[v][0] != -1){
          v = tree[v][0];
        }else{
          v = tree[v][1];
          ret|=1L << i;
        }
      }else{
        if (tree[v][1] != -1){
          v = tree[v][1];
          ret|=1L << i;
        }else{
          v = tree[v][0];
        }
      }
    }

    return ret ^ x;
  }

  public static void main(String args[]) throws Exception{
    new Main().run();
  }
}


import java.util.*;
import java.io.*;

public class Main{

    BufferedReader in;
    StringTokenizer str = null;

    private String next() throws Exception{
    	if (str == null || !str.hasMoreElements())
    	    str = new StringTokenizer(in.readLine());
    	return str.nextToken();
    }

    private int nextInt() throws Exception{
	return Integer.parseInt(next());
    }

    private long nextLong() throws Exception{
	return Long.parseLong(next());
    }

    int n;
    long []a;
    Bit bit[];

    final static long oo = Long.MAX_VALUE/2;

    public void run() throws Exception{
    	in = new BufferedReader(new InputStreamReader(System.in));
    	n = nextInt();
    	a = new long[n];
    	for(int i=0;i<n;i++) a[i] = nextLong();

    	bit = new Bit[66];
    	for(int i=0;i<66;i++){
    	    bit[i] = new Bit(n);
    	}

    	for(int i=0;i<n;i++){
    	    for(int j=0;j<64;j++){
    		if((a[i] & (1L << j)) > 0){
    		    bit[j].update(i+1, 1);
    		}
    	    }
    	}

    	long ret = -oo;

    	for(int i=0;i<=n;i++){
    	    long left = 0, right = 0;
    	    for(int j=0;j<64;j++){
    		int l = bit[j].sum(0, i);
    		int r = bit[j].sum(i+1, n);
    		if (l % 2 == 1) left|=1L<<j;
    		if (r % 2 == 1) right|=1L<<j;
    	    }

    	    ret = Math.max(ret, Math.max(left, right));
    	}

    	System.out.println(ret);
    }

    static class Bit{

	int bit[];
	int n;

	public Bit(int n){
	    bit = new int[n+10];
	    this.n = n;
	}

	public int sum(int l, int r){
	    int sum = sum(r);
	    if (l > 0) sum-=sum(l-1);

	    return sum;
	}

	public int sum(int x){
	    int sum = 0;
	    while(x > 0){
		sum+=bit[x];
		x-=x&-x;
	    }

	    return sum;
	}

	public void update(int x, int d){
	    while(x <= n){
		bit[x]+=d;
		x+=x&-x;
	    }
	}
    }

    public static void main(String args[]) throws Exception{
	   new Main().run();
    }
}


import java.util.*;
import java.io.*;

public class Main{

  BufferedReader in;
  StringTokenizer str = null;
  PrintWriter out;

  private String next() throws Exception{
    while(str == null || !str.hasMoreElements())
      str = new StringTokenizer(in.readLine());
    return str.nextToken();
  }

  private int nextInt() throws Exception{
    return Integer.parseInt(next());
  }

  private long nextLong() throws Exception{
    return Long.parseLong(next());
  }

  int n, vtx = 1, root = 0;
  long []a, prefix;
  int tree[][];

  final static long oo = Long.MAX_VALUE/2;

  public void run() throws Exception{
    in = new BufferedReader(new InputStreamReader(System.in));
    out = new PrintWriter(System.out);
    n = nextInt();
    a = new long[n];
    for(int i=0;i<n;i++){
      a[i] = nextLong();
    }

    long ret = 0;
    prefix = new long[n+1];
    for(int i=1;i<=n;i++){
      prefix[i] = prefix[i-1] ^ a[i-1];
      ret = Math.max(ret, prefix[i]);
    }

    //System.out.println(Arrays.toString(prefix));

    tree = new int[4 * 64][2];
    for(int i=0;i<tree.length;i++){
      Arrays.fill(tree[i], -1);
    }
    add(0);

    long suffix = 0;
    for(int i=n-1;i>=0;i--){
      suffix^=a[i];
      ret = Math.max(ret, suffix);
      add(suffix);
      //System.out.println("suffix is " + suffix);
      long s = get(prefix[i]);
      //System.out.println("prefix is " + prefix[i] + "; s is " + s);
      ret = Math.max(ret, s);
    }

    out.println(ret);
    out.close();
  }

  private void add(long x){
    int v = root;

    for(int i=60;i>=0;i--){
      if ((x & (1L << i)) > 0){
        if(tree[v][1] == -1){
          tree[v][1] = vtx++;
        }
        v = tree[v][1];
      }else{
        if (tree[v][0] == -1){
          tree[v][0] = vtx++;
        }
        v = tree[v][0];
      }
    }
  }

  private long get(long x){
    long ret = 0;
    int v = root;

    for(int i=60;i>=0;i--){
      if((x & (1L << i)) > 0){
        if (tree[v][0] != -1){
          v = tree[v][0];
        }else{
          v = tree[v][1];
          ret|=1L << i;
        }
      }else{
        if (tree[v][1] != -1){
          v = tree[v][1];
          ret|=1L << i;
        }else{
          v = tree[v][0];
        }
      }
    }

    return ret ^ x;
  }

  public static void main(String args[]) throws Exception{
    new Main().run();
  }
}


import java.util.*;
import java.io.*;

public class Main{

  BufferedReader in;
  StringTokenizer str = null;
  PrintWriter out;

  private String next() throws Exception{
    while(str == null || !str.hasMoreElements())
      str = new StringTokenizer(in.readLine());
    return str.nextToken();
  }

  private int nextInt() throws Exception{
    return Integer.parseInt(next());
  }

  private long nextLong() throws Exception{
    return Long.parseLong(next());
  }

  int n, vtx = 1, root = 0;
  long []a, prefix;
  int tree[][];

  final static long oo = Long.MAX_VALUE/2;

  public void run() throws Exception{
    in = new BufferedReader(new InputStreamReader(System.in));
    out = new PrintWriter(System.out);
    n = nextInt();
    a = new long[n];
    for(int i=0;i<n;i++){
      a[i] = nextLong();
    }

    long ret = 0;
    prefix = new long[n+1];
    for(int i=1;i<=n;i++){
      prefix[i] = prefix[i-1] ^ a[i-1];
      ret = Math.max(ret, prefix[i]);
    }

    //System.out.println(Arrays.toString(prefix));

    tree = new int[10000000][2];
    for(int i=0;i<tree.length;i++){
      Arrays.fill(tree[i], -1);
    }
    add(0);

    long suffix = 0;
    for(int i=n-1;i>=0;i--){
      suffix^=a[i];
      ret = Math.max(ret, suffix);
      add(suffix);
      //System.out.println("suffix is " + suffix);
      long s = get(prefix[i]);
      //System.out.println("prefix is " + prefix[i] + "; s is " + s);
      ret = Math.max(ret, s);
    }

    out.println(ret);
    out.close();
  }

  private void add(long x){
    int v = root;

    for(int i=60;i>=0;i--){
      if ((x & (1L << i)) > 0){
        if(tree[v][1] == -1){
          tree[v][1] = vtx++;
        }
        v = tree[v][1];
      }else{
        if (tree[v][0] == -1){
          tree[v][0] = vtx++;
        }
        v = tree[v][0];
      }
    }
  }

  private long get(long x){
    long ret = 0;
    int v = root;

    for(int i=60;i>=0;i--){
      if((x & (1L << i)) > 0){
        if (tree[v][0] != -1){
          v = tree[v][0];
        }else{
          v = tree[v][1];
          ret|=1L << i;
        }
      }else{
        if (tree[v][1] != -1){
          v = tree[v][1];
          ret|=1L << i;
        }else{
          v = tree[v][0];
        }
      }
    }

    return ret ^ x;
  }

  public static void main(String args[]) throws Exception{
    new Main().run();
  }
}


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class E {

    static StringTokenizer st;
    static BufferedReader in;
    static int[][]t;
    static int[]c, res;
    static int cnt;
    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
        int n = nextInt();
        long[]a = new long[n+1];
        for (int i = 1; i <= n; i++) {
            a[i] = nextLong();
        }
        long[]xor = new long[n+1];
        long ans = 0;
        for (int i = 1; i <= n; i++) {
            xor[i] = xor[i-1] ^ a[i];
            ans = Math.max(ans, xor[i]);
        }
        c = new int[60];
        res = new int[60];
        long tail = 0;
        t = new int[60*n+1][2];
        t[0][0] = t[0][1] = -1;
        for (int i = n-1; i >= 1; i--) {
            tail ^= a[i+1];
            ans = Math.max(ans, tail);
            add(tail);
            long s = get(xor[i]);
            ans = Math.max(ans, s);
        }
        System.out.println(ans);
        pw.close();
    }
    private static long get(long s) {
        int v = 0;
        for (int i = 59; i >= 0; i--) {
            c[i] = (int) (s % 2);
            s /= 2;
        }
        for (int i = 0; i < 60; i++) {
            if (t[v][1-c[i]] != -1) {
                v = t[v][1-c[i]];
                res[i] = 1;
            }
            else {
                v = t[v][c[i]];
                res[i] = 0;
            }
        }
        s = 0;
        for (int i = 0; i < 60; i++) {
            s = s*2+res[i];
        }
        return s;
    }
    private static void add(long s) {
        for (int i = 59; i >= 0; i--) {
            c[i] = (int) (s % 2);
            s /= 2;
        }
        int v = 0;
        for (int i = 0; i < 60; i++) {
            if (t[v][c[i]]==-1) {
                t[v][c[i]] = ++cnt;
                t[cnt][0] = t[cnt][1] = -1;
            }
            v = t[v][c[i]];
        }
    }
    private static int nextInt() throws IOException{
        return Integer.parseInt(next());
    }

    private static long nextLong() throws IOException{
        return Long.parseLong(next());
    }

    private static double nextDouble() throws IOException{
        return Double.parseDouble(next());
    }

    private static String next() throws IOException {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(in.readLine());
        }
        return st.nextToken();
    }
}


import java.util.*;
import java.io.*;
import java.math.*;
import java.awt.geom.*;

import static java.lang.Math.*;

public class Solution implements Runnable {

	static final int MAXBIT = 45;

	public void solve() throws Exception {
		int n = sc.nextInt();
		long a [] = new long [n + 2];
		long b [] = new long [n + 2];
		for (int i = 1; i <= n; i++) {
			a[i] = sc.nextLong();
		}
		long num = 0;
		for (int i = n + 1; i >= 0; i--) {
			num ^= a[i];
			b[i] = num;
		}
		num = 0;
		for (int i = 0; i <= n + 1; i++) {
			num ^= a[i];
			a[i] = num;
		}
		Arrays.sort(b);
		long c [] = new long [n + 2];
		long d [] = new long [n + 2];

		long result = 0;
		long mask = 0;
		for (int bit = MAXBIT - 1; bit >= 0; bit--) {
			mask |= (1L << bit);
			result ^= (1L << bit);
			for (int i = 0; i <= n + 1; i++) {
				c[i] = a[i] & mask;
				d[i] = b[i] & mask;
			}
			boolean good = false;
			for (int i = 0; i <= n; i++) {
				long check = c[i] ^ result;
				int l = -1;
				int r = n + 2;
				while (r - l > 1) {
					int mid = (r + l) >> 1;
					if (check <= d[mid])
						r = mid;
					else
						l = mid;
				}
				if (r != n + 2 && check == d[r]) {
					good = true;
					break;
				}
			}
			if (!good)
				result ^= (1L << bit);
		}
		out.println(result);
	}

	static Throwable uncaught;

	BufferedReader in;
	FastScanner sc;
	PrintWriter out;

	@Override
	public void run() {
		try {
			// in = new BufferedReader(new FileReader(".in"));
			// out = new PrintWriter(new FileWriter(".out"));
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
			sc = new FastScanner(in);
			solve();
		} catch (Throwable uncaught) {
			Solution.uncaught = uncaught;
		} finally {
			out.close();
		}
	}

	public static void main(String[] args) throws Throwable {
		Thread thread = new Thread(null, new Solution(), "", (1 << 26));
		thread.start();
		thread.join();
		if (Solution.uncaught != null) {
			throw Solution.uncaught;
		}
	}

}

class FastScanner {

	BufferedReader in;
	StringTokenizer st;

	public FastScanner(BufferedReader in) {
		this.in = in;
	}

	public String nextToken() throws Exception {
		while (st == null || !st.hasMoreTokens()) {
			st = new StringTokenizer(in.readLine());
		}
		return st.nextToken();
	}

	public int nextInt() throws Exception {
		return Integer.parseInt(nextToken());
	}

	public long nextLong() throws Exception {
		return Long.parseLong(nextToken());
	}

	public double nextDouble() throws Exception {
		return Double.parseDouble(nextToken());
	}

}


import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Writer;
import java.math.BigInteger;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		OutputWriter out = new OutputWriter(outputStream);
		TaskE solver = new TaskE();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskE {
    public void solve(int testNumber, InputReader in, OutputWriter out) {
		int n = in.readInt();
		long[] mas = new long[n];

		for (int i = 0; i < n; ++i)
			mas[i] = in.readLong();

		long[] prefix = new long[n];
		long[] suffix = new long[n];

		long best = 0;
		long value = 0;
		for (int i = 0; i < n; ++i) {
			value ^= mas[i];
			best = Math.max(best, value);
			prefix[i] = best;
		}

		best = 0;
		value = 0;
		for (int i = n - 1; i >= 0; --i) {
			value ^= mas[i];
			best = Math.max(best, value);
			suffix[i] = best;
		}

		best = 0;
		best = Math.max(best, suffix[0]);
		best = Math.max(best, prefix[n - 1]);

		for (int i = 0; i < n - 1; ++i) {
			value = prefix[i] ^ suffix[i + 1];
			best = Math.max(best, value);
		}

		out.printLine(best);
    }
}

class InputReader {

	private InputStream stream;
	private byte[] buf = new byte[1 << 13];
	private int curChar;
	private int numChars;

	public InputReader(InputStream stream) {
		this.stream = stream;
	}

	private int read() {
		if (numChars == -1)
			throw new InputMismatchException();
		if (curChar >= numChars) {
			curChar = 0;
			try {
				numChars = stream.read(buf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (numChars <= 0)
				return -1;
		}
		return buf[curChar++];
	}

	public int readInt() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		int res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	public long readLong() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		long res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	public static boolean isSpaceChar(int c) {
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}

	}

class OutputWriter {
	private final PrintWriter writer;

	public OutputWriter(OutputStream outputStream) {
		writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream), 1 << 13));
	}

	public OutputWriter(Writer writer) {
		this.writer = new PrintWriter(writer);
	}

	public void print(Object... objects) {
		for (int i = 0; i < objects.length; i++) {
			if (i != 0)
				writer.print(' ');
			writer.print(objects[i]);
		}
	}

	public void printLine(Object... objects) {
		print(objects);
		writer.println();
	}

	public void close() {
		writer.close();
	}

	}


import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Random;
import java.io.Writer;
import java.math.BigInteger;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		OutputWriter out = new OutputWriter(outputStream);
		TaskE solver = new TaskE();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskE {
	public void solve(int testNumber, InputReader in, OutputWriter out) {
		int n = in.readInt();
		long[] mas = new long[n];

		for (int i = 0; i < n; ++i)
			mas[i] = in.readLong();

		long[] prefix = new long[n];

		long value = 0;
		for (int i = 0; i < n; ++i) {
			value ^= mas[i];
			prefix[i] = value;
		}

		PrefixTreeCompressed tree = new PrefixTreeCompressed();

		long best = 0;
		final int MAX_LOG = 50;
		value = 0;
		for (int pos = n - 1; pos >= -1; --pos) {
			int[] array = new int[MAX_LOG];
			for (int i = MAX_LOG - 1; i >= 0; --i)
				array[MAX_LOG - 1 - i] = (int) ((value >> i) & 1);

			tree.add(array);

			long ans = 0;
			PrefixTreeCompressed.Node v = tree.root;
			long pref = 0;
			if (pos > -1) pref = prefix[pos];
			for (int i = MAX_LOG - 1; i >= 0; --i) {
				int bit = (int) ((pref >> i) & 1);
				if (v.next.contains(bit ^ 1)) {
					ans ^= (1L << i);
					v = v.next.get(bit ^ 1);
				} else {
					v = v.next.get(bit);
				}
			}

			best = Math.max(best, ans);

			if (pos > -1) value ^= mas[pos];
		}

		out.printLine(best);
	}
}

class InputReader {

	private InputStream stream;
	private byte[] buf = new byte[1 << 13];
	private int curChar;
	private int numChars;

	public InputReader(InputStream stream) {
		this.stream = stream;
	}

	private int read() {
		if (numChars == -1)
			throw new InputMismatchException();
		if (curChar >= numChars) {
			curChar = 0;
			try {
				numChars = stream.read(buf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (numChars <= 0)
				return -1;
		}
		return buf[curChar++];
	}

	public int readInt() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		int res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	public long readLong() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		long res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	public static boolean isSpaceChar(int c) {
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}

	}

class OutputWriter {
	private final PrintWriter writer;

	public OutputWriter(OutputStream outputStream) {
		writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream), 1 << 13));
	}

	public OutputWriter(Writer writer) {
		this.writer = new PrintWriter(writer);
	}

	public void print(Object... objects) {
		for (int i = 0; i < objects.length; i++) {
			if (i != 0)
				writer.print(' ');
			writer.print(objects[i]);
		}
	}

	public void printLine(Object... objects) {
		print(objects);
		writer.println();
	}

	public void close() {
		writer.close();
	}

	}

class PrefixTreeCompressed {
	public final class Node {
		public RandomizedHashMap<Integer, Node> next = new RandomizedHashMap<Integer, Node>();
		public boolean terminal = false;
	}

	public Node root = new Node();

	public void add(int... array) {
		Node current = root;
		for (int i = 0; i < array.length; ++i) {
			if (!current.next.contains(array[i]))
				current.next.put(array[i], new Node());

			current = current.next.get(array[i]);
		}
		current.terminal = true;
	}
}

class RandomizedHashMap<K, V> {
	private static final int[] shift = new int[8];

	static {
		Random random = new Random(System.nanoTime());
		for (int i = 0; i < shift.length; ++i)
			shift[i] = 1 + i * 3 + random.nextInt(10);
	}

	private Pair<K, V>[] array;
	private int size;

	public RandomizedHashMap() {
		array = (Pair<K, V>[]) new Pair[4];
	}

	private void ensureCapacity(int capacity) {
		capacity <<= 1;
		if (array.length < capacity) {
			int newCapacity = array.length;
			while (newCapacity < capacity) newCapacity <<= 1;

			Pair<K, V>[] oldArray = array;
			array = (Pair<K, V>[]) new Pair[newCapacity];

			for (int i = 0; i < oldArray.length; ++i)
				if (oldArray[i] != null) {
					--size;
					put(oldArray[i].first, oldArray[i].second);
				}
		}

		capacity <<= 2;
		if (array.length > capacity) {
			int newCapacity = array.length;
			while (newCapacity > capacity) newCapacity >>>= 1;

			Pair<K, V>[] oldArray = array;
			array = (Pair<K, V>[]) new Pair[newCapacity];

			for (int i = 0; i < oldArray.length; ++i)
				if (oldArray[i] != null) {
					--size;
					put(oldArray[i].first, oldArray[i].second);
				}
		}
	}

	private int getIndex(int hash) {
		int index = hash;

		for (int i = 0; i < shift.length; ++i)
			index ^= hash >>> shift[i];

		return index & (array.length - 1);
	}

	// API:

	public boolean contains(K key) {
		int index = getIndex(key.hashCode());

		while (true) {
			if (array[index] == null) return false;
			else if (array[index].first.equals(key)) return true;

			index = (index + 1) & (array.length - 1);
		}
	}

	public V get(K key) {
		int index = getIndex(key.hashCode());

		while (true) {
			if (array[index] == null) throw new RuntimeException();
			else if (array[index].first.equals(key)) return array[index].second;

			index = (index + 1) & (array.length - 1);
		}
	}

	public void put(K key, V value) {
		ensureCapacity(size + 1);
		int index = getIndex(key.hashCode());

		while (true) {
			if (array[index] == null) {
				array[index] = new Pair<K, V>(key, value);
				++size;
				return;
			}

			index = (index + 1) & (array.length - 1);
		}
	}

	}

class Pair<F, S> {
	public F first;
	public S second;

	public Pair(F first, S second) {
		this.first = first;
		this.second = second;
	}

	public int hashCode() {
		int hFirst = first != null ? first.hashCode() : 0;
		int hSecond = second != null ? second.hashCode() : 0;
		return 31 * hFirst + hSecond;
	}

	public boolean equals(Object o) {
		if (this == o) return true;
		if (o == null || getClass() != o.getClass()) return false;

		Pair pair = (Pair) o;

		return (first != null ? first.equals(pair.first) : pair.first == null) &&
				(second != null ? second.equals(pair.second) : pair.second == null);
	}

	public Pair<F, S> clone() {
		return new Pair<F, S>(first, second);
	}

	public String toString() {
		return "(" + first + ", " + second + ")";
	}
}


import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Writer;
import java.math.BigInteger;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		OutputWriter out = new OutputWriter(outputStream);
		TaskE solver = new TaskE();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskE {
	public void solve(int testNumber, InputReader in, OutputWriter out) {
		int n = in.readInt();
		long[] mas = new long[n];

		for (int i = 0; i < n; ++i)
			mas[i] = in.readLong();

		long[] prefix = new long[n];

		long value = 0;
		for (int i = 0; i < n; ++i) {
			value ^= mas[i];
			prefix[i] = value;
		}

		PrefixTree tree = new PrefixTree(2);

		long best = 0;
		final int MAX_LOG = 50;
		value = 0;
		for (int pos = n - 1; pos >= -1; --pos) {
			int[] array = new int[MAX_LOG];
			for (int i = MAX_LOG - 1; i >= 0; --i)
				array[MAX_LOG - 1 - i] = (int) ((value >> i) & 1);

			tree.add(array);

			long ans = 0;
			PrefixTree.Node v = tree.root;
			long pref = 0;
			if (pos > -1) pref = prefix[pos];
			for (int i = MAX_LOG - 1; i >= 0; --i) {
				int bit = (int) ((pref >> i) & 1);
				if (v.next[bit ^ 1] != null) {
					ans ^= (1L << i);
					v = v.next[bit ^ 1];
				} else {
					v = v.next[bit];
				}
			}

			best = Math.max(best, ans);

			if (pos > -1) value ^= mas[pos];
		}

		out.printLine(best);
	}
}

class InputReader {

	private InputStream stream;
	private byte[] buf = new byte[1 << 13];
	private int curChar;
	private int numChars;

	public InputReader(InputStream stream) {
		this.stream = stream;
	}

	private int read() {
		if (numChars == -1)
			throw new InputMismatchException();
		if (curChar >= numChars) {
			curChar = 0;
			try {
				numChars = stream.read(buf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (numChars <= 0)
				return -1;
		}
		return buf[curChar++];
	}

	public int readInt() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		int res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	public long readLong() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		long res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	public static boolean isSpaceChar(int c) {
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}

	}

class OutputWriter {
	private final PrintWriter writer;

	public OutputWriter(OutputStream outputStream) {
		writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream), 1 << 13));
	}

	public OutputWriter(Writer writer) {
		this.writer = new PrintWriter(writer);
	}

	public void print(Object... objects) {
		for (int i = 0; i < objects.length; i++) {
			if (i != 0)
				writer.print(' ');
			writer.print(objects[i]);
		}
	}

	public void printLine(Object... objects) {
		print(objects);
		writer.println();
	}

	public void close() {
		writer.close();
	}

	}

class PrefixTree {
	public final class Node {
		public Node[] next;
		public boolean terminal = false;

		public Node() {
			next = new Node[alphabetSize];
		}
	}

	private int alphabetSize;
	public Node root;

	public PrefixTree(int alphabetSize) {
		this.alphabetSize = alphabetSize;
		root = new Node();
	}

	public void add(int... array) {
		Node current = root;
		for (int i = 0; i < array.length; ++i) {
			if (current.next[array[i]] == null)
				current.next[array[i]] = new Node();

			current = current.next[array[i]];
		}
		current.terminal = true;
	}
}