import java.util.*; class No0178{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int sp, tb, temp; int cnt = 0; ArrayList a = new ArrayList(); for(int i = 0; i < n; i++){ sp = sc.nextInt(); tb = sc.nextInt() * 4; a.add(sp + tb); } Collections.sort(a); Collections.reverse(a); for(int i = 1; i < n; i++){ temp = a.get(0) - a.get(i); if(temp % 2 != 0){ cnt = -1; break; }else{ cnt = cnt + (temp / 2); } } System.out.println(cnt); } }