#include using namespace std; int main() { int N, X[1000], Y[1000]; cin >> N; for(int i = 0; i < N; i++) { cin >> X[i] >> Y[i]; } int ret = max(-1, Y[0] - X[0]); for(int i = 0; i < N; i++) { if(Y[i] - X[i] != ret) ret = -1; } if(ret == 0) ret = -1; cout << ret << endl; }