#include using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) typedef long long ll; typedef pair pii; typedef vector vll; typedef vector vi; typedef vector> vvi; typedef vector> vvll; const ll inf = 1e16; const ll md = 1000000007; int main() { int n; cin>>n; vll a(n); vll b(n); rep(i,n){ cin>>a[i]; cin>>b[i]; } rep(i,n) if(a[0]&1!=a[i]&1){ puts("-1"); return 0; } ll mx=0; rep(i,n) mx=max(mx,a[i]+b[i]*4); ll ans=0; rep(i,n) ans+=(mx-(a[i]+b[i]*4))/2; cout<