#include using namespace std; int main() { long N, ret = 0; bool diff[2] = {}; cin >> N; while(N--) { long a, b; cin >> a >> b; long space = a + 4 * b; diff[space & 1] = true; ret = max(ret, space); } if(diff[0] & diff[1]) cout << -1 << endl; else cout << ret << endl; }