#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;
}
