#include using namespace std; int main(){ int n; cin >> n; int x,y; cin >> x >> y; int check = y - x; while(cin >> x >> y){ if(check != y - x) check = -1; break; } cout << (check < 0 ? -1 : check) << endl; return 0; }