#include using namespace std; typedef long long ll; #define REP(i, n) for(int(i)=0;(i)<(n);++(i)) #define FOR(i, f, t) for(int(i)=(f);(i)<(t);(++i)) int main(){ do { cin.tie(0); ios_base::sync_with_stdio(false); } while(0); int N; cin >> N; ll x,y; cin >> x >> y; ll z = y - x; ll res = z; if(z < 1) res = -1; if(z > 0){ REP(i,N-1){ cin >> x >> y; if(z + x != y) res = -1; } } cout << res << endl; }