#include <bits/stdc++.h>
using namespace std;
int c[1001][1001];
int main() {
  int n, m, a, b, ans = -1;
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    cin >> a >> b;
    for (int j = max(1, a - 2); j <= a; j++)
      for (int k = max(1, b - 2); k <= b; k++) {
        ++c[j][k];
        if (c[j][k] == 9) {
          for (int z = i + 1; z <= m; z++) cin >> a >> b;
          ans = i;
          break;
        }
      }
    if (ans != -1) break;
  }
  cout << ans;
}
