#include using namespace std; int main() { int i; int N; int X; int Y; int iChk; cin >> N; cin >> X; cin >> Y; iChk = Y - X; if( iChk < 0 ) { cout << - 1 << endl; return 0; } for( i = 1; i < N; i++ ) { cin >> X; cin >> Y; if( iChk != Y - X ) { cout << - 1 << endl; return 0; } } cout << iChk << endl; return 0; }