#include <bits/stdc++.h>
using namespace std;
int mp[1020][1020];
int main() {
  int i, j, k, n, m, x, y;
  memset(mp, 0, sizeof(mp));
  scanf("%d %d", &n, &m);
  for (k = 0; k < m; k++) {
    scanf("%d %d", &x, &y);
    for (i = x - 1; i <= x + 1; i++) {
      for (j = y - 1; j <= y + 1; j++) {
        mp[i][j]++;
        if (mp[i][j] == 9) {
          cout << k + 1 << endl;
          return 0;
        }
      }
    }
  }
  cout << "-1" << endl;
  return 0;
}
