def chk_1st_row(p_l, N):
  if(p_l <= N):
    return True
  else:
    return False

def chk_last_row(p_l, N):
  if(N**2-N+1 <= p_l):
    return True
  else:
    return False
  
def chk_isle(p_l, N):
  if(p_l % N == 0 or p_l % N == 1):
    return True
  else:
    return False

def chk_right(p_l, p, N):
  # print(p_l, ',', N * (p_l // N + 1))
  for i in range(p_l+1, N * (p_l // N + 1) + 1):
    if(i in p):
      return True
  return False

def chk_left(p_l, p, N):
  # print(p_l, N * (p_l // N))
  for i in range(N * (p_l // N) + 1, p_l):
    if(i in p):
      return True
  return False

def chk_front(p_l, p, N):
  while(p_l > 0):
    p_l -= N
    if(p_l in p):
      return True
      break
  return False

def chk_rear(p_l, p, N):
  while(p_l < N**2):
    p_l += N
    if(p_l in p):
      return True
      break
  return False

N = int(input())
count = 0

in_theater = []
for i in range(1,N**2+1):
  in_theater.append(i)

p = list(map(int,input().split()))
# print(p)
for i in range(N**2):
  p_l = p[0]
  p.remove(p[0])
  if(chk_1st_row(p_l, N)):
    continue
  elif(chk_last_row(p_l, N)):
    continue
  elif(chk_isle(p_l, N)):
    continue
  elif(not(chk_right(p_l, p, N))):
    continue
  elif(not(chk_left(p_l, p, N))):
    continue
  elif(not(chk_front(p_l, p, N))):
    continue
  elif(not(chk_rear(p_l, p, N))):
    continue
  count += 1
  # print(p_l, count)
print(count)
  