#!/usr/bin/env python #coding:utf8 def read(): N = input() ret = [] for i in range(N): ret.append(map(int, raw_input().split())) return ret def work(ABList): vList = [A + B * 4 for (A, B) in ABList] maxV = max(vList) ans = 0 for (A, B) in ABList: if (maxV - (A + B * 4)) % 2 != 0: print -1 return ans += (maxV - (A + B * 4)) / 2 print ans if __name__ == "__main__": work(read())