//#pragma GCC optimize ("O2")
//#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
//#include<atcoder/all>
//using namespace atcoder;
#include<cstdio>
#include<cstring>
#include<algorithm>


using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int CM = 1 << 17, CL = 12;
char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	if (ci - owa > 0) {
		memcpy(cn, owa, CL);
		ci -= CM;
		fread(cn + CL, 1, CM, stdin);
	}
	ll tmp = *(ll*)ci;
	int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
	tmp = tmp << dig & ma1;
	tmp = tmp * 10 + (tmp >> 8) & ma2;
	tmp = tmp * 100 + (tmp >> 16) & ma3;
	tmp = tmp * 10000 + (tmp >> 32) & ma4;
	ci += 72 - dig >> 3;
	return tmp;
}

const int bm = 200010;
int BIT[bm];
void add(int A) {
	while (A <= bm) {
		BIT[A]++;
		A += A & -A;
	}
}
int query(int A) {
	int ret = 0;
	while (A > 0) {
		ret += BIT[A];
		A -= A & -A;
	}
	return ret;
}

int Q[200001], ne[200001], he[200001];
int main() {
	//cin.tie(0);
	//ios::sync_with_stdio(false);


	int H = getint(), W = getint(), M = getint();

	int X[200001], Y[200001];
	rep1(i, H) X[i] = W + 1;
	rep1(i, W) Y[i] = H + 1;
	rep(i, M) {
		int x = getint(), y = getint();
		if (y < X[x]) X[x] = y;
		if (x < Y[y]) Y[y] = x;
	}
	ll kotae = 1;
	int k = 1;
	for (int i = 2; i <= H; i++) {
		if (X[i] == 1) break;
		kotae += X[i] - 1;
		Q[k] = i;
		ne[k] = he[X[i] - 1];
		he[X[i] - 1] = k++;
	}

	int atta = W;
	if (X[1] <= atta) atta = X[1] - 1;
	for (int i = W; i > atta; i--) {
		for (int q = he[i]; q; q = ne[q]) {
			add(Q[q]);
		}
	}
	for (int i = atta; i >= 2; i--) {
		for (int q = he[i]; q; q = ne[q]) {
			add(Q[q]);
		}
		int are = query(Y[i] - 1);
		kotae += Y[i] - 1 - are;
	}

	printf("%lld\n", kotae);

	Would you please return 0;
}
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;

#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define INF LONG_MAX/3
//#define DIV 1000000007
//#define DIV 998244353

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

ll N;
ll num;

bool done[25];
ll col[25];

vector<pair<ll, ll> >path;
vector<ll> to[25];

//void dfs1(ll cur) {
//
//	queue<ll> Q;
//	Q.push(cur);
//
//
//	while(!Q.empty()) {
//
//
//
//	}
//	done[cur] = true;
//
//	for(ll next: to[cur]) {
//		if(done[next]) continue;
//		path.push_back(make_pair(cur, next));
//		dfs1(next);
//	}
//	return;
//}

void dfs0(ll cur) {
	queue<pair<ll, ll> > Q;
	Q.push(make_pair(-1, cur));


	while(!Q.empty()) {
		ll f = Q.front().first;
		ll t = Q.front().second;
		Q.pop();

		if(done[t]) continue;
		done[t] = true;
		if(f != -1)
		path.push_back(make_pair(f, t));

		for(ll next: to[t]) {
			if(done[next]) continue;
			Q.push(make_pair(t, next));
		}
	}
	return;
}

bool check() {
	rep(p0, N) {
		for(ll p1: to[p0]) {
			if(col[p0] != -1 && col[p0] == col[p1]) return false;

		}
	}
	return true;
}

void dfs2(ll idx) {
	if(idx == path.size()) {
		if(check()) {
			num++;
		}
		return;
	}

	ll F = path[idx].first;
	ll T = path[idx].second;

	rep(i, 3) {
		if(i == col[F]) continue;
		col[T] = i;
		dfs2(idx+1);
		col[T] = -1;
	}
}


int main(){
	ll M;
	cin >> N >> M;

	rep(i, M) {
		ll a, b;
		cin >> a >> b;
		a--;b--;
		to[a].push_back(b);
		to[b].push_back(a);
	}

	ll ans = 1;
	rep(i, N) {
		if(done[i]) continue;

		path.clear();
		dfs0(i);
		//cout << "i = " << i << endl;
		//for(auto item: path) cout << item.first << " -> " << item.second << endl;

		num = 0;
		rep(i, N) col[i] = -1;
		col[i] = 0;
		dfs2(0);

		ans *= num * 3;
	}
	cout << ans << endl;
}
