package me.yukicoder.lv1; import java.util.Scanner; public class No0185 { public static void main(String[] args) { try (Scanner sc = new Scanner(System.in)) { int N = sc.nextInt(); int ans = 0; for (int i = 0; i < N; i++) { int x = sc.nextInt(); int y = sc.nextInt(); ans = y - x; if (ans != y - x || ans < 0) { ans = -1; break; } } System.out.println(ans); } } }