# coding: utf-8 # yukicoder No.178 美しいWhitespace (1) def is_complete(space_n, tab_n): # 完璧にできるときは必要な全角スペースの数を、そうでないときは-1を返す関数 parity = [i % 2 for i in space_n] # スペースの数の偶奇リスト zspace_num = 0 if parity.count(1) == len(parity) or parity.count(0) == len(parity): # 全ての行のスペースの数の偶奇が一致しているときだけ完全に出来る width = [a + 4 * b for (a,b) in zip(space_n, tab_n)] max_w = max(width) for (a,b) in zip(space_n, tab_n): zspace_num += (max_w - (a + 4 * b)) // 2 # 必要な全角スペースの数をカウント return zspace_num else: # 偶奇が一致していないときは不可 return -1 # 入力部 N = int(input()) space_n = [] tab_n = [] for _ in range(N): a, b = map(int, input().split()) space_n.append(a) tab_n.append(b) # 出力部 print(is_complete(space_n, tab_n))