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 <bits/stdc++.h>
using namespace std;
int r, c, n;
int g[3000][6000];
vector<int> a;
vector<int> sz;
vector<pair<int, int> > a_up;
vector<pair<int, int> > sz_up;
int get(int x) {
  if (a[x] == x)
    return x;
  else {
    a_up.push_back({x, a[x]});
    a[x] = get(a[x]);
    return a[x];
  }
}
void unite(int x, int y) {
  x = get(x), y = get(y);
  if (x != y) {
    if (sz[x] < sz[y]) {
      a_up.push_back({x, a[x]});
      a[x] = y;
      sz_up.push_back({y, sz[y]});
      sz[y] += sz[x];
    } else {
      a_up.push_back({y, a[y]});
      a[y] = x;
      sz_up.push_back({x, sz[x]});
      sz[x] += sz[y];
    }
  }
}
int geti(int x, int y) { return x * 2 * c + y; }
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie();
  cout.tie();
  cin >> r >> c >> n;
  a.resize(r * c * 2);
  sz.assign(r * c * 2, 1);
  iota(a.begin(), a.end(), 0);
  int res = 0;
  while (n--) {
    a_up.clear();
    sz_up.clear();
    vector<int> _a, _sz;
    if (n == 547) {
      _a = a;
      _sz = sz;
    }
    int x, y;
    cin >> x >> y;
    x--, y--;
    g[x][y] = 1;
    g[x][y + c] = 1;
    if (x > 0 && g[x - 1][y] == 1) unite(geti(x, y), geti(x - 1, y));
    if (x < r - 1 && g[x + 1][y] == 1) unite(geti(x, y), geti(x + 1, y));
    if (y > 0 && g[x][y - 1] == 1) unite(geti(x, y), geti(x, y - 1));
    if (y < c * 2 - 1 && g[x][y + 1] == 1) unite(geti(x, y), geti(x, y + 1));
    if (x > 0 && y > 0 && g[x - 1][y - 1] == 1)
      unite(geti(x, y), geti(x - 1, y - 1));
    if (x < r - 1 && y > 0 && g[x + 1][y - 1] == 1)
      unite(geti(x, y), geti(x + 1, y - 1));
    if (x < r - 1 && y < c * 2 - 1 && g[x + 1][y + 1] == 1)
      unite(geti(x, y), geti(x + 1, y + 1));
    if (x > 0 && y < c * 2 - 1 && g[x - 1][y + 1] == 1)
      unite(geti(x, y), geti(x - 1, y + 1));
    y += c;
    if (x > 0 && g[x - 1][y] == 1) unite(geti(x, y), geti(x - 1, y));
    if (x < r - 1 && g[x + 1][y] == 1) unite(geti(x, y), geti(x + 1, y));
    if (y > 0 && g[x][y - 1] == 1) unite(geti(x, y), geti(x, y - 1));
    if (y < c * 2 - 1 && g[x][y + 1] == 1) unite(geti(x, y), geti(x, y + 1));
    if (x > 0 && y > 0 && g[x - 1][y - 1] == 1)
      unite(geti(x, y), geti(x - 1, y - 1));
    if (x < r - 1 && y > 0 && g[x + 1][y - 1] == 1)
      unite(geti(x, y), geti(x + 1, y - 1));
    if (x < r - 1 && y < c * 2 - 1 && g[x + 1][y + 1] == 1)
      unite(geti(x, y), geti(x + 1, y + 1));
    if (x > 0 && y < c * 2 - 1 && g[x - 1][y + 1] == 1)
      unite(geti(x, y), geti(x - 1, y + 1));
    y -= c;
    if (get(geti(x, y)) == get(geti(x, y + c))) {
      reverse(a_up.begin(), a_up.end());
      reverse(sz_up.begin(), sz_up.end());
      for (auto i : a_up) a[i.first] = i.second;
      for (auto i : sz_up) sz[i.first] = i.second;
      if (n == 547) assert(a == _a && sz == _sz);
      g[x][y] = 0;
      g[x][y + c] = 0;
    } else {
      res++;
    }
  }
  cout << res << '\n';
  return 0;
}
