# coding:utf-8 N = int(input()) s1 = [] s2 = [] for i in range(N): a, b = map(int, input().split()) c = a + 4 * b s1.append(c) s2.append(c%2) if len(set(s2)) == 2: print('-1') else: count_fullwidth = 0 for j in s1: count_fullwidth += (max(s1) - j) // 2 print(count_fullwidth)