#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#include <complex>
#define rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define all(x) (x).begin(),(x).end()
#define inf 1e18

using namespace std;

typedef long long llint;
typedef long long ll;
typedef pair<llint, llint> P;

struct BIT{
	int size;
	vector<llint> bit;
	BIT(){size = 0;}
	BIT(int s){
		size = s;
		bit.resize(size+1);
		init();
	}
	void init(){
		for(int i = 1; i <= size; i++) bit[i] = 0;
	}
	llint query(int i){
		llint ret = 0;
		while(i > 0){
			ret += bit[i];
			i -= i&(-i);
		}
		return ret;
	}
	void add(int i, llint x){
		while(i <= size){
			bit[i] += x;
			i += i&(-i);
		}
	}
};

ll h, w, m;
ll x[200005], y[200005];
vector<ll> xvec[200005], yvec[200005];
BIT bit(200005);
bool used[200005];

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> h >> w >> m;
	rep(i, 1, m){
		cin >> y[i] >> x[i];
		xvec[x[i]].push_back(y[i]);
		yvec[y[i]].push_back(x[i]);
	}
	rep(i, 1, 200000){
		sort(all(xvec[i])), sort(all(yvec[i]));
		xvec[i].push_back(h+1);
		yvec[i].push_back(w+1);
	}
	
	ll H = xvec[1].front()-1, W = yvec[1].front()-1;
	//cout << H << " " << W << endl;
	
	ll ans = 0;
	rep(i, 1, W) ans += (int)xvec[i].front()-1;
	rep(i, 1, H) ans += (int)yvec[i].front()-1;
	
	//cout << ans << endl;
	
	rep(i, 1, H){
		ll r = min(W, yvec[i].front()-1);
		ans -= r - bit.query(r);
		for(auto x : yvec[i]) if(!used[x]) used[x] = true, bit.add(x, 1);
	}
	cout << ans << endl;
	
	return 0;
}
#include <bits/stdc++.h>
using namespace std;

#define ll long long

const int MAXN=2e5+10;

int minu[MAXN],minl[MAXN];

int t[MAXN];

int get(int p){
	int res=0;
	for(;p;p=(p&(p-1)))
		res+=t[p];
	return res;
}

void add(int p,int n){
	for(;p<=n;p=(p|(p-1))+1)
		t[p]++;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int h,w,m;
	cin>>h>>w>>m;
	for(int i=1;i<=w;i++)
		minu[i]=h+1;
	for(int i=1;i<=h;i++)
		minl[i]=w+1;
	for(int i=1;i<=m;i++){
		int x,y;
		cin>>x>>y;
		minu[y]=min(minu[y],x);
		minl[x]=min(minl[x],y);
	}
	vector<pair<int,int>> adds;
	ll result=0;
	for(int i=1;i<=w;i++){
		if(minu[i]==1)
			break;
		result+=minu[i]-1;
		adds.push_back(make_pair(minu[i]-1,i));
	}
	sort(begin(adds),end(adds));
	int maxh=0;
	for(int i=1;i<=h;i++){
		if(minl[i]>1)
			maxh=i;
		else
			break;
	}
	for(int i=maxh;i>=1;i--){
		while(adds.size()>0&&adds.back().first>=i){
			add(adds.back().second,w);
			adds.pop_back();
		}
		result+=minl[i]-1;
		result-=get(minl[i]-1);
	}
	cout<<result<<'\n';
}
