#include "bits/stdc++.h"

using namespace std;
#define int long long
#define pb push_back
#define endl "\n"
#define x first
#define y second
#define PII pair<int,int>
#define PIII pair<int,PII>
const int MOD = 1e9 + 7;
const int N = 3e5;

bool cmp(PII p1, PII p2) {
    if (p1.first == p2.first)return p1.second > p2.second;
    return p1.first < p2.first;
}

void slu() {
    int n, k;
    cin >> n >> k;
    vector<PII > a(n);
    for (int i = 0; i < n; i++)cin >> a[i].first;
    for (int i = 0; i < n; i++)cin >> a[i].second;
    std::sort(a.begin(), a.end(), cmp);
    for (int i = 1; i < n; i++)a[i].second += a[i - 1].second;
    int l = -1, r = a[n - 1].first - a[0].first + 1;
    while (l + 1 != r) {
        int mid = (l + r) >> 1;
        bool check = false;
        for (int i = 0; i < n && (!check); i++) {
            int need = mid + a[i].first;
            int ll = i, rr = n;
            while (ll + 1 != rr) {
                int tmid = (ll + rr) >> 1;
                if (a[tmid].first > need)rr = tmid;
                else ll = tmid;
            }
            if (i == 0) {
                if (a[ll].second >= k)check = true;
            } else if (a[ll].second - a[i - 1].second >= k)check = true;
        }
        if (check)r = mid;
        else l = mid;
    }
    if (r == a[n - 1].first - a[0].first + 1)r = -1;
    cout << r << endl;
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int T;
//    cin >> T;
    T = 1;
    while (T--)slu();

}