from sys import stdin, stdout
import heapq
import cProfile
from collections import Counter, defaultdict, deque
from functools import reduce
import math

def get_int():
    return int(stdin.readline().strip())


def get_tuple():
    return map(int, stdin.readline().split())


def get_list():
    return list(map(int, stdin.readline().split()))

def bfs(x,y,n,dp):
    queue = [(x,y)]
    while queue:
        i,j = queue.pop(0)
        #print("A",i,j)
        if dp[i][j] == 1 or i==0 or i==n-1 or j==0 or j==n-1:
            dp[x][y] = 1
            return True
        f = 0
        for i,j in [[i-1,j],[i,j-1],[i+1,j],[i,j+1]]:
            if 0<=i<n and 0<=j<n and dp[i][j]==1:
                f = 1
                queue.append((i,j))
        #print(queue)
        if f==0:
            break
    #print(x,y)
    dp[x][y] = 1
    return False


def solve():
    n = int(input())
    people = list(map(int,input().strip().split()))
    hash = dict()
    dp = []
    c = 1
    for i in range(n):
        tmp = []
        for j in range(n):
            hash[c] = [i,j]
            tmp.append(0)
            c += 1
        dp.append(tmp)
    #print(hash)
    #print(dp)
    ans = 0
    for val in people:
        value = hash[val]
        i,j = value[0],value[1]
        #print(val,i,j,dp)
        if not bfs(i,j,n,dp):
            ans += 1
        #print("a is",ans)
    print(ans)



def main():
    solve()


TestCases = False

if TestCases:
    for i in range(get_int()):
        main()
else:
    main()
