N =int(input())
a = [0]*(N**2+1)
persons = [int(i) for i in input().split()]
for i in persons:
    a[i] = 1
ans = 0
upper = N*N - N

def check(k,a):
    if k <= N or k%N == 1 or k%N == 0 or k >= upper:
        return 1
    if a[k+1] == 0:
        a[k] = 1
        if(check(k+1,a)):
            return 1
    if a[k-N] == 0:
        a[k] = 1
        if(check(k-N,a)):
            return 1
    if a[k+N] == 0:
        a[k] = 1
        if(check(k+N,a)):
            return 1
    if a[k-1] == 0:
        a[k] = 1
        if(check(k-1,a)):
            return 1
    return 0

for i in  persons:
    if not check(i,a):
        ans += 1
    a[i] = 0
print(ans)
 