#include <bits/stdc++.h>
using namespace std;
int get() {
  char c;
  while (c = getchar(), (c < '0' || c > '9') && (c != '-'))
    ;
  bool flag = (c == '-');
  if (flag) c = getchar();
  int x = 0;
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - 48;
    c = getchar();
  }
  return flag ? -x : x;
}
void output(int x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  int len = 0, data[10];
  while (x) {
    data[len++] = x % 10;
    x /= 10;
  }
  if (!len) data[len++] = 0;
  while (len--) putchar(data[len] + 48);
  putchar('\n');
}
int m, n;
bool a[1000][1000];
bool check(int x, int y) {
  if (x < 0 || y < 0 || x >= m - 1 || y >= n - 1) return 0;
  return a[x][y] && a[x][y + 1] && a[x + 1][y] && a[x + 1][y + 1];
}
int main() {
  m = get();
  n = get();
  int k = get();
  memset(a, 0, sizeof(a));
  for (int i = 0; i < k; i++) {
    int x = get() - 1, y = get() - 1;
    a[x][y] = true;
    if (check(x - 1, y - 1) || check(x - 1, y) || check(x, y - 1) ||
        check(x, y)) {
      output(i + 1);
      return 0;
    }
  }
  output(0);
  return 0;
}
