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