n=int(input())
a=[int(i) for i in input().split()][::-1]
tate=[[0 for i in range(int(n))] for i in range(int(n))]
yoko=[[0 for i in range(int(n))] for i in range(int(n))]
ans=0

for i in a:
    yokoindex=[int((i-1)//n),int(i-int((i-1)//n)*n)-1]
    if i%n==0:
        tateindex=[int(n-1),int(i//n-1)]
    else:
        tateindex=[int(i%n-1),int(i//n)]
    if 1 not in yoko[yokoindex[0]][:yokoindex[1]] or 1 not in yoko[yokoindex[0]][yokoindex[1]+1:] or 1 not in tate[tateindex[0]][:tateindex[1]] or 1 not in tate[tateindex[0]][tateindex[1]+1:]:
        yoko[yokoindex[0]][yokoindex[1]]+=1
        tate[tateindex[0]][tateindex[1]]+=1
    else:
        ans+=1
print(ans)