#include<bits/stdc++.h>
#define PRINT(x) cerr<<#x<<'='<<x<<endl;
#define NL(x) " \n"[(x)]
#define lld long long
#define pil pair<int,lld>
#define pli pair<lld,int>
#define pll pair<lld,lld>
#define pii pair<int,int>
#define pb push_back
#define fi first
#define se second
#define mid (l+r)/2
#define endl '\n'
#define all(a) begin(a),end(a)
#define sz(a) int((a).size())
#define LINF 1000000000000000LL
#define INF 1000000000
#define EPS 1e-9
using namespace std;
#define MAXN 1100
int N, M, K;
bool pos[MAXN][MAXN];
bool postoji(pii X) {
    return (1 <= X.fi && X.fi <= N && 1 <= X.se && X.se <= M && !pos[X.fi][X.se]);
}

void dfs(int x, int y) {
    pos[x][y] = true;
    if(postoji({x+1, y})) dfs(x+1, y);
    if(postoji({x-1, y})) dfs(x-1, y);
    if(postoji({x, y+1})) dfs(x, y+1);
    if(postoji({x, y-1})) dfs(x, y-1);
}
int main() {
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);cerr.tie(0);
    cin >> N >> M >> K;
    for(int i = 1; i <= K; i++) {
        int x, y; cin >> x >> y;
        pos[x][y] = 1;
    }
    int rez = 0;
    for(int i = 1; i <= N; i++) {
        for(int j = 1; j <= M; j++) {
            if(!pos[i][j]) dfs(i, j), rez++;
        }
    }
    cout << rez << endl;
    return 0;
}