#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a[501][501], b[250001], cnt = 0;
  cin >> n;
  for (int i = 1; i < n + 1; i++) {
    for (int j = 1; j < n + 1; j++) {
      a[i][j] = 1;
    }
  }
  for (int i = 0; i < (n * n); i++) {
    cin >> b[i];
    int p, q, r, s, flag = 0;
    if (b[i] % n == 0) {
      p = b[i] / n;
      q = n;
    } else {
      p = (b[i] / n) + 1;
      q = (b[i] % n);
    }
    if (p == 1 || p == n || q == 1 || q == n) {
      a[p][q] = 0;
      continue;
    } else {
      a[p][q] = 0;
      for (int i = 1; i < p; i++) {
        if (a[i][q] == 1) {
          flag = 1;
          break;
        }
      }
      if (flag == 0) {
        continue;
      }
      flag = 0;
      for (int i = p + 1; i <= n; i++) {
        if (a[i][q] == 1) {
          flag = 1;
          break;
        }
      }
      if (flag == 0) {
        continue;
      }
      flag = 0;
      for (int i = 1; i < q; i++) {
        if (a[p][i] == 1) {
          flag = 1;
          break;
        }
      }
      if (flag == 0) {
        continue;
      }
      flag = 0;
      for (int i = q + 1; i <= n; i++) {
        if (a[p][i] == 1) {
          flag = 1;
          break;
        }
      }
      if (flag == 1) {
        cnt++;
      }
    }
  }
  cout << cnt << endl;
}
