import heapq def main(): n = int(input()) c = [list(map(int, input().split())) for _ in range(n)] heap = [] dist = {} goal = (1 << n) - 1 for s0 in range(n): state = (s0, 0, 1 << s0) dist[state] = 0 heapq.heappush(heap, (0, s0, 0, 1 << s0)) while heap: cost, last_p, B_mask, A_flips = heapq.heappop(heap) if (B_mask ^ A_flips) == goal: print(cost) return if cost > dist.get((last_p, B_mask, A_flips), float('inf')): continue current_white = B_mask ^ A_flips for q in range(n): if not (current_white & (1 << q)): new_A_flips = A_flips ^ (1 << q) if (B_mask & (1 << last_p)) == 0: new_B_mask = B_mask | (1 << last_p) else: new_B_mask = B_mask new_cost = cost + c[last_p][q] new_state = (q, new_B_mask, new_A_flips) if new_cost < dist.get(new_state, float('inf')): dist[new_state] = new_cost heapq.heappush(heap, (new_cost, q, new_B_mask, new_A_flips)) print(-1) if __name__ == "__main__": main()