import std.stdio, std.conv, std.math, std.string, std.range, std.array, std.algorithm; void main() { immutable N = readln().strip().to!int(); int[] a; a.length = N; foreach(immutable int i; 0 .. N) { auto buf = readln().strip().split().map!(to!int)().array(); if(buf[0]%2 == 1) { writeln(-1); return; } a[i] = buf[0]/2 + buf[1]*2; } (a.reduce!max * N - a.reduce!"a+b").writeln(); }