N = int(input()) x = [list(map(int, input().split())) for _ in range(N)] x = list(map(lambda x: x[0]+x[1]*4, x)) if len(set(map(lambda x: x&1, x)))==2: print(-1) exit() lim = max(x) ans = 0 for y in x: ans += (lim-y)//2 print(ans)