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

//package cf;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

public class Pr325D {
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    PrintWriter writer = new PrintWriter(System.out);

    long[] readLongs() throws IOException {
        String[] s = reader.readLine().split(" ");
        long[] longs = new long[s.length];
        for(int i = 0; i < longs.length; i++) {
            longs[i] = Long.parseLong(s[i]);
        }
        return longs;
    }

    int[] readInts() throws IOException {
        String[] s = reader.readLine().split(" ");
        int[] ints = new int[s.length];
        for(int i = 0; i < ints.length; i++) {
            ints[i] = Integer.parseInt(s[i]);
        }
        return ints;
    }

    int[] tt;
    int tx = 0;
    int readInt() throws IOException {
        if(tt == null || tx >= tt.length) {
            tt = readInts();
            tx = 0;
        }
        return tt[tx++];
    }

    void solve() throws IOException {
        final int r = readInt() + 2;
        final int c = readInt();
        if(c == 1) {
            writer.println(0);
            writer.flush();
            return;
        }
        final boolean[][] used = new boolean[r][2 * c];
        int n = readInt();
        final int[] dr = {-1, -1, -1, 0, 1, 1, 1, 0,};
        final int[] dc = {-1, 0, 1, 1, 1, 0, -1, -1,};
        class DisjointSet {
            int[] parent = new int[2 * r * c];
            {
                for(int i = 0; i < 2 * r * c; i++) {
                    parent[i] = i;
                }
            }

            int getParent(int p) {
                return parent[p] == p ? p : (parent[p] = getParent(parent[p]));
            }

            int getParent(int r1, int c1) {
                return getParent(r1 * 2 * c + c1);
            }

            void unite(int r1, int c1, int r2, int c2) {
                if(!used[r1][c1] || !used[r2][c2]) {
                    return;
                }
                int p1 = getParent(r1, c1);
                int p2 = getParent(r2, c2);
                if(p1 != p2) {
                    parent[p1] = p2;
                }
            }

            int neighbouringSets(int[] ns, int r1, int c1) {

                int i = 0;
                for(int k = 0; k < 8; k++) {
                    int rr = r1 + dr[k], cc = (c1 + dc[k] + 2 * c) % (2 * c);
                    if(used[rr][cc]) {
                        ns[i++] = getParent(rr, cc);
                    }
                }
                return i;
            }
        }
        DisjointSet ds = new DisjointSet();
        int[] s1 = new int[8], s2 = new int[8];
        int ans = 0;
        for(int i = 0; i < n; i++) {
            int r1 = readInt();
            int c1 = readInt() - 1;
            int r2 = r1;
            int c2 = c1 + c;
            int cnt1 = ds.neighbouringSets(s1, r1, c1);
            int cnt2 = ds.neighbouringSets(s2, r2, c2);
            boolean ok = true;
            for(int j1 = 0; ok && j1 < cnt1; j1++) {
                for(int j2 = 0; ok && j2 < cnt2; j2++) {
                    ok = s1[j1] != s2[j2];
                }
            }
            if(ok) {
                ans++;
                used[r1][c1] = used[r2][c2] = true;
                for(int k = 0; k < 8; k++) {
                    ds.unite(r1, c1, r1 + dr[k], (c1 + dc[k] + 2 * c) % (2 * c));
                    ds.unite(r2, c2, r2 + dr[k], (c2 + dc[k] + 2 * c) % (2 * c));
                }
            }
        }
        writer.println(ans);
        writer.flush();
    }

    public static void main(String[] args) throws IOException {
        new Pr325D().solve();
    }
}
