#include using namespace std; int main(){ int n; cin >> n; int rel; for(int i=0; i < n; i++){ int x,y; cin >> x >> y; if(i==0) rel = y - x; else if(rel != y - x){ cout << -1 << endl; return 0; } } if(rel > 0){ cout << rel << endl; } else{ cout << -1 << endl; } }