#include <bits/stdc++.h>
inline void tc() {}
using namespace std;
int main() {
  tc;
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, m, k, ans = 0, flag = 0;
  cin >> n >> m >> k;
  int arr[n][m];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) arr[i][j] = 0;
  }
  for (int i = 0; i < k; i++) {
    int a, b;
    cin >> a >> b;
    int x = a - 1, y = b - 1;
    arr[x][y] = 1;
    if (x - 1 >= 0 && y - 1 >= 0 && flag == 0) {
      if (arr[x - 1][y] == 1 && arr[x - 1][y - 1] == 1 && arr[x][y - 1] == 1) {
        ans = i + 1;
        flag = 1;
      }
    }
    if (x + 1 < n && y - 1 >= 0 && flag == 0) {
      if (arr[x][y - 1] == 1 && arr[x + 1][y - 1] == 1 && arr[x + 1][y] == 1) {
        ans = i + 1;
        flag = 1;
      }
    }
    if (x - 1 >= 0 && y + 1 < m && flag == 0) {
      if (arr[x - 1][y] == 1 && arr[x - 1][y + 1] == 1 && arr[x][y + 1]) {
        ans = i + 1;
        flag = 1;
      }
    }
    if (x + 1 < n && y + 1 < m && flag == 0) {
      if (arr[x][y + 1] == 1 && arr[x + 1][y] == 1 && arr[x + 1][y + 1] == 1) {
        ans = i + 1;
        flag = 1;
      }
    }
  }
  cout << (ans) << "\n";
  return 0;
}
