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