#include <bits/stdc++.h>
using namespace std;
int s[1001][1001], n, m;
int dr[] = {0, 1, 1};
int dc[] = {1, 1, 0};
int dr2[] = {-1, -1, 0};
int dc2[] = {0, 1, 1};
int dr3[] = {0, -1, -1};
int dc3[] = {-1, -1, 0};
int dr4[] = {0, 1, 1};
int dc4[] = {-1, -1, 0};
bool check(int i, int j) {
  int c = 0;
  for (int k = 0; k < 3; k++) {
    int nr = i + dr[k];
    int nc = j + dc[k];
    if (nr < m && nc < n && nr >= 0 && nc >= 0 && s[nr][nc]) {
      c++;
    }
  }
  if (c == 3)
    return true;
  else
    return false;
}
bool check2(int i, int j) {
  int c = 0;
  for (int k = 0; k < 3; k++) {
    int nr = i + dr2[k];
    int nc = j + dc2[k];
    if (nr < m && nc < n && nr >= 0 && nc >= 0 && s[nr][nc]) {
      c++;
    }
  }
  if (c == 3)
    return true;
  else
    return false;
}
bool check3(int i, int j) {
  int c = 0;
  for (int k = 0; k < 3; k++) {
    int nr = i + dr3[k];
    int nc = j + dc3[k];
    if (nr < m && nc < n && nr >= 0 && nc >= 0 && s[nr][nc]) {
      c++;
    }
  }
  if (c == 3)
    return true;
  else
    return false;
}
bool check4(int i, int j) {
  int c = 0;
  for (int k = 0; k < 3; k++) {
    int nr = i + dr4[k];
    int nc = j + dc4[k];
    if (nr < m && nc < n && nr >= 0 && nc >= 0 && s[nr][nc]) {
      c++;
    }
  }
  if (c == 3)
    return true;
  else
    return false;
}
int main() {
  int k, r, c, sum = 0;
  cin >> m >> n >> k;
  s[n][m];
  while (k--) {
    cin >> r >> c;
    r--;
    c--;
    s[r][c] = 1;
    sum++;
    if (check(r, c) || check2(r, c) || check3(r, c) || check4(r, c)) {
      cout << sum << endl;
      return 0;
    }
  }
  cout << 0 << endl;
  return 0;
}
