#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
vector<int> a;
template <typename T>
struct SegmentTree {
  using F = function<T(T, T)>;
  int n;
  T init;
  F f = [&](T l, T r) { return (l.first < r.first) ? r : l; };
  vector<T> data;
  SegmentTree() {}
  SegmentTree(int n_, vector<T> v = vector<T>(), T init = T{0, -1})
      : init(init) {
    n = 1;
    while (n < n_) n *= 2;
    data.assign(n * 2 - 1, init);
    if (n_ == v.size()) build(v);
  }
  void build(vector<T> v) {
    for (int i = 0; i < v.size(); ++i) data[i + n - 1] = v[i];
    for (int i = n - 2; i >= 0; --i) {
      data[i] = f(data[i * 2 + 1], data[i * 2 + 2]);
    }
  }
  void update(int k, T x) {
    k += n - 1;
    data[k] = x;
    while (k > 0) {
      k = (k - 1) / 2;
      data[k] = f(data[k * 2 + 1], data[k * 2 + 2]);
    }
  }
  T query(int a, int b, int k = 0, int l = 0, int r = -1) {
    if (r < 0) r = n;
    if (b <= l || r <= a) return init;
    if (a <= l && r <= b) return data[k];
    T vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
    T vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
    return f(vl, vr);
  }
  void print() {
    for (int i = 0; i < n; ++i)
      cerr << '(' << data[i + n - 1].first << ',' << data[i + n - 1].second
           << ')' << ' ';
    cerr << endl;
  }
};
int main() {
  int n;
  cin >> n;
  a.resize(n);
  vector<int> b(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) cin >> b[i];
  vector<P> p(n);
  for (int i = 0; i < n; i++) {
    p[i] = {b[i], i};
  }
  SegmentTree<P> seg(n, p);
  int ans = 0;
  while (true) {
    int x, k;
    tie(x, k) = seg.query(0, n);
    if (x < a[k] || ans > 1000) {
      ans = -1;
      break;
    }
    if (x == a[k]) {
      break;
    }
    x -= (k - 1 >= 0) ? seg.query(k - 1, k).first : seg.query(n - 1, n).first;
    x -= (k + 1 <= n - 1) ? seg.query(k + 1, k + 2).first
                          : seg.query(0, 1).first;
    seg.update(k, {x, k});
    ans++;
  }
  cout << ans << endl;
}
