#include using namespace std; int main(){ int N,x,y,ans=0; cin >> N; while(cin >> x >> y){ if(y-x<1 || (ans!=0&&ans!=y-x)){ cout << -1 << endl; return 0; }else{ ans=y-x; } } cout << ans << endl; return 0; }