import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); int[] X = new int[N], Y = new int[N]; for(int i = 0; i < N; i++) { X[i] = sc.nextInt(); Y[i] = sc.nextInt(); } int[] Z = new int[N]; for(int i = 0; i < N; i++) { Z[i] = Y[i] - X[i]; } int cnt = 0; for(int i = 0; i < N; i++) { if(Z[0] == Z[i] && Z[i] >= 0) { cnt++; } } if(cnt == N) { System.out.println(cnt); } else { System.out.println(-1); } } }