#include <bits/stdc++.h>
using namespace std;
const double eps = 1.0e-11;
const double pi = acos(-1.0);
const int N = 1009;
bool mask[N][N];
int main() {
  int n, m;
  cin >> n >> m;
  int nn = -1;
  for (long long i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    mask[x][y] = 1;
    for (int dx = -1; dx <= 1; ++dx)
      for (int dy = -1; dy <= 1; ++dy) {
        if (x + dx < 2 || x + dx > n - 1 || y + dy < 2 || y + dy > n - 1)
          continue;
        bool isgood = true;
        for (int dx1 = -1; dx1 <= 1; ++dx1)
          for (int dy1 = -1; dy1 <= 1; ++dy1)
            if (mask[x + dx + dx1][y + dy + dy1] == false) isgood = false;
        if (isgood && nn == -1) nn = i + 1;
      }
  }
  cout << nn << endl;
  return 0;
}
