#include <bits/stdc++.h>
using Int = long long;  // clang-format off
using pii = std::pair<Int, Int>;
#define REP_(i, a_, b_, a, b, ...) for (Int i = (a), lim##i = (b); i < lim##i; i++)
#define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define RREP_(i, a_, b_, a, b, ...) for (Int i = Int(b) - 1, low##i = (a); i >= low##i; i--)
#define RREP(i, ...) RREP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define ALL(v) std::begin(v), std::end(v)
struct SetupIO { SetupIO() { std::cin.tie(nullptr), std::ios::sync_with_stdio(false), std::cout << std::fixed << std::setprecision(13); } } setup_io;
#ifndef dump
#define dump(...)
#endif  // clang-format on
struct in {
    template <class T> operator T() {
        T t;
        std::cin >> t;
        return t;
    }
};
void out() { std::cout << "\n"; }
template <class Head, class... Tail> void out(Head&& h, Tail&&... t) {
    std::cout << h << (sizeof...(Tail) == 0 ? "" : " "), out(std::forward<Tail>(t)...);
}
template <class T> bool chmin(T& a, const T& b) { return a > b ? a = b, true : false; }
template <class T> bool chmax(T& a, const T& b) { return a < b ? a = b, true : false; }
template <class T> using V = std::vector<T>;

/**
 *    author:  knshnb
 *    created: Sun May 23 20:22:56 JST 2021
 **/

/// @docs src/DataStructure/SegmentTree.md
template <class T, class F> struct SegmentTree {
    const F op;
    const T e;
    SegmentTree(F op_, T e_) : op(op_), e(e_) {}
    int n;
    std::vector<T> t;
    void set_by_identity(int n_) {
        n = n_;
        t.clear(), t.resize(2 * n, e);
    }
    void set_by_vector(const std::vector<T>& a) {
        n = a.size();
        t.clear(), t.resize(2 * n, e);
        for (int i = 0; i < n; i++) t[i + n] = a[i];
        build();
    }
    void build() {
        for (int i = n - 1; i; --i) t[i] = op(t[2 * i], t[2 * i + 1]);
    }
    T& operator[](int i) { return t[i + n]; }
    // [l, r)
    T query(int l, int r) const {
        assert(0 <= l && l <= r && r <= n);
        T resl = e, resr = e;
        for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
            if (l & 1) resl = op(resl, t[l++]);
            if (r & 1) resr = op(t[--r], resr);
        }
        return op(resl, resr);
    }
    // i番目をxに変更
    void update(int i, const T& x) {
        assert(0 <= i && i < n);
        t[i += n] = x;
        while (i >>= 1) t[i] = op(t[2 * i], t[2 * i + 1]);
    }
    // i番目にxを作用 (a[i] = op(a[i], x))
    void operate(int i, const T& x) {
        assert(0 <= i && i < n);
        i += n;
        t[i] = op(t[i], x);
        while (i >>= 1) t[i] = op(t[2 * i], t[2 * i + 1]);
    }
    friend std::string to_string(const SegmentTree<T, F>& seg) {
        return to_string(std::vector<T>(seg.t.begin() + seg.n, seg.t.end()));
    }
};
template <class T, class F> auto make_segment_tree(F op, T e) { return SegmentTree<T, F>(op, e); }

signed main() {
    Int n = in();
    V<Int> a(n), b(n);
    REP(i, n) a[i] = in();
    REP(i, n) b[i] = in();
    std::reverse(ALL(a));
    std::reverse(ALL(b));
    REP(i, n) a[i] -= i;
    REP(i, n) b[i] -= i;
    std::map<Int, std::set<Int>> mpb;
    V<Int> idx(n);
    REP(i, n) { mpb[b[i]].insert(i); }
    REP(i, n) {
        auto it = mpb[a[i]].begin();
        if (it == mpb[a[i]].end()) {
            out(-1);
            return 0;
        }
        idx[i] = *it;
        mpb[a[i]].erase(it);
    }
    dump(idx);
    Int ans = 0;
    auto seg = make_segment_tree<Int>([](Int x, Int y) { return x + y; }, 0);
    seg.set_by_identity(n);
    REP(i, n) {
        ans += i - seg.query(0, idx[i]);
        seg.operate(idx[i], 1);
    }
    out(ans);
}

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<cmath>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<bitset>
#include<climits>
#include<complex>
using namespace std;
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')';}
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) {os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }
void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
#define int long long
template<typename T>
void dbg_a(T *a,int l,int r){cout<<" {";for(int i = l;i<r;i++) cout<<a[i]<<", ";cout<<a[r]<<"}"<<endl;}
typedef long long ll;
template<typename T = int>
inline T read(){
    T f = 1,r = 0;
    char c = getchar();
    while(c<'0'||c>'9'){if(c == '-') f = -1; c = getchar();}
    while(c>='0'&&c<='9'){ r = (r<<1) + (r<<3) + c - '0';c = getchar();}
    return f*r;
}
typedef pair<int,int> PII;
#define fi first
#define se second
#define mst(a,b) memset(a,b,sizeof(a))
#define For(i,a,b) for(int i = a;i<=b;i++)
#define For_(i,a,b) for(int i = a;i>=b;i--)
#define _for(i,a) for(int i = 0;i<a;i++)
#define All(x) x.begin(),x.end()

//    For(i,1,n) For(j,1,m) printf("f[%lld][%lld] = %lld\n",a,b,c);

const int N = 50 + 2,M = N*2 + 10,INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;

int n,m,x;
int a[N],mx[N],dp[N][2],k[N];
signed main(){
    n = read();x = read();
    For(i,1,n) a[i] = read();
    For(i,1,n-1) mx[i] = a[i+1]/a[i];
    For_(i,n,1){
        k[i] = x/a[i];
        x %= a[i];
    }
    
    dp[1][0] = 1;
    if(k[1]) dp[1][1] = 1;
    For(i,1,n-1){
        dp[i+1][0] = dp[i][0];
        if(k[i + 1]) dp[i+1][1] = dp[i][0];
        dp[i+1][1] += dp[i][1];
        if(k[i+1] + 1 != mx[i + 1]) dp[i+1][0] += dp[i][1];
    }
    cout<<dp[n][0]<<"\n";
    return 0;
}
