#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
inline long long int input() {
  long long int n;
  cin >> n;
  return n;
}
long long int poww(long long int a, long long int b, long long int md) {
  return (!b ? 1
             : (b & 1 ? a * poww(a * a % md, b / 2, md) % md
                      : poww(a * a % md, b / 2, md) % md));
}
const long long int MAXN = 2e5 + 10;
const long long int MAXA = 1010;
const long long int INF = 8e18;
const long long int MOD = 1e9 + 7;
const long double PI = 4 * atan((long double)1);
long long int a[MAXA][MAXA];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
  ;
  long long int n, m;
  cin >> n >> m;
  long long int q;
  cin >> q;
  for (long long int i = 0; i < MAXA; i++) {
    for (long long int j = 0; j < MAXA; j++) {
      a[i][j] = 0;
    }
  }
  long long int ind = 0;
  for (long long int i = 0; i < q; i++) {
    long long int x, y;
    cin >> x >> y;
    a[x][y] = 1;
    if ((a[x + 1][y + 1] == 1 && a[x + 1][y] == 1 && a[x][y + 1] == 1) ||
        (a[x - 1][y + 1] == 1 && a[x - 1][y] == 1 && a[x][y + 1] == 1) ||
        (a[x - 1][y - 1] == 1 && a[x - 1][y] == 1 && a[x][y - 1] == 1) ||
        (a[x + 1][y - 1] == 1 && a[x][y - 1] == 1 && a[x + 1][y] == 1)) {
      return cout << i + 1 << '\n', 0;
      ;
    }
  }
  long long int cnt = 0;
  for (long long int i = 0; i < n; i++) {
    for (long long int j = 0; j < m; j++) {
      if (a[i][j] && a[i][j + 1] && a[i + 1][j] && a[i + 1][j + 1]) cnt++;
    }
  }
  cout << (cnt == 0 ? 0 : ind) << '\n';
  return 0;
}
