2 5 10
2 2
1 1
1 4
2 1
1 2
1 5
2 4
2 5
1 3
2 3
 2 2 2
1 1
2 2
 3 3 9
1 1
1 2
1 3
2 1
2 2
2 3
3 1
3 2
3 3
 7 5 35
5 3
3 5
1 1
2 5
6 4
7 2
5 1
3 4
6 5
7 3
4 1
2 2
4 2
2 4
4 3
3 3
6 1
1 2
4 5
1 3
2 1
5 5
7 5
7 1
6 2
1 4
1 5
3 2
4 4
5 2
2 3
6 3
7 4
5 4
3 1
 1 5 4
1 1
1 2
1 4
1 5
 1 1 1
1 1
 5 7 21
4 4
4 5
5 5
5 6
5 7
5 1
5 2
4 2
3 2
3 1
3 7
3 6
2 6
1 6
1 7
1 1
1 2
1 3
1 4
2 4
3 4
 2 1 1
1 1
 2 2 4
2 1
1 1
1 2
2 2
 3000 3000 1
2222 738
 5 7 35
1 2
2 3
5 1
5 7
4 4
5 3
3 1
2 6
4 5
2 7
4 1
2 1
2 2
1 7
5 6
3 6
4 6
1 6
1 1
3 3
3 4
4 2
2 5
5 5
3 5
2 4
1 5
1 3
4 3
5 4
1 4
3 7
4 7
3 2
5 2
 5 4 1
4 1
 3 4 12
2 3
3 2
2 2
2 1
1 2
3 1
1 4
1 3
3 3
2 4
3 4
1 1
 3 3 3
1 1
2 2
3 3

8
 1
 6
 26
 4
 0
 20
 0
 2
 1
 28
 1
 9
 3

import java.awt.Point;
import java.util.ArrayDeque;
import java.util.Queue;
import java.util.Scanner;


public class Main {

    static int[] parent, rank, min, max, adj;
    static boolean[] taken;
    static int c;
    
    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        int r = sc.nextInt();
        c = sc.nextInt();
        int n = sc.nextInt();
        
        int rc = r*c;
        parent = new int[rc];
        for(int i = 0; i < rc; i++) parent[i] = i;
        rank = new int[rc];
        min = new int[rc];
        max = new int[rc];
        adj = new int[rc];
        taken = new boolean[rc];
        
        int count = 0;
        
        Queue<Point> q = new ArrayDeque<Point>();
        
        for(int i = 0; i < n; i++)
        {
            int cr, cc;
            boolean inq = false;
            if(!q.isEmpty())
            {
                Point p = q.remove();
                cr = p.x;
                cc = p.y;
                i--;
                inq = true;
            }
            else
            {
                cr = sc.nextInt()-1;
                cc = sc.nextInt()-1;
            }
            
            int loc = cr*c + cc;
            if(taken[loc]) continue;
            taken[loc] = true;
            min[loc] = cc;
            max[loc] = cc+1;
            
            int[] dr = {-1, 1, 0, 0};
            int[] dc = {0, 0, -1, 1};
            
            Point crange = new Point(cc, cc+1);
            
            for(int j = 0; j < 4; j++)
            {
                int nr = cr + dr[j];
                int nc = (cc + dc[j])%c;
                if(nc == -1) nc = c-1;
                
                int nloc = nr*c + nc;
                if(nr >= r || nr < 0 || !taken[nloc]) continue;
                
                crange = rangeMerge(crange.x, crange.y, min[find(nloc)], max[find(nloc)]);
            }
            
            if(crange.y - crange.x == c) 
            {
                taken[loc] = false;
                continue;
            }
            
            if(!inq) count++;
            for(int j = 0; j < 4; j++)
            {
                int nr = cr + dr[j];
                int nc = (cc + dc[j])%c;
                if(nc == -1) nc = c-1;
                
                int nloc = nr*c + nc;
                if(nr >= r || nr < 0) continue;
                adj[nloc]++;
                if(adj[nloc] >= 3) 
                {
                    q.add(new Point(nr, nc));
                }
                if(!taken[nloc]) continue;
                union(nloc, loc);
            }
        }
        
        System.out.println(count);

    }
    
    public static Point rangeMerge(int min1, int max1, int min2, int max2)
    {
        if(max1 >= min1 && max2 >= min2)
        {
            return new Point(Math.min(min1, min2), Math.max(max1, max2));
        }
        else
        {
            if(max1 < min1) max1 += c;
            if(max2 < min2) max2 += c;
            
            int cmin = Math.min(min1, min2);
            int cmax = Math.max(max1, max2);
            
            if(cmax > c)
            {
                return new Point(cmin, cmax - c);
            }
            return new Point(cmin, cmax);
        }
    }
    
    public static void union(int a, int b)
    {
        int pa = find(a);
        int pb = find(b);
        if(pa == pb) return;
        
        if(rank[pa] < rank[pb]) 
        {
            parent[pa] = pb;
            Point range = rangeMerge(min[pa], max[pa], min[pb], max[pb]);
            min[pb] = range.x;
            max[pb] = range.y;
        }
        else 
        {
            parent[pb] = pa;
            Point range = rangeMerge(min[pa], max[pa], min[pb], max[pb]);
            min[pa] = range.x;
            max[pa] = range.y;
        }
        
        if(rank[pa] == rank[pb]) rank[pa]++;
        
        
    }
    
    public static int find(int x)
    {
        if(parent[x] == x) return x;
        return parent[x] = find(parent[x]);
    }

}
