import numpy as np
import math
N=int(input())
List=list(map(int, input().split()))
MAS=np.arange(1,N**2+1)
print(MAS)
MAS=MAS.reshape(N,N)
print(MAS)

i=0
ans=0
while i<N**2:
    if List[i]<=N:
        pass
    elif List[i]>=((N**2)-(N-1)):
        pass
    elif (List[i]-1)%N==0 or List[i]%N==0:
        pass
    else:
        ans+=1
    i+=1
    
if N>3:
    Maina=0
    n=1
    while n<=N-3:
        #print("A")
        Maina+=n
        n+=1
    print(ans-Maina)
    quit()
    

print(ans)
