#include <bits/stdc++.h>
bool arr[1002][1002];
using namespace std;
int main() {
  int n, m, k, sum = 0;
  cin >> n >> m >> k;
  bool f = 1;
  for (int i = 1; i <= k; i++) {
    int x, y;
    cin >> x >> y;
    arr[x][y] = 1;
    if (arr[x + 1][y] && arr[x][y + 1] && arr[x + 1][y + 1] && f) {
      sum = i;
      f = 0;
    } else if (arr[x + 1][y] && arr[x][y - 1] && arr[x + 1][y - 1] && f) {
      sum = i;
      f = 0;
    } else if (arr[x - 1][y] && arr[x][y - 1] && arr[x - 1][y - 1] && f) {
      sum = i;
      f = 0;
    } else if (arr[x - 1][y] && arr[x][y + 1] && arr[x - 1][y + 1] && f) {
      sum = i;
      f = 0;
    }
  }
  cout << sum;
  return 0;
}
