import sys from collections import deque def main(): N = int(sys.stdin.readline()) x = [0] * N y = [0] * N # その座標にいる UMA の集合を bit で持っておく。 uma_set = [[0] * 1100 for _ in range(1100)] for i in range(N): x[i], y[i] = map(int, sys.stdin.readline().split()) # 負になってバグるのを防ぐため +5 ずつしておく x[i] += 5 y[i] += 5 uma_set[x[i]][y[i]] = 1 << i # 設置する点の候補を列挙 dx = [2, 1, -1, -2, -2, -1, 1, 2] dy = [1, 2, 2, 1, -1, -2, -2, -1] candidates = {(x[i] + dx[j], y[i] + dy[j]) for i in range(N) for j in range(8)} # UMA のいる場所を除く candidates -= set(zip(x, y)) # dp INF = 1 << 30 dp = [INF] * (1 << N) new_dp = deque([INF] * (1 << N)) dp[0] = 0 dx1 = [-1, -1, +2, -2] dy1 = [+2, -2, -1, -1] dx2 = [+1, +1, +2, -2] dy2 = [+2, -2, +1, +1] for a, b in candidates: new_dp = dp.copy() for bits in range(1 << N): if dp[bits] == INF: continue for dir in range(4): bits_next = bits # 向いた先の UMA を bits_next に加える bits_next |= uma_set[a + dx1[dir]][b + dy1[dir]] bits_next |= uma_set[a + dx2[dir]][b + dy2[dir]] new_dp[bits_next] = min(new_dp[bits_next], dp[bits] + 1) dp, new_dp = new_dp, dp print((dp[-1] if dp[-1] != INF else -1)) if __name__ == '__main__': main()