#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using uint = unsigned int;
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rep1(i,n) for(int i=1;i<=int(n);i++)
#define per(i,n) for(int i=int(n)-1;i>=0;i--)
#define per1(i,n) for(int i=int(n);i>0;i--)
#define all(c) c.begin(),c.end()
#define si(x) int(x.size())
#define pb emplace_back
#define fs first
#define sc second
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
template<class T,class U> void chmax(T& x, U y){if(x<y) x=y;}
template<class T,class U> void chmin(T& x, U y){if(y<x) x=y;}
template<class T> void mkuni(V<T>& v){sort(all(v));v.erase(unique(all(v)),v.end());}
template<class T> int lwb(const V<T>& v, const T& a){return lower_bound(all(v),a) - v.begin();}
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
void dmpr(ostream& os){os<<endl;}
template<class T,class... Args>
void dmpr(ostream&os,const T&t,const Args&... args){
	os<<t<<" ~ ";
	dmpr(os,args...);
}
#define shows(...) cerr << "LINE" << __LINE__ << " : ";dmpr(cerr,##__VA_ARGS__)
#define dump(x) cerr << "LINE" << __LINE__ << " : " << #x << " = {";  \
	for(auto v: x) cerr << v << ","; cerr << "}" << endl;
#else
#define show(x) void(0)
#define dump(x) void(0)
#define shows(...) void(0)
#endif

struct BIT{
	using D = int;
	int N;
	vector<D> bit;
	BIT(int n){		//nは区間幅!!!
		N=n;
		bit.assign(n+1,0);
	}
	BIT(){}
	void init(int n){
		N=n;
		bit.assign(n+1,0);
	}
	D sum(int i){		//i個の和a[0]+..a[i-1]
		D s=0;
		while(i>0){
			s+=bit[i];
			i-=(i&-i);
		}
		return s;
	}
	D val(int i){	//return a[i]	(0-ind)
		return sum(i+1)-sum(i);
	}
	void add(int i,D x){	//a[i]+=x (0-indexed)
		i++;
		while(i<=N){
			bit[i]+=x;
			i+=(i&-i);
		}
	}
};

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);		//DON'T USE scanf/printf/puts !!
	cout << fixed << setprecision(20);

	auto f = [&](int H,int W,VV<int> x2ys,VV<int> y2xs){
		V<int> res(H);
		y2xs[0].pb(H);
		rep(i,y2xs[0][0]){
			res[i] = (x2ys[i].empty() ? W : x2ys[i][0]);
		}
		return res;
	};
	int H,W,N; cin >> H >> W >> N;
	VV<int> x2ys(H),y2xs(W);
	rep(i,N){
		int x,y;cin>>x>>y;x--,y--;
		x2ys[x].pb(y);y2xs[y].pb(x);
	}
	rep(i,H) sort(all(x2ys[i]));
	rep(i,W) sort(all(y2xs[i]));

	auto a = f(H,W,x2ys,y2xs);
	auto b = f(W,H,y2xs,x2ys);
	show(a);show(b);
	VV<int> h2bs(H);
	rep(i,W){
		if(b[i]) h2bs[b[i]-1].pb(i);
	}
	ll ans = 0;

	BIT bit(W);
	per(i,H){
		for(int j: h2bs[i]) bit.add(j,1);
		ans += a[i] + bit.sum(W) - bit.sum(a[i]);
	}
	cout << ans << endl;
}
#include <bits/stdc++.h>
using namespace std;
//#include <atcoder/all>
//using namespace atcoder;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep1(i,n) for (int i = 1; i <= (n); ++i)
#define bit(n,k) ((n>>k)&1) //nのk　bit目
#define vec(T) vector<T>
#define vvec(T) vector<vector<T>>
using ll = long long;
using P = pair<int,int>;


template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll llINF = 1LL << 60;
const int iINF = 1e9;


//---20210207---------------------------------------------
struct Solver{

    struct path{
        int to,cost;
        path(int to=0, int cost=0):to(to),cost(cost){}
    };


    void solve(){
        int N,M;
        cin >> N>>M;

        vvec(path) r(N);
        vec(int) selfr(N,iINF);
        rep(i,M){
            int a,b,c;
            cin >> a >> b >> c;
            a--;b--;
            if(a==b) chmin(selfr[a],c);
            else r[a].emplace_back(b,c);
        }


        vvec(int) d(N,vec(int)(N,iINF));
        rep(st,N){
            d[st][st]=0;
            priority_queue<P,vector<P>,greater<P>> q;
            q.emplace(0,st);

            while(q.size()){
                int c0 = q.top().first;
                int now = q.top().second;
                q.pop();
                if(d[st][now]<c0) continue;
                for(path t:r[now]){
                    int c1 = c0+t.cost;
                    if( d[st][t.to] <= c1 ) continue;
                    d[st][t.to] = c1;
                    q.emplace(c1, t.to);
                }
            }
        }

        rep(st,N){
            int ans = selfr[st];
            rep(gl,N){
                if(st==gl) continue;
                chmin(ans, d[st][gl]+d[gl][st] );
            }
            if(ans==iINF) ans = -1;
            cout << ans << endl;
        }

    }
};


int main(){
    int testcasenum=1;
    //cin >> testcasenum;
    rep1(ti,testcasenum){
        Solver solver;
        solver.solve();
    }
    return 0;
}




//---20210206------------------------------------------
/*

struct Solver{

    struct path{
        int to,c;
        path(int to=0, int c=0):to(to),c(c){}
    };

    vvec(path) r = vvec(path)(2021);
    vec(int) used = vec(int)(2021);

    int res;
    int start;
    void dfs(int now, int c){
        for(auto t:r[now]){
            if(used[t.to]) continue;
            if(t.to==start){
                chmin(res,c+t.c);
                continue;
            }        
            used[t.to]=1;
            dfs(t.to, c+t.c);
        }
        used[now]=0;
        return;
    }



    void solve(){
        int N,M;
        cin >> N>>M;
        rep(i,M){
            int a,b,c;
            cin >> a >> b >> c;
            r[a].emplace_back(b,c);
        }

        rep1(st,N){
            rep(i,2021) used[i]=0;
            res = iINF;
            start = st;
            dfs(st,0);
            if(res==iINF) cout << -1 << endl;
            else cout << res << endl;
        }
    }


};


int main(){
    int testcasenum=1;
    //cin >> testcasenum;
    rep1(ti,testcasenum){
        Solver solver;
        solver.solve();
    }
    return 0;
}
*/