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