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;
struct pr {
  int x, y;
  pr() {
    this->x = 0;
    this->y = 0;
  }
  pr(int x, int y) {
    this->x = x;
    this->y = y;
  }
};
template <class T>
class Stack {
 private:
  struct point {
    point *next;
    T *value;
    point() { this->value = NULL; }
    point(T x) { this->value = &x; }
  };
  point *head;
  int count;

 public:
  Stack() {
    this->head = NULL;
    this->count = 0;
  }
  int length() { return this->count; }
  void push(T x) {
    point *p = point(x);
    p->next = this->head;
    this->head = p;
    this->count++;
  }
  int pop() {
    if (head != NULL) {
      point *p = head;
      head = head->next;
      delete p;
      this->count--;
      return 1;
    } else
      return 0;
  }
  T *getHead() {
    if (this->head == NULL)
      return NULL;
    else
      return this->head->value;
  }
};
int r, c, n;
int fat[5050 * 5050 * 2];
bool d[5050][5050 * 2];
stack<pr> stk;
int sign(int x, int y) { return (x - 1) * c * 2 + y; }
void init() {
  for (int i = 1; i <= r; i++) {
    for (int j = 1; j <= 2 * c; j++) {
      int k = sign(i, j);
      fat[k] = k;
      d[i][j] = false;
    }
  }
}
int getfat(int x) {
  if (x == fat[x]) return x;
  stk.push(pr(x, fat[x]));
  return fat[x] = getfat(fat[x]);
}
void back(int a, int b) {
  a = getfat(a), b = getfat(b);
  if (a == b) return;
  stk.push(pr(a, fat[a]));
  stk.push(pr(b, fat[b]));
  fat[b] = a;
}
int direct[8][2];
bool check(int x, int y) {
  while (!stk.empty()) stk.pop();
  int temp[2][2] = {{x, y}, {x, y + c}};
  for (int i = 0; i < 2; i++) {
    for (int j = 0; j < 8; j++) {
      int a1 = temp[i][0] + direct[j][0];
      int a2 = temp[i][1] + direct[j][1];
      if (a1 < 1 || a1 > r) continue;
      if (a2 < 1)
        a2 = 2 * c;
      else if (a2 > 2 * c)
        a2 = 1;
      if (d[a1][a2] == false) continue;
      back(sign(temp[i][0], temp[i][1]), sign(a1, a2));
    }
  }
  if (getfat(sign(temp[0][0], temp[0][1])) ==
      getfat(sign(temp[1][0], temp[1][1]))) {
    while (!stk.empty()) {
      pr tp = stk.top();
      stk.pop();
      fat[tp.x] = tp.y;
    }
    return 0;
  }
  d[x][y] = d[x][y + c] = 1;
  return 1;
}
int N;
int main() {
  int dp = 0;
  for (int i = -1; i <= 1; i++)
    for (int j = -1; j <= 1; j++)
      if (!((i == 0) && (j == 0))) {
        direct[dp][0] = i;
        direct[dp][1] = j;
        dp++;
      }
  int x, y, ans = 0;
  cin >> r >> c >> N;
  init();
  while (N--) {
    cin >> x >> y;
    if (check(x, y)) ans++;
  }
  if (c <= 1)
    cout << 0 << endl;
  else
    cout << ans << endl;
  return 0;
}
