#!/usr/bin/env python3 #fileencoding: utf-8 cand = -1 for i in range(int(input())): x, y = [int(i) for i in input().strip().split(" ")] if cand == -1: cand = y - x if cand <= 0: cand = -1 break continue elif cand != (y-x): cand = -1 break print(cand)