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

#include <iostream>
#include <vector>
#define MAXR 3005
#define MAXC 6005
#define MAXN 600005

using namespace std;

int n, R, C, yMin[MAXN], yMax[MAXN], next[MAXN], a[MAXR][MAXC];
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}; 
int dy[] = {1, 0, -1, 0, 1, -1, 1, -1};

bool ok(int x, int y)
{
  return x >= 0 && x < R && y >= 0 && y < 2 * C;
}

int find(int i)
{
  return !next[i] ? i : (next[i] = find(next[i]));
}

struct data
{
  int l, r;
  vector<int> u;
  
  int ff(int x, int y)
  {
    l = y;
    r = y;
    u.clear();
    for (int i = 0; i < 8; i++)
    {
      int xx, yy;
      xx = x + dx[i];
      yy = y + dy[i];
      if (ok(xx, yy) && a[xx][yy])
      {
        int v = find(a[xx][yy]);
        l = min(l, yMin[v]);
        r = max(r, yMax[v]);
        u.push_back(v);
      }
    }
  }
};

bool check(int x, int y)
{
  if (x == 2 && y == 2)
  {
    int f = 0;
  }
  data p, q;
  p.ff(x, y);
  q.ff(x, y + C);
  for (int i = 0; i < p.u.size(); i++)
    for (int j = 0; j < q.u.size(); j++)
      if (p.u[i] == q.u[j]) 
      {
        int l, r;
        l = min(p.l, q.l);
        r = max(p.r, q.r);
        return !(l == 0 && r == 2 * C - 1);
      }
      
  return 1;  
}

int Union(int i, int j)
{
  i = find(i);
  j = find(j);
  if (i != j) 
  {
    next[i] = j;
    yMin[j] = min(yMin[i], yMin[j]);
    yMax[j] = max(yMax[i], yMax[j]);
  }
}

int join(int x, int y, int i)
{
  a[x][y] = i;
  yMin[i] = y;
  yMax[i] = y;
  for (int k = 0; k < 8; k++)
  {
    int xx, yy;
    xx = x + dx[k];
    yy = y + dy[k];
    if (ok(xx, yy) && a[xx][yy]) Union(i, a[xx][yy]);
  }
}

main()
{
  cin >> R >> C >> n;
  
  int result = 0;
  for (int i = 1; i <= n; i++)
  {
    int x, y;
    cin >> x >> y;
    x--, y--;
    if (check(x, y))
    {
      result++;
      join(x, y, i);
      join(x, y + C, i + n);
    }
  }
  
  cout << result;
  //system("pause");
}
