#include <bits/stdc++.h>
using namespace std;


vector<vector<int> > dirs = { { 0, -1 },
                              { -1, 0 },
                              { 0, 1 },
                              { 1, 0 } };


void dfs(vector<vector<int> >& grid, int x0, int y0,
         int i, int j, vector<pair<int, int> >& v)
{
    int rows = grid.size(), cols = grid[0].size();

    if (i < 0 || i >= rows || i < 0
        || j >= cols || grid[i][j] <= 0){
        return;
    }


    grid[i][j] *= -1;

    v.push_back({ i - x0, j - y0 });


    for (auto dir : dirs) {
        dfs(grid, x0, y0, i + dir[0], j + dir[1], v);
    }
}


int countDistinctIslands(vector<vector<int> >& grid)
{
    int rows = grid.size();
    if (rows == 0){
        return 0;
    }
    int cols = grid[0].size();
    if (cols == 0){
        return 0;
    }
    set<vector<pair<int, int> > > coordinates;

    for (int i = 0; i < rows; ++i) {
        for (int j = 0; j < cols; ++j) {


            if (grid[i][j] != 1){
                continue;
            }

            vector<pair<int, int> > v;
            dfs(grid, i, j, i, j, v);


            coordinates.insert(v);
        }
    }

    return coordinates.size();
}

int main()
{
    int n,m,k;
    cin>>n>>m>>k;

    vector<vector<int> > grid(n,vector<int> (m,1));
    for(int i=0;i<k;i++){
        int x,y;
        cin>>x>>y;
        grid[x-1][y-1]=0;
    }

    cout <<  countDistinctIslands(grid) <<endl;

    return 0;
}









/*
#include <bits/stdc++.h>

using namespace std;

struct segment{int x1,y1,x2,y2};

typedef pair<int,int> pii;
int brCvorova=0;

vector<vector<int> > graphs;
map<segment,int> cvor;






int main()
{
    int n,h,w;
    cin >>h>>w>> n;

    set<int> ykord;
    map<int,set<int> > poxkord;

    for(int i=0;i<n;i++){
        int x,y;
        cin>>y>>x;
        ykord.insert(y);
        poxkord[y].insert(x);
    }
    int ssize=ykord.size();
    vector<pii> pretRed(200007);
    vector<pii> trenRed(200007);
    int prety=0;
    pretRed[0]=make_pair(-1,-1);
    for(int i= 0;i<ssize;i++){
        int y=*ykord.begin();
        if(y-prety>1){
            if(pretRed[0].first!=-1){
                int i=-1;
                brCvorova++;
                do{
                    i++
                    int x1=pretRed[i].first,x2=pretRed[i].second;
                    cvor[]
                }while(pretRed[i].second!=w)
            }

        }
    }
    cout << "Hello world!" << endl;
    return 0;
}*/