import std.algorithm; import std.array; import std.conv; import std.math; import std.stdio; import std.string; import std.range; int readint() { return readln.chomp.to!int; } int[] readints() { return readln.split.map!(to!int).array; } long calc(int[] xs) { int max = xs.maxElement; long ans = 0; foreach (x; xs) { if ((max - x) % 2 == 1) { return -1; } ans += max - x; } return ans / 2; } void main() { int n = readint(); int[] xs; for (int i = 0; i < n; i++) { auto ys = readints(); int a = ys[0], b = ys[1]; xs ~= a + 4 * b; } writeln(calc(xs)); }