#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <string.h>
#include <cmath>
#include <set>
#include<list>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define check(v) rep(i,v.size()) cout << v[i] << " ";\
cout << endl
#define INF 1e9
#define pii pair<int, int>
typedef long long ll;
using namespace std;

int main() {
    int w, h, n;
    cin >> w >> h >> n;
    set<pii> xlist;
    set<pii> ylist;

    rep(i, n){
        int t, s;
        cin >> t >> s;
        xlist.insert(pii(t, s));
        ylist.insert(pii(s, t));
    }

    int x, y;
    x = 0;
    y = 0;
    int ans = 0;
    while(true){
        auto xp = xlist.begin();
        while((*xp).first == x){
            ylist.erase(pii((*xp).second, x));
            xp = xlist.erase(xp);
            if(xlist.empty()){
                break;
            }
        }

        if(ylist.empty()){
            break;
        }

        auto yp = ylist.begin();
        while((*yp).first == y){
            xlist.erase(pii((*yp).second, y));
            yp = ylist.erase(yp);
            if(ylist.empty()){
                break;
            }
        }

        if(xlist.empty()){
            break;
        }else{
            ++ans;

            if((*xlist.rbegin()).first - x > (*ylist.rbegin()).first - y){
                ++y;
            }else{
                ++x;
            }
        }
    }

    cout << ans << "\n";

    return 0;
}
