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