// E - White Pawn
#include <bits/stdc++.h>
using namespace std;

int main(){
	int N, M; cin>>N>>M;
	int C = min(N, M), L = C*2 + 1;

	auto ixOk = [&](int y){ return 0 <= y && y < L; };

	vector<pair<int,int>> D;
	while(M--){
		int x, y; cin>>x>>y;
		y -= N - C;
		if(ixOk(y)) D.emplace_back(x, y);
	}
	sort(D.begin(), D.end());

	vector<int> Y, S(L); S[C] = 1;

	auto update = [&](){
		vector<int> A;
		for(int&y:Y)
			if((ixOk(y-1) && S[y-1]) || (ixOk(y+1) && S[y+1])) A.push_back(y);
		for(int&y:Y) S[y] = 0;
		for(int&y:A) S[y] = 1;
	};

	int px = 0;
	for(auto&[x, y]:D){
		if(px != x) update(), Y.clear(), px = x;
		Y.push_back(y);
	}
	update();
	cout<< accumulate(S.begin(), S.end(), 0) <<endl;
}

#include <bits/stdc++.h>

#define int long long
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

const int N = 2e5+5;
int bit[N], row[N], col[N];
vector<int> tt[N];

void update(int pos, int val){
	while(pos < N){
		bit[pos] += val;
		pos += pos&-pos;
	}
}

int query(int pos){
	int res = 0;
	while(pos){
		res += bit[pos];
		pos -= pos&-pos;
	}
	return res;
}

signed main(){
	fastio
	int h,w,m;
	cin >> h >> w >> m;
	fill(row,row+N,w);
	fill(col,col+N,h);
	while(m--){
		int x,y;
		cin >> x >> y;
		x--,y--;
		row[x] = min(row[x],y);
		col[y] = min(col[y],x);
		tt[y].push_back(x);
	}
	int ans = 0;
	int i;
	for(i = 0;i < h&&row[i];i++) ans += row[i];
	int ok[h];
	fill(ok,ok+h,1);
	for(;i < h;i++) ok[i] = 0, update(i,1);
	for(i = 0;i < w&&col[i];i++){
		for(int j : tt[i]){
			if(ok[j]) ok[j] = 0, update(j,1);
		}
		ans += query(col[i]-1);
	}
	cout << ans << "\n";
}

/*
	*	*	*	*
	*	*	X	*
	*	X	*	X
	*	*	*	*
*/