#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;
int N, M, K;
set<pii> c, b1, b;
map<pii, bool> pos;
bool postoji(pii X) {
    return (1 <= X.fi && X.fi <= N && 1 <= X.se && X.se <= M && b.find(X) != b.end());
}
bool nepostoji(pii X) {
    return (1 <= X.fi && X.fi <= N && 1 <= X.se && X.se <= M && c.find(X) == c.end());
}
void ubaci(pii X, set<pii> &b) {
    if(nepostoji(X)) b.insert(X);
    if(nepostoji({X.fi+1, X.se})) b.insert({X.fi+1, X.se});
    if(nepostoji({X.fi-1, X.se})) b.insert({X.fi-1, X.se});
    if(nepostoji({X.fi, X.se+1})) b.insert({X.fi, X.se+1});
    if(nepostoji({X.fi, X.se-1})) b.insert({X.fi, X.se-1});
}
void dfs(pii X) {
    pos[X] = true;
    if(postoji({X.fi+1, X.se}) && !pos[{X.fi+1, X.se}]) dfs({X.fi+1, X.se});
    if(postoji({X.fi-1, X.se}) && !pos[{X.fi-1, X.se}]) dfs({X.fi-1, X.se});
    if(postoji({X.fi, X.se+1}) && !pos[{X.fi, X.se+1}]) dfs({X.fi, X.se+1});
    if(postoji({X.fi, X.se-1}) && !pos[{X.fi, X.se-1}]) dfs({X.fi, X.se-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;
        c.insert({x, y});
    }
    for(auto x : c) {
        ubaci(x, b1);
    }
    for(auto x : b1) {
        ubaci(x, b);
    }
    int rez = 0;
    for(auto x : b) {
        if(!pos[x]) rez++, dfs(x);
    }
    cout << rez << endl;
    return 0;
}