import sys
sys.stdin = open('plants.in', 'r')
rints = lambda: [int(x) for x in sys.stdin.readline().split()]
n, a, b, ans = int(input()), rints(), rints(), 0
for i in range(1, n):
a[i] += ans * b[i]
if b[i - 1] >= b[i]:
if a[i - 1] > a[i]:
ans = -1
break
else:
be, en, cur = 0, 10 ** 9, float('inf')
while be <= en:
md = (be + en) >> 1
if a[i - 1] + md * b[i - 1] <= a[i] + md * b[i]:
en, cur = md - 1, md
else:
be = md + 1
ans = max(ans, cur)
print(ans)
aW1wb3J0IHN5cwoKc3lzLnN0ZGluID0gb3BlbigncGxhbnRzLmluJywgJ3InKQpyaW50cyA9IGxhbWJkYTogW2ludCh4KSBmb3IgeCBpbiBzeXMuc3RkaW4ucmVhZGxpbmUoKS5zcGxpdCgpXQpuLCBhLCBiLCBhbnMgPSBpbnQoaW5wdXQoKSksIHJpbnRzKCksIHJpbnRzKCksIDAKCmZvciBpIGluIHJhbmdlKDEsIG4pOgogICAgYVtpXSArPSBhbnMgKiBiW2ldCiAgICBpZiBiW2kgLSAxXSA+PSBiW2ldOgogICAgICAgIGlmIGFbaSAtIDFdID4gYVtpXToKICAgICAgICAgICAgYW5zID0gLTEKICAgICAgICAgICAgYnJlYWsKICAgIGVsc2U6CiAgICAgICAgYmUsIGVuLCBjdXIgPSAwLCAxMCAqKiA5LCBmbG9hdCgnaW5mJykKICAgICAgICB3aGlsZSBiZSA8PSBlbjoKICAgICAgICAgICAgbWQgPSAoYmUgKyBlbikgPj4gMQogICAgICAgICAgICBpZiBhW2kgLSAxXSArIG1kICogYltpIC0gMV0gPD0gYVtpXSArIG1kICogYltpXToKICAgICAgICAgICAgICAgIGVuLCBjdXIgPSBtZCAtIDEsIG1kCiAgICAgICAgICAgIGVsc2U6CiAgICAgICAgICAgICAgICBiZSA9IG1kICsgMQogICAgICAgIGFucyA9IG1heChhbnMsIGN1cikKcHJpbnQoYW5zKQo=