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(); a[i] = buf[0]/2 + buf[1]*2; } if(a.all!"a%2 == 1" || a.all!"a%2 == 0") { (a.reduce!max * N - a.reduce!"a+b").writeln(); } else { writeln(-1); } }