#include <bits/stdc++.h>
using namespace std;
const int N = 1010;
int n, m, k, z, x;
int arr[N][N];
int main() {
  cin >> n >> m >> k;
  for (int c = 1; c <= k; c++) {
    cin >> z >> x;
    arr[z][x] = 1;
    for (int q = z - 1; q <= z + 1; q++)
      for (int w = x - 1; w <= x + 1; w++)
        if (arr[q][w] && arr[q][w + 1] && arr[q + 1][w] && arr[q + 1][w + 1]) {
          cout << c;
          return 0;
        }
  }
  cout << 0;
  return 0;
}
