#include long long a[100005]; long long b[100005]; long long min(long long a,long long b){ return a>b?b:a; } int main(){ int n; scanf("%d",&n); long long sumA = 0, sumB = 0; for(int i = 1; i <= n; i++){ scanf("%lld",&a[i]); sumA += a[i]; } for(int i = 1; i <= n; i++){ scanf("%lld",&b[i]); sumB += b[i]; } long long add = 2-n, diff = sumB-sumA; if(n==2){ if(diff!=0) printf("-1\n"); else{ long long gap = a[1]-b[1]; if(gap<0) gap *= -1; printf("%lld\n",gap); } } else if(diff%add || diff>0) printf("-1\n"); else{ long long time = diff/add; long long have = time*2; int ok = 1; for(int i = 1; i <= n; i++){ a[i] -= time; //printf("a[%d] = %lld\n",i,a[i]); if(a[i]>b[i]) ok = 0; else{ long long gap = b[i]-a[i]; if(gap%2 || gap>have) ok = 0; else have -= gap; } } if(ok) printf("%lld\n",time); else printf("-1\n"); } return 0; }