#include <bits/stdc++.h>
using namespace std;
int arr[1005][1005];
long long int x[100010], y[100010];
int main() {
  int n, m, k, a, b;
  cin >> n >> m >> k;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      arr[i][j] = 0;
    }
  }
  int flag = 0, count = 0, temp = 1;
  for (int i = 1; i <= k; i++) {
    cin >> x[i] >> y[i];
  }
  for (int i = 1; i <= k; i++) {
    a = x[i];
    b = y[i];
    count++;
    arr[a][b] = 1;
    if (flag == 0 && a - 1 > 0 && a - 1 <= n && b - 1 > 0 && b - 1 <= m) {
      if (arr[a - 1][b - 1] == 1 && arr[a - 1][b] == 1 && arr[a][b - 1] == 1) {
        temp = count;
        flag = 1;
        break;
      }
    }
    if (flag == 0 && a - 1 > 0 && a - 1 <= n && b + 1 > 0 && b + 1 <= m) {
      if (arr[a - 1][b + 1] == 1 && arr[a - 1][b] == 1 && arr[a][b + 1] == 1) {
        temp = count;
        flag = 1;
        break;
      }
    }
    if (flag == 0 && a + 1 > 0 && a + 1 <= n && b - 1 > 0 && b - 1 <= m) {
      if (arr[a][b - 1] == 1 && arr[a + 1][b - 1] == 1 && arr[a + 1][b] == 1) {
        temp = count;
        flag = 1;
        break;
      }
    }
    if (flag == 0 && a + 1 > 0 && a + 1 <= n && b + 1 > 0 && b + 1 <= m) {
      if (arr[a][b + 1] == 1 && arr[a + 1][b] == 1 && arr[a + 1][b + 1] == 1) {
        temp = count;
        flag = 1;
        break;
      }
    }
  }
  if (flag == 0)
    cout << "0" << endl;
  else if (flag == 1)
    cout << temp << endl;
  return 0;
}
