#include using namespace std; typedef long long ll; typedef unsigned long long ull; typedef vector VI; typedef vector VVI; #define REP(i, n) for(int(i)=0;(i)<(n);++(i)) #define FOR(i, f, t) for(int(i)=(f);(i)<(t);(++i)) #define RREP(i, n) for(int(i)=(n)-1;(i)>=0;--(i)) const int MOD = int(1e9+7); int N,M,W,H; int res = 0; int l[1111]; int f[2]; int main(){ do { cin.tie(0); ios_base::sync_with_stdio(false); } while(0); cin >> N; if(N>1000)throw; int maxl = 0; REP(i,N){ int a,b; cin >> a >> b; if(a>10000000||b>10000000)throw; int l_ = a+4*b; f[l_%2] = 1; l[i] = l_; maxl = max(maxl, l_); } if(f[0] && f[1]){ cout << -1 << endl; return 0; } int res = 0; REP(i,N){ res += (maxl - l[i])/2; } cout << res << endl; return 0; }