#include int main() { int n; scanf("%d", &n); int i; int a[1003], b[1003]; for (i = 0; i < n; i++) scanf("%d %d", &a[i], &b[i]); int max = 0; for (i = 0; i < n; i++) if (max < a[i] + 4 * b[i]) max = a[i] + 4 * b[i]; int ans = 0; for (i = 0; i < n; i++) { if ((max - a[i] - 4 * b[i]) % 2 > 0) { printf("-1\n"); return 0; } ans += max - a[i] - 4 * b[i]; } printf("%d\n", ans / 2); return 0; }