import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int cnt = 0; boolean huhu = false ; int N = Integer.parseInt(sc.next()); Long[] a = new Long[N]; Long[] b = new Long[N]; Long[] sum = new Long[N+1]; while(true){ a[cnt] = Long.parseLong(sc.next()); b[cnt] = Long.parseLong(sc.next()); cnt++; if(cnt==N)break; } sum[0] = (long)0; for( int i = 0; i < N ; i++ ){ sum[i+1] = a[i] + ( 4 * b[i] ); } Arrays.sort( sum ); Long max = sum[N]; long d = 0; for( int i = 1; i < N ; i++ ){ d += ( max - sum[i] ) / 2 ; } if( d % 2 == 1 && max % 2 == 0 ) System.out.print( -1 ); else if( max % 2 == 1 && d % 2 == 0 ) System.out.print( -1 ); else System.out.print( d ); System.out.println(); } }