#include <bits/stdc++.h>
using namespace std;
const int MaxN = 1224;
const int dx[] = {1, 0, 0, -1, -1, 1, -1, 1, 0};
const int dy[] = {0, -1, 1, 0, 1, 1, -1, -1, 0};
int n, m;
bool mark[MaxN][MaxN];
inline bool in(int x, int y) { return (x >= 1 && x <= n && y >= 1 && y <= n); }
bool check(int x, int y) {
  for (int i = 0; i < 9; i++)
    if (!in(x + dx[i], y + dy[i]) || !mark[x + dx[i]][y + dy[i]]) return false;
  return true;
}
int main() {
  cin.sync_with_stdio(0);
  cin >> n >> m;
  for (int iter = 1; iter <= m; iter++) {
    int x, y;
    cin >> x >> y;
    mark[x][y] = true;
    bool found = false;
    for (int i = 0; i < 9; i++) {
      int newx = x + dx[i], newy = y + dy[i];
      if (in(newx, newy) && check(newx, newy)) found = true;
    }
    if (found) {
      cout << iter << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
