import java.io.PrintWriter; import java.util.*; import java.io.*; import java.util.function.*; public class Main { public static void main(String[] args) { new Main().stream(); } final FastIO io = new FastIO(); final PrintWriter out = new PrintWriter(System.out); void stream(){ solve(); out.flush(); } long f(int[] a, int[] b){ long[] sums = new long[a.length]; REP(a.length,i-> sums[i] = a[i] + b[i] * 4); long oddNum = Arrays.stream(sums).filter(i -> i % 2 == 0).count(); if(oddNum==0||oddNum==sums.length){ long max = Arrays.stream(sums).max().getAsLong(); long diffSum = Arrays.stream(sums).map(i -> max - i ).sum(); return diffSum / 2; }else{ return -1; } } void solve() { int N = io.Int(); int[] a = new int[N]; int[] b = new int[N]; REP(N, i->{ a[i] = io.Int(); b[i] = io.Int(); }); System.out.println(f(a,b)); } void FOR(int a, int b, Consumeract) { for(int i = a; i < b; ++i) act.accept(i); } void REP(int a, Consumeract) { FOR(0, a, act); } } class FastIO{ private final InputStream in = System.in; private final byte[] buffer = new byte[1<<12]; private int ptr = 0, buffLen = 0; private boolean hasNextByte () { if(ptr < buffLen) return true; ptr = 0; try{ buffLen = in.read(buffer); } catch (IOException e){ e.printStackTrace(); } return buffLen > 0; } private int readByte () { return hasNextByte()? buffer[ptr++] : -1; } private boolean isPrintableChar (int c) { return 33 <= c && c <= 126; } //ASCII private void skipUnprintable () { while (hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; } private boolean hasNext () { skipUnprintable(); return hasNextByte();} private String next () { if(!hasNext()) throw new NoSuchElementException(); StringBuilder sb = new StringBuilder(); int b = readByte(); while (isPrintableChar(b)){ sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } public String String () { return next(); } public char Char () { return next().charAt(0);} public int Int () { return Integer.parseInt(next());} public long Long () { return Long.parseLong(next());} public double Double () { return Double.parseDouble(next());} }