#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16777216")
using namespace std;
double pi = acos((double)-1);
const int MOD = 1000000007;
const int INF = 2147483647;
const long long LLONG_INF = 9223372036854775807LL;
bool is_colored_square(bool** a, int x, int y, int n, int m) {
  if (x < 0 || x >= n - 1) return false;
  if (y < 0 || y >= m - 1) return false;
  return a[x][y] && a[x + 1][y] && a[x][y + 1] && a[x + 1][y + 1];
}
int main() {
  ios_base::sync_with_stdio(0);
  clock_t tStart = clock();
  int tests = 1;
  for (int test = 1; test <= tests; test++) {
    int n, m, k;
    cin >> n >> m >> k;
    bool** a = new bool*[n];
    for (int i = 0; i < n; i++) {
      a[i] = new bool[m];
      for (int j = 0; j < m; j++) {
        a[i][j] = false;
      }
    }
    int answer = 0;
    for (int i = 0; i < k; i++) {
      int ai, aj;
      cin >> ai >> aj;
      ai--;
      aj--;
      a[ai][aj] = true;
      if (is_colored_square(a, ai, aj, n, m) ||
          is_colored_square(a, ai - 1, aj, n, m) ||
          is_colored_square(a, ai, aj - 1, n, m) ||
          is_colored_square(a, ai - 1, aj - 1, n, m)) {
        if (answer == 0) answer = i + 1;
      }
    }
    cout << answer << endl;
  }
}
