# -*- 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)) e = functools.reduce(lambda x, y: x == y, l) print(l[0] if e and l[0] > 0 else -1)