#include <bits/stdc++.h>
using namespace std;
const long long N = 1e3 + 9;
long long n, m, k;
long long s[N][N];
pair<long long, long long> d[9] = {{-1, 0}, {-1, -1}, {0, -1}, {1, -1}, {1, 0},
                                   {1, 1},  {0, 1},   {-1, 1}, {-1, 0}};
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m >> k;
  for (long long i = 0; i < (k); i++) {
    long long x, y;
    cin >> x >> y;
    x--;
    y--;
    s[x][y] = 1;
    for (long long j = 0; j < 8; j += 2) {
      long long ok = 1;
      for (long long j2 = 0; j2 < 3; j2++)
        if (x + d[j + j2].first >= 0 && y + d[j + j2].second >= 0) {
          if (!s[x + d[j + j2].first][y + d[j + j2].second]) ok = 0;
        } else
          ok = 0;
      if (ok) {
        cout << i + 1;
        return 0;
      }
    }
  }
  cout << 0;
}
