#include using namespace std; typedef long long ll; typedef pair P; const int INF = 1e9; const int mod = 1e9+7; const double EPS = 1e-10; const double PI = acos(-1.0); int main() { int n,x,y,ans; cin >> n >> x >> y; ans = y-x; if(ans <= 0) ans = -1; for(int i = 1; i < n; i++){ cin >> x >> y; if(ans != y-x) ans = -1; } cout << ans << endl; return 0; }