import std.algorithm, std.array, std.container, std.range, std.bitmanip; import std.numeric, std.math, std.bigint, std.random; import std.string, std.conv, std.stdio, std.typecons; void main() { auto n = readln.chomp.to!int; auto ai = iota(n) .map!(_ => readln.split.map!(to!int)) .map!(rd => rd[1] - rd[0]).array; if (ai.any!(a => a <= 0) || ai.length >= 2 && ai[1..$].any!(a => a != ai.front)) { writeln(-1); } else { writeln(ai.front); } }