N      = int(input())
guest  = [i for i in range(1, (N**2)+1)]
number = list(map(int, input().split()))
ans    = 0

for i in number:
	if (i-N) in guest and (i-1) in guest and (i+1) in guest and (i+N) in guest:
		ans += 1
	guest.remove(i)
    
print(ans)