# -*- coding:utf-8 -*- import functools if __name__ == '__main__': n = int(input()) l = [] for _ in range(n): l.append(tuple(map(int, input().split()))) l = tuple(map(lambda x: x[1] - x[0], l)) print(l[0] if functools.reduce(lambda x, y: x == y, l) >= 0 else -1)