#include inline long nextInt(void) { long temp; std::cin >> temp; return temp; } int main() { int even = 0; int odd = 0; int N; int max = -1; int ans = 0; int temp; std::vector v; std::cin >> N; for(int i = 0; i < N; ++i) { temp = nextInt() + 4 * nextInt(); v.push_back(temp); if( temp % 2 == 0 ) ++even; else ++odd; if( max < temp ) { max = temp; } } if( even != 0 && odd != 0 ) { std::cout << -1 << std::endl; return 0; } for(int i = 0; i < N; ++i) { ans += max - v[i]; } ans /= 2; std::cout << ans << std::endl; return 0; }