#include #include #include typedef long long ll; int main(void) { std::cin.tie(0); std::ios::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(8); int n; std::cin >> n; ll w_max = 0, w_sum = 0; for (int i = 0; i < n; ++i) { ll a, b; std::cin >> a >> b; ll w_now = a + 4*b; if (i != 0 && w_now%2 != w_max%2) {std::cout << -1 << std::endl; return 0;} w_max = std::max(w_max, w_now); w_sum += w_now; } ll w_diff = w_max * n - w_sum; std::cout << w_diff/2 << std::endl; return 0; }