#include #include using namespace std; int main(){ int ans = 0,lenmax = 0,n; bool oe; cin >> n; int a[n],b[n],length[n]; for(int i = 0;i < n;i++){ cin >> a[i] >> b[i]; length[i] = a[i] + 4 * b[i]; if(!i) oe = length[i] % 2; else if(oe != length[i] % 2){ cout << -1 << endl; return 0; } lenmax = max(lenmax,length[i]); } for(int i = 0;i < n;i++) ans += lenmax - length[i]; cout << ans / 2 << endl; }