/* LittleFall : Hello! */
#include <bits/stdc++.h>
using namespace std; using ll = long long; inline ll read();
const ll M = 200016, MOD = 1000000007;

ll cal(ll n)
{
	return n*(n+1)/2;
}
struct Star{
	ll x,y;
}star[M];
bool cmp(const Star &a, const Star &b)
{
	if(a.y==b.y)
		return a.x<b.x;
	return a.y>b.y;
}
int main(void)
{
	#ifdef _LITTLEFALL_
	freopen("in.txt","r",stdin);
    #endif

// f(总横坐标数) - f(不必须包含的横坐标数)
	ll n = read();
	for(int i=1; i<=n; ++i)
	{
		star[i].x = read();
		star[i].y = read();
	}
	sort(star+1, star+n+1, cmp);

	ll ans = 0;
	set<ll> cols;
	set<ll> tmp;
	for(int i=1; i<=n; ++i)
	{
		tmp.insert(star[i].x);
		if(star[i].y != star[i+1].y)
		{
			for(ll c:tmp)
				cols.insert(c);
			ll all = cols.size(), vasili = cols.size()-tmp.size();
			ans += cal(all)-cal(vasili);
			tmp.clear();
		}
	}
	cout << ans << endl;

    return 0;
}

inline ll read(){
    ll x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9') {if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}


/* LittleFall : Hello! */
#include <bits/stdc++.h>
using namespace std; using ll = long long; inline ll read();
const ll M = 200016, MOD = 1000000007;

ll cal(ll n)
{
	return n*(n+1)/2;
}
struct Star{
	ll x,y;
}star[M];
bool cmp(const Star &a, const Star &b)
{
	if(a.y==b.y)
		return a.x<b.x;
	return a.y>b.y;
}
int main(void)
{
	#ifdef _LITTLEFALL_
	freopen("in.txt","r",stdin);
    #endif

// f(总横坐标数) - f(不必须包含的横坐标数)
	ll n = read();
	for(int i=1; i<=n; ++i)
	{
		star[i].x = read();
		star[i].y = read();
	}
	sort(star+1, star+n+1, cmp);

	ll ans = 0;
	set<ll> cols;
	set<ll> tmp;
	for(int i=1; i<=n; ++i)
	{
		tmp.insert(star[i].x);
		if(star[i].y != star[i+1].y)
		{
			for(ll c:tmp)
				cols.insert(c);
			ll all = cols.size(), vasili = cols.size()-tmp.size();
			ans += cal(all)-vasili;
			//cout << ans << endl;
			tmp.clear();
		}
	}
	cout << ans << endl;

    return 0;
}

inline ll read(){
    ll x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9') {if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}


#include<bits/stdc++.h>
#define int 			long long
using namespace std;

typedef pair<int, int> ii;

const int N = 2e5 + 4;
int n;
ii a[N];

vector<int> X, Y;

void compress() {
	for (int i = 1; i <= n; ++i) {
		X.push_back(a[i].first);
		Y.push_back(a[i].second);
	}

	sort(X.begin(), X.end());
	X.resize(unique(X.begin(), X.end()) - X.begin());
	sort(Y.begin(), Y.end());
	Y.resize(unique(Y.begin(), Y.end()) - Y.begin());

	for (int i = 1; i <= n; ++i) {
		a[i].first = lower_bound(X.begin(), X.end(), a[i].first) - X.begin() + 1;
		a[i].second = lower_bound(Y.begin(), Y.end(), a[i].second) - Y.begin() + 1;
	}
}

vector<int> V[N];
bool mark[N];

void sol() {
	compress();

	sort(a+1, a+n+1, [] (ii u, ii v) {
		return u.second < v.second || ( u.second == v.second && u.first < v.first );
	});

	for (int i = 1; i <= n; ++i) V[ a[i].second ].push_back( a[i].first );

	int num = 0, res = 0;
	for (int y = 1; y <= (int) Y.size(); ++y) {
		for (int x : V[y]) {
				// cerr << "?? " << x << '\n';
			num += (1 - mark[x]);
			mark[x] = true;
		}
		res += (int) V[y].size() + num * (num-1) / 2;
	}
	cout << res << '\n';
}

main() {
	if (fopen("input.txt", "r")) {
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	}

	cin >> n;
	for (int i = 1; i <= n; ++i) cin >> a[i].first >> a[i].second;

	sol();

	return 0;
}


#include<bits/stdc++.h>
#define int 			long long
using namespace std;

typedef pair<int, int> ii;

const int N = 2e5 + 4;
int n;
ii a[N];

vector<int> X, Y;

void compress() {
	for (int i = 1; i <= n; ++i) {
		X.push_back(a[i].first);
		Y.push_back(a[i].second);
	}

	sort(X.begin(), X.end());
	X.resize(unique(X.begin(), X.end()) - X.begin());
	sort(Y.begin(), Y.end());
	Y.resize(unique(Y.begin(), Y.end()) - Y.begin());

	for (int i = 1; i <= n; ++i) {
		a[i].first = lower_bound(X.begin(), X.end(), a[i].first) - X.begin() + 1;
		a[i].second = lower_bound(Y.begin(), Y.end(), a[i].second) - Y.begin() + 1;
	}
}

vector<int> V[N];
int mark[N];

struct Binary_Indexed_Tree {
	int node[N];

	void update(int pos, int val) {
		for (int i = pos; i < N; i += i & (-i)) node[i] += val;
	}
	int get(int pos) {
		int ans = 0;
		for (int i = pos; i > 0; i -= i & (-i)) ans += node[i];
		return ans;
	}
} BIT;

void sol() {
	compress();

	sort(a+1, a+n+1, [] (ii u, ii v) {
		return u.second < v.second || ( u.second == v.second && u.first < v.first );
	});

	for (int i = 1; i <= n; ++i) V[ a[i].second ].push_back( a[i].first );

	int num = 0, res = 0;
	for (int y = (int) Y.size(); y >= 1; --y) {
		for (int x : V[y]) if (!mark[x]) {
			num++; mark[x] = y;
			BIT.update(x, 1);
		}

		int Add = 0, Prev = 0;
		for (int x : V[y]) {
				// cerr << "??? " << '\n';
			int tmp = BIT.get(x) - Prev;
			Add += tmp * (num - Prev - tmp + 1);
			Prev += tmp;
		}
 		res += Add;

			// cerr << "# " << y << " --> " << Add << '\n';
	}
	cout << res << '\n';
}

main() {
	if (fopen("input.txt", "r")) {
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	}

	cin >> n;
	for (int i = 1; i <= n; ++i) cin >> a[i].first >> a[i].second;

	sol();

	return 0;
}


#include<bits/stdc++.h>
#define int 			long long
using namespace std;

typedef pair<int, int> ii;

const int N = 2e5 + 4;
int n;
ii a[N];

vector<int> X, Y;

void compress() {
	for (int i = 1; i <= n; ++i) {
		X.push_back(a[i].first);
		Y.push_back(a[i].second);
	}

	sort(X.begin(), X.end());
	X.resize(unique(X.begin(), X.end()) - X.begin());
	sort(Y.begin(), Y.end());
	Y.resize(unique(Y.begin(), Y.end()) - Y.begin());

	for (int i = 1; i <= n; ++i) {
		a[i].first = lower_bound(X.begin(), X.end(), a[i].first) - X.begin() + 1;
		a[i].second = lower_bound(Y.begin(), Y.end(), a[i].second) - Y.begin() + 1;
	}
}

vector<int> V[N];
int mark[N];

struct Binary_Indexed_Tree {
	int node[N];

	void update(int pos, int val) {
		for (int i = pos; i < N; i += i & (-i)) node[i] += val;
	}
	int get(int pos) {
		int ans = 0;
		for (int i = pos; i > 0; i -= i & (-i)) ans += node[i];
		return ans;
	}
} BIT;

void sol() {
	compress();

	sort(a+1, a+n+1, [] (ii u, ii v) {
		return u.second < v.second || ( u.second == v.second && u.first < v.first );
	});

	for (int i = 1; i <= n; ++i) V[ a[i].second ].push_back( a[i].first );

	int num = 0, res = 0;
	for (int y = (int) Y.size(); y >= 1; --y) {
		for (int x : V[y]) if (!mark[x]) {
			num++; mark[x] = y;
			BIT.update(x, 1);
		}

		int Add = 0, Prev = 0;
		for (int x : V[y]) if (mark[x] == y) {
			int tmp = BIT.get(x) - Prev;
			Add += tmp * (num - Prev - tmp + 1);
			Prev += tmp;
		}
 		res += Add;

			cerr << "# " << y << " --> " << Add << '\n';
	}
	cout << res << '\n';
}

main() {
	if (fopen("input.txt", "r")) {
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	}

	cin >> n;
	for (int i = 1; i <= n; ++i) cin >> a[i].first >> a[i].second;

	sol();

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;

int N;
LL ans;
LL BIT[202020];
int X[202020], Y[202020];
bool chk[202020];
vector<int> xcomp, ycomp;
vector<int> V[202020];
map<int,int> M;

void update(int t){
    while (t <= N+1){
        BIT[t]++;
        t += t & -t;
    }
}

LL read(int t){
    LL ret = 0;
    while (t){
        ret += BIT[t];
        t -= t & -t;
    }
    return ret;
}

int main(){
    scanf("%d", &N);
    for (int i=1; i<=N; i++) {
        scanf("%d %d", &X[i], &Y[i]);
        xcomp.push_back(X[i]);
        ycomp.push_back(Y[i]);
    }
    sort(xcomp.begin(), xcomp.end());
    sort(ycomp.begin(), ycomp.end());
    xcomp.erase(unique(xcomp.begin(), xcomp.end()), xcomp.end());
    ycomp.erase(unique(ycomp.begin(), ycomp.end()), ycomp.end());
    for (int i=1; i<=N; i++) {
        V[i].push_back(0);
        V[i].push_back(N+1);
    }
    for (int i=1; i<=N; i++) V[N-(lower_bound(ycomp.begin(), ycomp.end(), Y[i])-ycomp.begin())].push_back(lower_bound(xcomp.begin(), xcomp.end(), X[i])-xcomp.begin()+1);
    for (int i=1; i<=N; i++) sort(V[i].begin(), V[i].end());
    for (int i=1; i<=N; i++){
        LL cnt = read(N+1);
        for (int j=1; j<(int)V[i].size()-1; j++) if (chk[V[i][j]]) cnt--;
        ans += cnt * (cnt+1) / 2;
        for (int j=0; j<(int)V[i].size()-1; j++){
            cnt = read(V[i][j+1]-1) - read(V[i][j]);
            ans -= cnt * (cnt+1) / 2;
        }
        for (int j=1; j<(int)V[i].size()-1; j++) ans += read(V[i][j]-1) - read(V[i][j-1]);
        for (int j=1; j<(int)V[i].size()-1; j++) ans += read(V[i][j+1]-1) - read(V[i][j]);
        ans += (V[i].size()-2) * (V[i].size()-1) / 2;
        for (int j=1; j<(int)V[i].size()-1; j++){
            if (!chk[V[i][j]]){
                update(V[i][j]);
                chk[V[i][j]] = true;
            }
        }
    }
    printf("%lld\n", ans);
    return 0;
}


#include <iostream>
#include <algorithm>
#include <unordered_set>
#include <vector>
#include <cstring>
#include <unordered_map>
#include <set>
#include <queue>
#include <map>
#include <list>
#include <cmath>
#include <iomanip>

#define pb push_back
#define mp make_pair
#define set(a,v) memset(a,v,sizeof(a))
#define fr first
#define se second
#define all(a) a.begin(), a.end()
#define sz size()

using namespace std;

typedef long double ld;
typedef long long ll;
typedef unsigned long long llu;
typedef pair<int,int> pii;
typedef pair<ll ,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;

const int inf = 1e9+7;
const ll big = inf*1LL*inf;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);

    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    int n, k;
    cin >> n >> k;

    int a[n+1], b[n+1];
    for (int i=1;i <= n; ++i)
        cin >> a[i];
    for (int i=1;i <= n; ++i)
        cin >> b[i];

    ll lo = 0, hi = big;
    ll ans = -1;
    while (lo <= hi) {
        ll c = (lo+hi) >> 1;
        set<pair<ll, pll>> laps;
        for (int i=1;i <= n; ++i) {
            laps.insert({a[i]/b[i], {a[i], i}});
        }

        ll totalTime = k, elapsedTime = 0;

        bool np = false;
        while (totalTime) {
            pair<ll, pll> lap = *(laps.begin());
            laps.erase(laps.begin());
            ll ttl = lap.fr, charge = lap.se.fr;
            int ind = lap.se.se;
            if (charge - elapsedTime*b[ind] < 0) {
                np = true;
                break;
            }

            charge += c;
            ttl = charge/b[ind];
            laps.insert({ttl, {charge, ind}});
            elapsedTime++;
            totalTime--;
        }

        if (np) {
            lo = c+1;
        } else {
            ans = c;
            hi = c-1;
        }

    }
    cout << ans;
    return 0;
}


#include <iostream>
#include <algorithm>
#include <unordered_set>
#include <vector>
#include <cstring>
#include <unordered_map>
#include <set>
#include <queue>
#include <map>
#include <list>
#include <cmath>
#include <iomanip>

#define pb push_back
#define mp make_pair
#define set(a,v) memset(a,v,sizeof(a))
#define fr first
#define se second
#define all(a) a.begin(), a.end()
#define sz size()

using namespace std;

typedef long double ld;
typedef long long ll;
typedef unsigned long long llu;
typedef pair<int,int> pii;
typedef pair<ll ,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;

const int inf = 1e9+7;
const ll big = inf*1LL*inf;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);

    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    int n, k;
    cin >> n >> k;

    ll a[n+1], b[n+1];
    for (int i=1;i <= n; ++i)
        cin >> a[i];
    for (int i=1;i <= n; ++i)
        cin >> b[i];

    ll lo = 0, hi = 2e12;
    ll ans = -1;
    while (lo <= hi) {
        ll c = (lo+hi) >> 1;
        vector<int> laps[k+10];
        ll charge[n+1];
        for (int i=1;i <= n; ++i) {
            if (a[i]/b[i] < k)
                laps[a[i]/b[i]+1].pb(i);
            charge[i] = a[i];
        }

        int t_neg = 0;
        bool np = false;
        for (int t=0;t < k; ++t) {
            while (t_neg < k and laps[t_neg].empty())
                t_neg++;

            if (t_neg == k) {
                break;
            }
            if (t_neg <= t) {
                np = true;
                break;
            }
            int ind = laps[t_neg].back();
            if (charge[ind]+c < (t+1)*b[ind]) {
                np = true;
                break;
            }

            charge[ind] += c;
            ll new_tneg = (charge[ind]-(t+1)*b[ind])/b[ind]+1;
            laps[t_neg].pop_back();
            if (t+1+new_tneg < k)
                laps[t+1+new_tneg].pb(ind);
        }
        if (np) {
            lo = c+1;
        } else {
            ans = c;
            hi = c-1;
        }

    }
    cout << ans;
    return 0;
}


#include <iostream>
#include <algorithm>
#include <unordered_set>
#include <vector>
#include <cstring>
#include <unordered_map>
#include <set>
#include <queue>
#include <map>
#include <list>
#include <cmath>
#include <iomanip>

#define pb push_back
#define mp make_pair
#define set(a,v) memset(a,v,sizeof(a))
#define fr first
#define se second
#define all(a) a.begin(), a.end()
#define sz size()

using namespace std;

typedef long double ld;
typedef long long ll;
typedef unsigned long long llu;
typedef pair<int,int> pii;
typedef pair<ll ,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;

const int inf = 1e9+7;
const ll big = inf*1LL*inf;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);

    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    int n, k;
    cin >> n >> k;

    ll a[n+1], b[n+1];
    for (int i=1;i <= n; ++i)
        cin >> a[i];
    for (int i=1;i <= n; ++i)
        cin >> b[i];

    ll lo = 0, hi = 2e12;
    ll ans = -1;
    while (lo <= hi) {
        ll c = (lo+hi) >> 1;
        set<pair<ll, pll>> laps;
        for (int i=1;i <= n; ++i) {
            laps.insert({a[i]/b[i], {a[i], i}});
        }

        int totalTime = k, elapsedTime = 0;

        bool np = false;
        while (totalTime) {
            pair<ll, pll> lap = *(laps.begin());
            laps.erase(laps.begin());
            ll ttl = lap.fr, charge = lap.se.fr;
            int ind = lap.se.se;

            if (ttl - elapsedTime >= totalTime) {
                break;
            }
            if (charge - elapsedTime*b[ind] < 0) {
                np = true;
                break;
            }

            charge += c;
            ttl = charge/b[ind];
            laps.insert({ttl, {charge, ind}});
            elapsedTime++;
            totalTime--;
        }

        if (np) {
            lo = c+1;
        } else {
            ans = c;
            hi = c-1;
        }

    }
    cout << ans;
    return 0;
}


#include <iostream>
#include <algorithm>
#include <unordered_set>
#include <vector>
#include <cstring>
#include <unordered_map>
#include <set>
#include <queue>
#include <map>
#include <list>
#include <cmath>
#include <iomanip>

#define pb push_back
#define mp make_pair
#define set(a,v) memset(a,v,sizeof(a))
#define fr first
#define se second
#define all(a) a.begin(), a.end()
#define sz size()

using namespace std;

typedef long double ld;
typedef long long ll;
typedef unsigned long long llu;
typedef pair<int,int> pii;
typedef pair<ll ,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;

const int inf = 1e9+7;
const ll big = inf*1LL*inf;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);

    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    int n, k;
    cin >> n >> k;

    ll a[n+1], b[n+1];
    for (int i=1;i <= n; ++i)
        cin >> a[i];
    for (int i=1;i <= n; ++i)
        cin >> b[i];

    ll lo = 0, hi = 2e12;
    ll ans = -1;
    while (lo <= hi) {
        ll c = (lo+hi) >> 1;
        set<pair<ll, pll>> laps;
        for (int i=1;i <= n; ++i) {
            if (a[i]/b[i] < k)
                laps.insert({a[i]/b[i], {a[i], i}});
        }

        int totalTime = k, elapsedTime = 0;

        bool np = false;
        while (totalTime and laps.size() > 0) {
            pair<ll, pll> lap = *(laps.begin());
            ll ttl = lap.fr, charge = lap.se.fr;
            int ind = lap.se.se;

            if (charge - elapsedTime*b[ind] < 0) {
                np = true;
                break;
            }

            laps.erase(laps.begin());
            charge += c;
            ttl = charge/b[ind];
            elapsedTime++;
            totalTime--;
            if (ttl < k)
                laps.insert({ttl, {charge, ind}});
        }

        if (np) {
            lo = c+1;
        } else {
            ans = c;
            hi = c-1;
        }

    }
    cout << ans;
    return 0;
}


#include <iostream>
#include <algorithm>
#include <unordered_set>
#include <vector>
#include <cstring>
#include <unordered_map>
#include <set>
#include <queue>
#include <map>
#include <list>
#include <cmath>
#include <iomanip>

#define pb push_back
#define mp make_pair
#define set(a,v) memset(a,v,sizeof(a))
#define fr first
#define se second
#define all(a) a.begin(), a.end()
#define sz size()

using namespace std;

typedef long double ld;
typedef long long ll;
typedef unsigned long long llu;
typedef pair<int,int> pii;
typedef pair<ll ,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;

const int inf = 1e9+7;
const ll big = inf*1LL*inf;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);

    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    int n, k;
    cin >> n >> k;

    int a[n+1], b[n+1];
    for (int i=1;i <= n; ++i)
        cin >> a[i];
    for (int i=1;i <= n; ++i)
        cin >> b[i];

    ll lo = 0, hi = big;
    ll ans = -1;
    while (lo <= hi) {
        ll c = (lo+hi) >> 1;
        set<pair<ll, pll>> laps;
        for (int i=1;i <= n; ++i) {
            laps.insert({a[i]/b[i], {a[i], i}});
        }

        ll totalTime = k, elapsedTime = 0;

        bool np = false;
        while (totalTime) {
            pair<ll, pll> lap = *(laps.begin());
            laps.erase(laps.begin());
            ll ttl = lap.fr, charge = lap.se.fr;
            int ind = lap.se.se;

            if (ttl - elapsedTime >= totalTime) {
                break;
            }
            if (charge - elapsedTime*b[ind] < 0) {
                np = true;
                break;
            }

            charge += c;
            ttl = charge/b[ind];
            laps.insert({ttl, {charge, ind}});
            elapsedTime++;
            totalTime--;
        }

        if (np) {
            lo = c+1;
        } else {
            ans = c;
            hi = c-1;
        }

    }
    cout << ans;
    return 0;
}


#include <bits/stdc++.h>

const int INF = (int)1e9;

using namespace std;

#define endl '\n'
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define popcnt(x) __builtin_popcount(x)

typedef long long ll;

int n, k;
vector<ll> a, b;

double calc(ll init, ll usage) {
    return (double) (init + 1) / usage;
}

bool valid(ll x) {
    set<pair<double, int>> s;
    for (int i = 0; i < n; i++) {
        double t = calc(a[i], b[i]);
        s.insert({t, i});
    }
    vector<ll> A(n), t(n);
    A = a;
    for (int i = 0; i < k; i++) {
        auto it = s.begin();
        pair<double, int> tmp = *it;
        s.erase(it);
        if ((double)i >= tmp.F) {
            return false;
        }
        ll rem = (ll) i - t[tmp.S];
        A[tmp.S] -= rem * b[tmp.S];
        A[tmp.S] -= b[tmp.S] - x;
        tmp = {calc(A[tmp.S], b[tmp.S]) + i + 1, tmp.S};
        t[tmp.S] = i + 1;
        s.insert(tmp);
    }
    return true;
}

int main () {
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    cin >> n >> k;
    a.resize(n), b.resize(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> b[i];
    }
    ll l = 0, h = 1e10;
    ll ans = -1;
    if (valid(0)) {
        cout << 0 << endl;
        return 0;
    }
    while (l < h) {
        ll mid = l + (h - l) / 2;
        if (valid(mid)) {
            h = mid;
            ans = mid;
        }
        else {
            l = mid + 1;
        }
    }
    if (valid(0)) {
        cout << 0 << endl;
        return 0;
    }
    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>

const int INF = (int)1e9;

using namespace std;

#define endl '\n'
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define popcnt(x) __builtin_popcount(x)

typedef long long ll;

int n, k;
vector<ll> a, b;

double calc(ll init, ll usage) {
    return (double) (init + 1) / usage;
}

bool valid(ll x) {
    set<pair<double, int>> s;
    for (int i = 0; i < n; i++) {
        double t = calc(a[i], b[i]);
        s.insert({t, i});
    }
    vector<ll> A(n), t(n);
    A = a;
    for (int i = 0; i < k; i++) {
        auto it = s.begin();
        pair<double, int> tmp = *it;
        s.erase(it);
        if ((double)i >= tmp.F) {
            return false;
        }
        ll rem = (ll) i - t[tmp.S];
        A[tmp.S] -= rem * b[tmp.S];
        A[tmp.S] -= b[tmp.S] - x;
        tmp = {calc(A[tmp.S], b[tmp.S]) + i + 1, tmp.S};
        t[tmp.S] = i + 1;
        s.insert(tmp);
    }
    return true;
}

int main () {
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    cin >> n >> k;
    a.resize(n), b.resize(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> b[i];
    }
    ll l = 0, h = 1e13;
    ll ans = -1;
    valid(5);
    while (l < h) {
        ll mid = l + (h - l) / 2;
        if (valid(mid)) {
            h = mid;
            ans = mid;
        }
        else {
            l = mid + 1;
        }
    }
    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>

const int INF = (int)1e9;

using namespace std;

#define endl '\n'
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define popcnt(x) __builtin_popcount(x)

typedef long long ll;

int n, k;
vector<ll> a, b;

double calc(ll init, ll usage) {
    return (double) (init + 1) / usage;
}

bool valid(ll x) {
    set<pair<double, int>> s;
    for (int i = 0; i < n; i++) {
        double t = calc(a[i], b[i]);
        s.insert({t, i});
    }
    vector<ll> A(n), t(n);
    A = a;
    for (int i = 0; i < k; i++) {
        auto it = s.begin();
        pair<double, int> tmp = *it;
        s.erase(it);
        if ((double)i >= tmp.F) {
            return false;
        }
        ll rem = (ll) i - t[tmp.S];
        A[tmp.S] -= rem * b[tmp.S];
        A[tmp.S] -= b[tmp.S] - x;
        tmp = {calc(A[tmp.S], b[tmp.S]) + i + 1, tmp.S};
        t[tmp.S] = i + 1;
        s.insert(tmp);
    }
    return true;
}

int main () {
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    cin >> n >> k;
    a.resize(n), b.resize(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> b[i];
    }
    ll l = 0, h = 1e10;
    ll ans = -1;
    while (l < h) {
        ll mid = l + (h - l) / 2;
        if (valid(mid)) {
            h = mid;
            ans = mid;
        }
        else {
            l = mid + 1;
        }
    }
    if (valid(0)) {
        cout << 0 << endl;
        return 0;
    }
    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>

const int INF = (int)1e9;

using namespace std;

#define endl '\n'
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define popcnt(x) __builtin_popcount(x)

typedef long long ll;

int n, k;
vector<ll> a, b;

double calc(ll init, ll usage) {
    return (double) (init + 1) / usage;
}

bool valid(ll x) {
    set<pair<double, int>> s;
    for (int i = 0; i < n; i++) {
        double t = calc(a[i], b[i]);
        s.insert({t, i});
    }
    vector<ll> A(n), t(n);
    A = a;
    for (int i = 0; i < k; i++) {
        auto it = s.begin();
        pair<double, int> tmp = *it;
        s.erase(it);
        if ((double)i >= tmp.F) {
            return false;
        }
//        cout << tmp.S << " >>>> " << tmp.F  << "  " << A[tmp.S] << endl;
        ll rem = (ll) i - t[tmp.S];
        A[tmp.S] -= rem * b[tmp.S];
        A[tmp.S] -= b[tmp.S] - x;
        tmp = {calc(A[tmp.S], b[tmp.S]) + i + 1, tmp.S};
        t[tmp.S] = i + 1;
        s.insert(tmp);
    }
    return true;
}

int main () {
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    cin >> n >> k;
    a.resize(n), b.resize(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> b[i];
    }
    ll l = 0, h = 1e15;
    ll ans = -1;
    valid(5);
    while (l < h) {
        ll mid = l + (h - l) / 2;
        if (valid(mid)) {
            h = mid;
            ans = mid;
        }
        else {
            l = mid + 1;
        }
    }
    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>

const int INF = (int)1e9;

using namespace std;

#define endl '\n'
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define popcnt(x) __builtin_popcount(x)

typedef long long ll;

int n, k;
vector<ll> a, b;

double calc(ll init, ll usage) {
    return (double) (init + 1) / usage;
}

bool valid(ll x) {
    set<pair<double, int>> s;
    for (int i = 0; i < n; i++) {
        double t = calc(a[i], b[i]);
        s.insert({t, i});
    }
    vector<ll> A(n), t(n);
    A = a;
    for (int i = 0; i < k; i++) {
        auto it = s.begin();
        pair<double, int> tmp = *it;
        s.erase(it);
        if ((double)i >= tmp.F) {
            return false;
        }
        ll rem = (ll) i - t[tmp.S];
        A[tmp.S] -= rem * b[tmp.S];
        A[tmp.S] -= b[tmp.S] - x;
        tmp = {calc(A[tmp.S], b[tmp.S]) + i + 1, tmp.S};
        t[tmp.S] = i + 1;
        s.insert(tmp);
    }
    return true;
}

int main () {
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    cin >> n >> k;
    a.resize(n), b.resize(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> b[i];
    }
    ll l = -1, h = 1e11;
    ll ans = -1;
    while (l < h) {
        ll mid = l + (h - l) / 2;
        if (valid(mid)) {
            h = mid;
            ans = mid;
        }
        else {
            l = mid + 1;
        }
    }
    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>

const int INF = (int)1e9;

using namespace std;

#define endl '\n'
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define popcnt(x) __builtin_popcount(x)

typedef long long ll;

int n, k;
vector<ll> a, b;

double calc(ll init, ll usage) {
    return (double) (init + 1) / usage;
}

bool valid(ll x) {
    set<pair<double, int>> s;
    for (int i = 0; i < n; i++) {
        double t = calc(a[i], b[i]);
        s.insert({t, i});
    }
    vector<ll> A(n), t(n);
    A = a;
    for (int i = 0; i < k; i++) {
        auto it = s.begin();
        pair<double, int> tmp = *it;
        s.erase(it);
        if ((double)i >= tmp.F) {
            return false;
        }
        ll rem = (ll) i - t[tmp.S];
        A[tmp.S] -= rem * b[tmp.S];
        A[tmp.S] -= b[tmp.S] - x;
        tmp = {calc(A[tmp.S], b[tmp.S]) + i + 1, tmp.S};
        t[tmp.S] = i + 1;
        s.insert(tmp);
    }
    return true;
}

int main () {
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    cin >> n >> k;
    a.resize(n), b.resize(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> b[i];
    }
    ll l = 0, h = 1e9;
    ll ans = -1;
    while (l < h) {
        ll mid = l + (h - l) / 2;
        if (valid(mid)) {
            h = mid;
            ans = mid;
        }
        else {
            l = mid + 1;
        }
    }
    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>

const int INF = (int)1e9;

using namespace std;

#define endl '\n'
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define popcnt(x) __builtin_popcount(x)

typedef long long ll;

int n, k;
vector<ll> a, b;

ll calc(ll init, ll usage) {
    return  (init + 1 + usage - 1) / usage;
}

bool valid(ll x) {
    priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> pq;
    vector<ll> tmp (n);
    for (int i = 0; i < n; i++) {
        tmp[i] = a[i];
        ll t = calc(a[i], b[i]);
        pq.push({t, i});
    }
    for (int i = 0; i < k; i++) {
        pair<ll, int> cur = pq.top();
        pq.pop();
        if (i >= cur.F) {
            return false;
        }
        tmp[cur.S] += x;
        cur.F = calc(tmp[cur.S], b[cur.S]);
        pq.push(cur);
    }
    return true;
}

int main () {
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    cin >> n >> k;
    a.resize(n), b.resize(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> b[i];
    }
    ll l = 0, h = 2e12;
    ll ans = -1;
    while (l < h) {
        ll mid = l + (h - l) / 2;
        if (valid(mid)) {
            h = mid;
            ans = mid;
        }
        else {
            l = mid + 1;
        }
    }
    cout << ans << endl;
    return 0;
}


#include <cstdio>
#include <memory.h>
#include <cstring>
#include <vector>
#include <deque>
#include <cstdlib>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cassert>
#include <functional>
#include <iostream>
#include <set>
#include <list>
#include <map>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
using namespace std;

typedef unsigned long long llu;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<string, int> psi;
const ll MOD = 1e9 + 7;
const long double PI = 3.141592653589793238462643383279502884197;

struct node {
	ll la, co;
	bool operator< (const node &v2) const { return la / co > v2.la / v2.co; };
};

priority_queue<node> tmp;
node vec[200000];
int n, k;

bool go(ll mid) {
	priority_queue<node> pq = tmp;

	node tv;
	for (int i = 1; i < k; i++) {
		tv = pq.top();
		pq.pop();
		tv.la += mid;

		if (tv.co * i > tv.la || (!pq.empty() && pq.top().co * i > pq.top().la)) return 0;
		pq.push(tv);
	}

	return 1;
}

int main() {
	scanf("%d %d", &n, &k);

	for (int i = 0; i < n; i++)
		scanf("%lld", &vec[i].la);

	for (int i = 0; i < n; i++) {
		scanf("%lld", &vec[i].co);
		tmp.push(vec[i]);
	}

	ll l = 0, r = 2e12 + 7, mid;
	while (l <= r) {
		mid = (l + r) / 2;
		if (go(mid)) r = mid - 1;
		else l = mid + 1;
	}

	if (l > 2e12 + 3) return !printf("-1");
	printf("%lld", l);
}


#include <cstdio>
#include <memory.h>
#include <cstring>
#include <vector>
#include <deque>
#include <cstdlib>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cassert>
#include <functional>
#include <iostream>
#include <set>
#include <list>
#include <map>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
using namespace std;

typedef unsigned long long llu;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<string, int> psi;
const ll MOD = 1e9 + 7;
const long double PI = 3.141592653589793238462643383279502884197;

struct node {
	ll la;
	int co;
	bool operator< (const node &v2) const { return la / co > v2.la / v2.co; };
};

priority_queue<node> tmp;
node vec[200000];
int n, k;

bool go(ll mid) {
	priority_queue<node> pq = tmp;

	node tv;
	for (int i = 1; i < k && !pq.empty(); i++) {
		tv = pq.top();
		pq.pop();
		tv.la += mid;

		if ((ll)tv.co * i > tv.la || (!pq.empty() && (ll)pq.top().co * i > pq.top().la)) return 0;
		if ((ll)tv.co * (k - 1) > tv.la) pq.push(tv);
	}

	return 1;
}

int main() {
	scanf("%d %d", &n, &k);

	for (int i = 0; i < n; i++)
		scanf("%lld", &vec[i].la);

	for (int i = 0; i < n; i++) {
		scanf("%d", &vec[i].co);
		tmp.push(vec[i]);
	}

	ll l = 0, r = 2e12 + 7, mid;
	while (l <= r) {
		mid = (l + r) / 2;
		if (go(mid)) r = mid - 1;
		else l = mid + 1;
	}

	if (l > 2e12 + 3) return !printf("-1");
	printf("%lld", l);
}


#include <cstdio>
#include <memory.h>
#include <cstring>
#include <vector>
#include <deque>
#include <cstdlib>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cassert>
#include <functional>
#include <iostream>
#include <set>
#include <list>
#include <map>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
using namespace std;

typedef unsigned long long llu;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<string, int> psi;
const ll MOD = 1e9 + 7;
const long double PI = 3.141592653589793238462643383279502884197;

priority_queue<pli, vector<pli>, greater<pli>> tmp;
pll vec[200000];
int num[200000];
int n, k;

bool go(ll mid) {
	priority_queue<pli, vector<pli>, greater<pli>> pq = tmp;
	memset(num, 0, sizeof(num));

	int tv, tt;
	for (int i = 1; i < k; i++) {
		tv = pq.top().second;
		pq.pop();
		if(n != 1) tt = pq.top().second;

		if (++num[tv] * mid + vec[tv].first < vec[tv].second * i || (n != 1 && num[tt] * mid + vec[tt].first < vec[tt].second * i)) return 0;
		pq.push({ (num[tv] * mid + vec[tv].first) / vec[tv].second, tv });
	}

	return 1;
}

int main() {
	scanf("%d %d", &n, &k);

	for (int i = 0; i < n; i++)
		scanf("%lld", &vec[i].first);

	for (int i = 0; i < n; i++) {
		scanf("%lld", &vec[i].second);
		tmp.push({ vec[i].first / vec[i].second, i });
	}

	ll l = 0, r = 2e12 + 7, mid;
	while (l <= r) {
		mid = (l + r) / 2;
		if (go(mid)) r = mid - 1;
		else l = mid + 1;
	}

	if (l > 2e12 + 3) return !printf("-1");
	printf("%lld", l);
}


#include <cstdio>
#include <memory.h>
#include <cstring>
#include <vector>
#include <deque>
#include <cstdlib>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cassert>
#include <functional>
#include <iostream>
#include <set>
#include <list>
#include <map>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
using namespace std;

typedef unsigned long long llu;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<string, int> psi;
const ll MOD = 1e9 + 7;
const long double PI = 3.141592653589793238462643383279502884197;

struct node {
	ll la, co;
	bool operator< (const node &v2) const { return la * v2.co > v2.la * co; };
};

priority_queue<node> tmp;
node vec[200000];
int n, k;

bool go(ll mid) {
	priority_queue<node> pq = tmp;

	node tv;
	for (int i = 1; i < k; i++) {
		tv = pq.top();
		pq.pop();
		tv.la += mid;

		if (tv.co * i > tv.la || (!pq.empty() && pq.top().co * i > pq.top().la)) return 0;
		pq.push(tv);
	}

	return 1;
}

int main() {
	scanf("%d %d", &n, &k);

	for (int i = 0; i < n; i++)
		scanf("%lld", &vec[i].la);

	for (int i = 0; i < n; i++) {
		scanf("%lld", &vec[i].co);
		tmp.push(vec[i]);
	}

	ll l = 0, r = 2e12 + 7, mid;
	while (l <= r) {
		mid = (l + r) / 2;
		if (go(mid)) r = mid - 1;
		else l = mid + 1;
	}

	if (l > 2e12 + 3) return !printf("-1");
	printf("%lld", l);
}


#include <cstdio>
#include <memory.h>
#include <cstring>
#include <vector>
#include <deque>
#include <cstdlib>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cassert>
#include <functional>
#include <iostream>
#include <set>
#include <list>
#include <map>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
using namespace std;

typedef unsigned long long llu;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<string, int> psi;
const ll MOD = 1e9 + 7;
const long double PI = 3.141592653589793238462643383279502884197;

struct node {
	llu la, co;
	bool operator< (const node &v2) const { return la * v2.co > v2.la * co; };
};

priority_queue<node> tmp;
node vec[200000];
int n, k;

bool go(llu mid) {
	priority_queue<node> pq = tmp;

	node tv;
	for (int i = 1; i < k; i++) {
		tv = pq.top();
		pq.pop();
		tv.la += mid;

		if (tv.co * i > tv.la || (!pq.empty() && pq.top().co * i > pq.top().la)) return 0;
		pq.push(tv);
	}

	return 1;
}

int main() {
	scanf("%d %d", &n, &k);

	for (int i = 0; i < n; i++)
		scanf("%llu", &vec[i].la);

	for (int i = 0; i < n; i++) {
		scanf("%llu", &vec[i].co);
		tmp.push(vec[i]);
	}

	llu l = 0, r = 2e12 + 7, mid;
	while (l <= r) {
		mid = (l + r) / 2;
		if (go(mid)) r = mid - 1;
		else l = mid + 1;
	}

	if (l > 2e12 + 3) return !printf("-1");
	printf("%lld", l);
}


#include <cstdio>
#include <memory.h>
#include <cstring>
#include <vector>
#include <deque>
#include <cstdlib>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cassert>
#include <functional>
#include <iostream>
#include <set>
#include <list>
#include <map>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
using namespace std;

typedef unsigned long long llu;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<string, int> psi;
const ll MOD = 1e9 + 7;
const long double PI = 3.141592653589793238462643383279502884197;

struct node {
	ll la;
	int co;
	bool operator< (const node &v2) const { return la * v2.co > v2.la * co; };
};

priority_queue<node> tmp;
node vec[200000];
int n, k;

bool go(ll mid) {
	priority_queue<node> pq = tmp;

	node tv;
	for (int i = 1; i < k; i++) {
		tv = pq.top();
		pq.pop();
		tv.la += mid;

		if (tv.co * i > tv.la || (!pq.empty() && pq.top().co * i > pq.top().la)) return 0;
		pq.push(tv);
	}

	return 1;
}

int main() {
	scanf("%d %d", &n, &k);

	for (int i = 0; i < n; i++)
		scanf("%lld", &vec[i].la);

	for (int i = 0; i < n; i++) {
		scanf("%d", &vec[i].co);
		tmp.push(vec[i]);
	}

	ll l = 0, r = 2e12 + 7, mid;
	while (l <= r) {
		mid = (l + r) / 2;
		if (go(mid)) r = mid - 1;
		else l = mid + 1;
	}

	if (l > 2e12 + 3) return !printf("-1");
	printf("%lld", l);
}


#include <cstdio>
#include <memory.h>
#include <cstring>
#include <vector>
#include <deque>
#include <cstdlib>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cassert>
#include <functional>
#include <iostream>
#include <set>
#include <list>
#include <map>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
using namespace std;

typedef unsigned long long llu;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<string, int> psi;
const ll MOD = 1e9 + 7;
const long double PI = 3.141592653589793238462643383279502884197;

struct node {
	llu la, co;
	bool operator< (const node &v2) const { return la * v2.co > v2.la * co; };
};

priority_queue<node> tmp;
node vec[200000];
int n, k;

bool go(llu mid) {
	priority_queue<node> pq = tmp;

	node tv;
	for (int i = 1; i < k; i++) {
		tv = pq.top();
		pq.pop();
		tv.la += mid;

		if (tv.co * i > tv.la || (!pq.empty() && pq.top().co * i > pq.top().la)) return 0;
		if (tv.la >= 2e13 + 7) return 1;
		pq.push(tv);
	}

	return 1;
}

int main() {
	scanf("%d %d", &n, &k);

	for (int i = 0; i < n; i++)
		scanf("%llu", &vec[i].la);

	for (int i = 0; i < n; i++) {
		scanf("%llu", &vec[i].co);
		tmp.push(vec[i]);
	}

	llu l = 0, r = 2e12 + 7, mid;
	while (l <= r) {
		mid = (l + r) / 2;
		if (go(mid)) r = mid - 1;
		else l = mid + 1;
	}

	if (l > 2e12 + 3) return !printf("-1");
	printf("%llu", l);
}


#include <cstdio>
#include <memory.h>
#include <cstring>
#include <vector>
#include <deque>
#include <cstdlib>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cassert>
#include <functional>
#include <iostream>
#include <set>
#include <list>
#include <map>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
using namespace std;

typedef unsigned long long llu;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<string, int> psi;
const ll MOD = 1e9 + 7;
const long double PI = 3.141592653589793238462643383279502884197;

struct node {
	llu la, co;
	bool operator< (const node &v2) const { return la * v2.co > v2.la * co; };
};

priority_queue<node> tmp;
node vec[200000];
int n, k;

bool go(llu mid) {
	priority_queue<node> pq = tmp;

	node tv;
	for (int i = 1; i < k; i++) {
		tv = pq.top();
		pq.pop();
		tv.la += mid;

		if (tv.co * i > tv.la || (!pq.empty() && pq.top().co * i > pq.top().la)) return 0;
		pq.push(tv);
	}

	return 1;
}

int main() {
	scanf("%d %d", &n, &k);

	for (int i = 0; i < n; i++)
		scanf("%llu", &vec[i].la);

	for (int i = 0; i < n; i++) {
		scanf("%llu", &vec[i].co);
		tmp.push(vec[i]);
	}

	ll l = 0, r = 2e12 + 7, mid;
	while (l <= r) {
		mid = (l + r) / 2;
		if (go(mid)) r = mid - 1;
		else l = mid + 1;
	}

	if (l > 2e12 + 3) return !printf("-1");
	printf("%lld", l);
}


#include <cstdio>
#include <memory.h>
#include <cstring>
#include <vector>
#include <deque>
#include <cstdlib>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cassert>
#include <functional>
#include <iostream>
#include <set>
#include <list>
#include <map>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
using namespace std;

typedef unsigned long long llu;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<string, int> psi;
const ll MOD = 1e9 + 7;
const long double PI = 3.141592653589793238462643383279502884197;

struct node {
	ll la, co;
	bool operator< (node &v2) const { return la * v2.co > v2.la * co; };
};

priority_queue<node> tmp;
node vec[200000];
int n, k;

bool go(ll mid) {
	priority_queue<node> pq = tmp;

	node tv;
	for (int i = 1; i < k; i++) {
		tv = pq.top();
		pq.pop();
		tv.la += mid;

		if (tv.co * i > tv.la || (!pq.empty() && pq.top().co * i > pq.top().la)) return 0;
		pq.push(tv);
	}

	return 1;
}

int main() {
	scanf("%d %d", &n, &k);

	for (int i = 0; i < n; i++)
		scanf("%lld", &vec[i].la);

	for (int i = 0; i < n; i++) {
		scanf("%lld", &vec[i].co);
		tmp.push(vec[i]);
	}

	ll l = 0, r = 2e12 + 7, mid;
	while (l <= r) {
		mid = (l + r) / 2;
		if (go(mid)) r = mid - 1;
		else l = mid + 1;
	}

	if (l > 2e12 + 3) return !printf("-1");
	printf("%lld", l);
}


#include <cstdio>
#include <memory.h>
#include <cstring>
#include <vector>
#include <deque>
#include <cstdlib>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cassert>
#include <functional>
#include <iostream>
#include <set>
#include <list>
#include <map>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
using namespace std;

typedef unsigned long long llu;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<string, int> psi;
const ll MOD = 1e9 + 7;
const long double PI = 3.141592653589793238462643383279502884197;

struct node {
	ll la, co;
	bool operator< (node v2) const { return la / co > v2.la / v2.co; };
};

priority_queue<node> tmp;
node vec[200000];
int n, k;

bool go(ll mid) {
	priority_queue<node> pq = tmp;

	node tv;
	for (int i = 1; i < k; i++) {
		tv = pq.top();
		pq.pop();
		tv.la += mid;

		if (tv.co * i > tv.la || (!pq.empty() && pq.top().co * i > pq.top().la)) return 0;
		pq.push(tv);
	}

	return 1;
}

int main() {
	scanf("%d %d", &n, &k);

	for (int i = 0; i < n; i++)
		scanf("%lld", &vec[i].la);

	for (int i = 0; i < n; i++) {
		scanf("%lld", &vec[i].co);
		tmp.push(vec[i]);
	}

	ll l = 0, r = 2e12 + 7, mid;
	while (l <= r) {
		mid = (l + r) / 2;
		if (go(mid)) r = mid - 1;
		else l = mid + 1;
	}

	if (l > 2e12 + 3) return !printf("-1");
	printf("%lld", l);
}


#include <cstdio>
#include <memory.h>
#include <cstring>
#include <vector>
#include <deque>
#include <cstdlib>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cassert>
#include <functional>
#include <iostream>
#include <set>
#include <list>
#include <map>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
using namespace std;

typedef unsigned long long llu;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<string, int> psi;
const ll MOD = 1e9 + 7;
const long double PI = 3.141592653589793238462643383279502884197;

struct node {
	ll la;
	int co;
	bool operator< (const node &v2) const { return la / co > v2.la / v2.co; };
};

priority_queue<node> tmp;
node vec[200000];
int n, k;

bool go(ll mid) {
	priority_queue<node> pq = tmp;

	node tv;
	for (int i = 1; i < k && !pq.empty(); i++) {
		tv = pq.top();
		pq.pop();

		if ((ll)tv.co * (i - 1) > tv.la) return 0;
		tv.la += mid;
		if ((ll)tv.co * i > tv.la) return 0;
		if ((ll)tv.co * (k - 1) > tv.la) pq.push(tv);
	}

	return 1;
}

int main() {
	scanf("%d %d", &n, &k);

	for (int i = 0; i < n; i++)
		scanf("%lld", &vec[i].la);

	for (int i = 0; i < n; i++) {
		scanf("%d", &vec[i].co);
		tmp.push(vec[i]);
	}

	ll l = 0, r = 2e12 + 7, mid;
	while (l <= r) {
		mid = (l + r) / 2;
		if (go(mid)) r = mid - 1;
		else l = mid + 1;
	}

	if (l > 2e12 + 3) return !printf("-1");
	printf("%lld", l);
}


#include <cstdio>
#include <memory.h>
#include <cstring>
#include <vector>
#include <deque>
#include <cstdlib>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cassert>
#include <functional>
#include <iostream>
#include <set>
#include <list>
#include <map>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
using namespace std;

typedef unsigned long long llu;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<string, int> psi;
const ll MOD = 1e9 + 7;
const long double PI = 3.141592653589793238462643383279502884197;

struct node {
	llu la, co;
	bool operator< (const node &v2) const { return la * v2.co > v2.la * co; };
};

priority_queue<node> tmp;
node vec[200000];
int n, k;

bool go(llu mid) {
	priority_queue<node> pq = tmp;

	node tv;
	for (int i = 1; i < k; i++) {
		tv = pq.top();
		pq.pop();
		tv.la += mid;

		if (tv.co * i > tv.la || (!pq.empty() && pq.top().co * i > pq.top().la)) return 0;
		if (tv.la >= 2e13 + 7) return 1;
		pq.push(tv);
	}

	return 1;
}

int main() {
	scanf("%d %d", &n, &k);

	for (int i = 0; i < n; i++)
		scanf("%llu", &vec[i].la);

	for (int i = 0; i < n; i++) {
		scanf("%llu", &vec[i].co);
		tmp.push(vec[i]);
	}

	ll l = 0, r = 2e12 + 7, mid;
	while (l <= r) {
		mid = (l + r) / 2;
		if (go(mid)) r = mid - 1;
		else l = mid + 1;
	}

	if (l > 2e12 + 3) return !printf("-1");
	printf("%lld", l);
}


#include <cstdio>
#include <memory.h>
#include <cstring>
#include <vector>
#include <deque>
#include <cstdlib>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cassert>
#include <functional>
#include <iostream>
#include <set>
#include <list>
#include <map>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
using namespace std;

typedef unsigned long long llu;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<string, int> psi;
const ll MOD = 1e9 + 7;
const long double PI = 3.141592653589793238462643383279502884197;

struct node {
	ll la;
	int co;
	bool operator< (const node &v2) const { return la / co > v2.la / v2.co; };
};

priority_queue<node> tmp;
node vec[200000];
int n, k;

bool go(ll mid) {
	priority_queue<node> pq = tmp;

	node tv;
	for (int i = 1; i < k; i++) {
		tv = pq.top();
		pq.pop();
		tv.la += mid;

		if ((ll)tv.co * i > tv.la || (!pq.empty() && (ll)pq.top().co * i > pq.top().la)) return 0;
		pq.push(tv);
	}

	return 1;
}

int main() {
	scanf("%d %d", &n, &k);

	for (int i = 0; i < n; i++)
		scanf("%lld", &vec[i].la);

	for (int i = 0; i < n; i++) {
		scanf("%d", &vec[i].co);
		tmp.push(vec[i]);
	}

	ll l = 0, r = 2e12 + 7, mid;
	while (l <= r) {
		mid = (l + r) / 2;
		if (go(mid)) r = mid - 1;
		else l = mid + 1;
	}

	if (l > 2e12 + 3) return !printf("-1");
	printf("%lld", l);
}


#include <cstdio>
#include <memory.h>
#include <cstring>
#include <vector>
#include <deque>
#include <cstdlib>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cassert>
#include <functional>
#include <iostream>
#include <set>
#include <list>
#include <map>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
using namespace std;

typedef unsigned long long llu;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<string, int> psi;
const ll MOD = 1e9 + 7;
const long double PI = 3.141592653589793238462643383279502884197;

struct node {
	ll la, co;
	bool operator< (const node &v2) const {
		if (la / co == v2.la / v2.co) return co < v2.co;
		return la / co > v2.la / v2.co;
	};
};

node vec[200000];
int n, k;

bool go(ll mid) {
	priority_queue<node> pq;
	for (int i = 0; i < n; i++)
		pq.push(vec[i]);

	node tv;
	for (int i = 1; i < k; i++) {
		tv = pq.top();
		pq.pop();
		tv.la += mid;

		if (tv.co * i > tv.la || (!pq.empty() && pq.top().co * i > pq.top().la)) return 0;
		pq.push(tv);
	}

	return 1;
}

int main() {
	scanf("%d %d", &n, &k);

	for (int i = 0; i < n; i++)
		scanf("%lld", &vec[i].la);

	for (int i = 0; i < n; i++)
		scanf("%lld", &vec[i].co);

	ll l = 0, r = 2e12 + 7, mid;
	while (l <= r) {
		mid = (l + r) / 2;
		if (go(mid)) r = mid - 1;
		else l = mid + 1;
	}

	if (l > 2e12 + 3) return !printf("-1");
	printf("%lld", l);
}


#include <cstdio>
#include <memory.h>
#include <cstring>
#include <vector>
#include <deque>
#include <cstdlib>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cassert>
#include <functional>
#include <iostream>
#include <set>
#include <list>
#include <map>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
using namespace std;

typedef unsigned long long llu;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<string, int> psi;
const ll MOD = 1e9 + 7;
const long double PI = 3.141592653589793238462643383279502884197;

struct node {
	ll la, co;
	bool operator< (node v2) const { return la / co > v2.la * v2.co; };
};

priority_queue<node> tmp;
node vec[200000];
int n, k;

bool go(ll mid) {
	priority_queue<node> pq = tmp;

	node tv;
	for (int i = 1; i < k; i++) {
		tv = pq.top();
		pq.pop();
		tv.la += mid;

		if (tv.co * i > tv.la || (!pq.empty() && pq.top().co * i > pq.top().la)) return 0;
		pq.push(tv);
	}

	return 1;
}

int main() {
	scanf("%d %d", &n, &k);

	for (int i = 0; i < n; i++)
		scanf("%lld", &vec[i].la);

	for (int i = 0; i < n; i++) {
		scanf("%lld", &vec[i].co);
		tmp.push(vec[i]);
	}

	ll l = 0, r = 2e12 + 7, mid;
	while (l <= r) {
		mid = (l + r) / 2;
		if (go(mid)) r = mid - 1;
		else l = mid + 1;
	}

	if (l > 2e12 + 3) return !printf("-1");
	printf("%lld", l);
}


#include <cstdio>
#include <memory.h>
#include <cstring>
#include <vector>
#include <deque>
#include <cstdlib>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cassert>
#include <functional>
#include <iostream>
#include <set>
#include <list>
#include <map>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
using namespace std;

typedef unsigned long long llu;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<string, int> psi;
const ll MOD = 1e9 + 7;
const long double PI = 3.141592653589793238462643383279502884197;

struct node {
	ll la;
	int co;
	bool operator< (const node &v2) const { return la / co > v2.la * v2.co; };
};

priority_queue<node> tmp;
node vec[200000];
int n, k;

bool go(ll mid) {
	priority_queue<node> pq = tmp;

	node tv;
	for (int i = 1; i < k; i++) {
		tv = pq.top();
		pq.pop();
		tv.la += mid;

		if ((ll)tv.co * i > tv.la || (!pq.empty() && (ll)pq.top().co * i > pq.top().la)) return 0;
		pq.push(tv);
	}

	return 1;
}

int main() {
	scanf("%d %d", &n, &k);

	for (int i = 0; i < n; i++)
		scanf("%lld", &vec[i].la);

	for (int i = 0; i < n; i++) {
		scanf("%d", &vec[i].co);
		tmp.push(vec[i]);
	}

	ll l = 0, r = 2e12 + 7, mid;
	while (l <= r) {
		mid = (l + r) / 2;
		if (go(mid)) r = mid - 1;
		else l = mid + 1;
	}

	if (l > 2e12 + 3) return !printf("-1");
	printf("%lld", l);
}


#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
typedef long long ll;
typedef long double  ld;
#define pii pair<ll,ll>
#define pic pair<ll,char>
#define vi vector< ll >
#define vvi vector< vi >
#define vpi vector< pii >
#define vvpi vector< vpi >
#define st  set <ll, greater <ll> >
#define mst  multiset <ll, greater <ll> >
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mapp  unordered_map <ll, ll>
#define ppii pair< pii, pii >
#define test(t) ll t;cin>>t;while(t--)
#define inarr(n) ll arr[n];for(ll i=0;i<n;i++)cin>>arr[i];
#define ingra(m) vvi arr(100005);for(ll i=0;i<m;i++){ll u,v;cin>>u>>v;arr[u].pb(v);arr[v].pb(u);}
#define mem(a,b) memset(a,b,sizeof(a))
#define inn freopen("input.txt", "r", stdin)
#define outt freopen("output.txt", "w", stdout)
#define all(arr) arr.begin(),arr.end()
ll power(ll x,ll y){ll res = 1;while(y){if(y&1) res = (res*x)%mod;y=y/2,x=(x*x)%mod;}return res%mod;}
ll n,k;
pair<  ll ,ll > arr[200001];
set < pair < ll , ll > > lol;
bool func(ll x)
{
    ll cnt = 1;
    ll haha[n];
    for(ll i=0;i<n;i++)
        haha[i] = arr[i].fi;
    while(cnt<=k-1 and !lol.empty())
    {
        pii temp= *lol.begin();
        lol.erase(lol.begin());
        haha[temp.sec]+=x;
        if((haha[temp.sec])<(cnt*arr[temp.sec].sec))
            return false;
        if(lol.empty()==false)
        {
            pii soch = *lol.begin();
            if(haha[soch.sec]<(cnt*arr[soch.sec].sec))
                return false;
        }
        if(haha[temp.sec]<(k-cnt+5)*arr[temp.sec].sec)
            lol.insert(mp(haha[temp.sec]/arr[temp.sec].sec,temp.sec));
        cnt++;
    }
    return true;
}
signed main()
{
    fast;
    cin>>n>>k;
    ll i;
    for(i=0;i<n;i++)
        cin>>arr[i].fi;
    for(i=0;i<n;i++)
        cin>>arr[i].sec;
    ll low = 0,high = 1e18;
    ll ans = -1;
    while(low<=high)
    {
        ll mid = (low+high)/2;
        lol.clear();
        for(i=0;i<n;i++){
        lol.insert(mp(arr[i].fi/arr[i].sec,i));
        }
        if(func(mid))
            ans = mid,high = mid-1;
        else
            low = mid+1;
    }
    cout<<ans;
}


#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
typedef long long ll;
typedef long double  ld;
#define pii pair<ll,ll>
#define pic pair<ll,char>
#define vi vector< ll >
#define vvi vector< vi >
#define vpi vector< pii >
#define vvpi vector< vpi >
#define st  set <ll, greater <ll> >
#define mst  multiset <ll, greater <ll> >
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mapp  unordered_map <ll, ll>
#define ppii pair< pii, pii >
#define test(t) ll t;cin>>t;while(t--)
#define inarr(n) ll arr[n];for(ll i=0;i<n;i++)cin>>arr[i];
#define ingra(m) vvi arr(100005);for(ll i=0;i<m;i++){ll u,v;cin>>u>>v;arr[u].pb(v);arr[v].pb(u);}
#define mem(a,b) memset(a,b,sizeof(a))
#define inn freopen("input.txt", "r", stdin)
#define outt freopen("output.txt", "w", stdout)
#define all(arr) arr.begin(),arr.end()
ll power(ll x,ll y){ll res = 1;while(y){if(y&1) res = (res*x)%mod;y=y/2,x=(x*x)%mod;}return res%mod;}
ll n,k;
pair<  ll ,ll > arr[200001];
set < pair < ll , ll > > lol;
bool func(ll x)
{
    ll cnt = 1;
    ll haha[n];
    for(ll i=0;i<n;i++)
        haha[i] = arr[i].fi;
    while(cnt<=k and !lol.empty())
    {
        pii temp= *lol.begin();
        if(temp.fi>=k-1)
            return 1;
        if(temp.fi<cnt-1)
            return 0;
        lol.erase(lol.begin());
        haha[temp.sec]+=x;
        if(haha[temp.sec]<(k)*arr[temp.sec].sec)
            lol.insert(mp(haha[temp.sec]/arr[temp.sec].sec,temp.sec));
        cnt++;
    }
    return true;
}
signed main()
{
    fast;
    cin>>n>>k;
    ll i;
    for(i=0;i<n;i++)
        cin>>arr[i].fi;
    for(i=0;i<n;i++)
        cin>>arr[i].sec;
    ll low = 0,high = 1e12;
    ll ans = -1;
    while(low<=high)
    {
        ll mid = (low+high)/2;
        lol.clear();
        for(i=0;i<n;i++){
        lol.insert(mp(arr[i].fi/arr[i].sec,i));
        }
        if(func(mid))
            ans = mid,high = mid-1;
        else
            low = mid+1;
    }
    cout<<ans;
}


#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
typedef long long ll;
typedef long double  ld;
#define pii pair<ll,ll>
#define pic pair<ll,char>
#define vi vector< ll >
#define vvi vector< vi >
#define vpi vector< pii >
#define vvpi vector< vpi >
#define st  set <ll, greater <ll> >
#define mst  multiset <ll, greater <ll> >
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mapp  unordered_map <ll, ll>
#define ppii pair< pii, pii >
#define test(t) ll t;cin>>t;while(t--)
#define inarr(n) ll arr[n];for(ll i=0;i<n;i++)cin>>arr[i];
#define ingra(m) vvi arr(100005);for(ll i=0;i<m;i++){ll u,v;cin>>u>>v;arr[u].pb(v);arr[v].pb(u);}
#define mem(a,b) memset(a,b,sizeof(a))
#define inn freopen("input.txt", "r", stdin)
#define outt freopen("output.txt", "w", stdout)
#define all(arr) arr.begin(),arr.end()
ll power(ll x,ll y){ll res = 1;while(y){if(y&1) res = (res*x)%mod;y=y/2,x=(x*x)%mod;}return res%mod;}
ll n,k;
pair<  ll ,ll > arr[200001];
set < pair < ll , ll > > lol;
bool func(ll x)
{
    ll cnt = 1;
    ll haha[n];
    for(ll i=0;i<n;i++)
        haha[i] = arr[i].fi;
    while(cnt<=k and !lol.empty())
    {
        pii temp= *lol.begin();
        if(temp.fi>=k-1)
            return 1;
        if(temp.fi<cnt-1)
            return 0;
        lol.erase(lol.begin());
        haha[temp.sec]+=x;
        if((haha[temp.sec])<(cnt*arr[temp.sec].sec))
            return false;
        if(haha[temp.sec]<(k)*arr[temp.sec].sec)
            lol.insert(mp(haha[temp.sec]/arr[temp.sec].sec,temp.sec));
        cnt++;
    }
    return true;
}
signed main()
{
    fast;
    cin>>n>>k;
    ll i;
    for(i=0;i<n;i++)
        cin>>arr[i].fi;
    for(i=0;i<n;i++)
        cin>>arr[i].sec;
    ll low = 0,high = 1e18;
    ll ans = -1;
    while(low<=high)
    {
        ll mid = (low+high)/2;
        lol.clear();
        for(i=0;i<n;i++){
        lol.insert(mp(arr[i].fi/arr[i].sec,i));
        }
        if(func(mid))
            ans = mid,high = mid-1;
        else
            low = mid+1;
    }
    cout<<ans;
}


#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
typedef long long ll;
typedef long double  ld;
#define pii pair<ll,ll>
#define pic pair<ll,char>
#define vi vector< ll >
#define vvi vector< vi >
#define vpi vector< pii >
#define vvpi vector< vpi >
#define st  set <ll, greater <ll> >
#define mst  multiset <ll, greater <ll> >
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mapp  unordered_map <ll, ll>
#define ppii pair< pii, pii >
#define test(t) ll t;cin>>t;while(t--)
#define inarr(n) ll arr[n];for(ll i=0;i<n;i++)cin>>arr[i];
#define ingra(m) vvi arr(100005);for(ll i=0;i<m;i++){ll u,v;cin>>u>>v;arr[u].pb(v);arr[v].pb(u);}
#define mem(a,b) memset(a,b,sizeof(a))
#define inn freopen("input.txt", "r", stdin)
#define outt freopen("output.txt", "w", stdout)
#define all(arr) arr.begin(),arr.end()
ll power(ll x,ll y){ll res = 1;while(y){if(y&1) res = (res*x)%mod;y=y/2,x=(x*x)%mod;}return res%mod;}
ll n,k;
pair<  ll ,ll > arr[200001];
priority_queue<pair<ll, ll>, vector<pair<ll, ll> >, greater<pair<ll, ll> > > lol;
bool func(ll x)
{
    ll cnt = 0;
    ll haha[n];
    for(ll i=0;i<n;i++)
        haha[i] = arr[i].fi;
    while(cnt<k and !lol.empty())
    {
        pii temp= lol.top();
        if(temp.fi>=k-1)
            return 1;
        if(temp.fi<cnt)
            return 0;
        lol.pop();
        // haha[temp.sec]+=x;
        haha[temp.sec] = min(haha[temp.sec]+x,1000000000000000LL);
        if(haha[temp.sec]<=(k)*arr[temp.sec].sec)
            lol.push(mp(haha[temp.sec]/arr[temp.sec].sec,temp.sec));
        cnt++;
    }
    return true;
}
signed main()
{
    fast;
    cin>>n>>k;
    ll i;
    for(i=0;i<n;i++)
        cin>>arr[i].fi;
    for(i=0;i<n;i++)
        cin>>arr[i].sec;
    ll low = 0,high = 2e12;
    ll ans = -1;
    while(low<=high)
    {
        ll mid = (low+high)/2;
        for(i=0;i<n;i++){
        lol.push(mp(arr[i].fi/arr[i].sec,i));
        }
        if(func(mid))
            ans = mid,high = mid-1;
        else
            low = mid+1;
        while(!lol.empty())
            lol.pop();
    }
    cout<<ans;
}


#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
typedef long long ll;
typedef long double  ld;
#define pii pair<ll,ll>
#define pic pair<ll,char>
#define vi vector< ll >
#define vvi vector< vi >
#define vpi vector< pii >
#define vvpi vector< vpi >
#define st  set <ll, greater <ll> >
#define mst  multiset <ll, greater <ll> >
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mapp  unordered_map <ll, ll>
#define ppii pair< pii, pii >
#define test(t) ll t;cin>>t;while(t--)
#define inarr(n) ll arr[n];for(ll i=0;i<n;i++)cin>>arr[i];
#define ingra(m) vvi arr(100005);for(ll i=0;i<m;i++){ll u,v;cin>>u>>v;arr[u].pb(v);arr[v].pb(u);}
#define mem(a,b) memset(a,b,sizeof(a))
#define inn freopen("input.txt", "r", stdin)
#define outt freopen("output.txt", "w", stdout)
#define all(arr) arr.begin(),arr.end()
ll power(ll x,ll y){ll res = 1;while(y){if(y&1) res = (res*x)%mod;y=y/2,x=(x*x)%mod;}return res%mod;}
ll n,k;
pair<  ll ,ll > arr[200001];
set < pair < ll , ll > > lol;
bool func(ll x)
{
    ll cnt = 1;
    ll haha[n];
    for(ll i=0;i<n;i++)
        haha[i] = arr[i].fi;
    while(cnt<=k-1 and !lol.empty())
    {
        pii temp= *lol.begin();
        lol.erase(lol.begin());
        haha[temp.sec]+=x;
        if((haha[temp.sec])<(cnt*arr[temp.sec].sec))
            return false;
        if(lol.empty()==false)
        {
            pii soch = *lol.begin();
            if(haha[soch.sec]<(cnt*arr[soch.sec].sec))
                return false;
        }
        if(haha[temp.sec]<(k-cnt)*arr[temp.sec].sec)
            lol.insert(mp(haha[temp.sec]/arr[temp.sec].sec,temp.sec));
        cnt++;
    }
    return true;
}
signed main()
{
    fast;
    cin>>n>>k;
    ll i;
    for(i=0;i<n;i++)
        cin>>arr[i].fi;
    for(i=0;i<n;i++)
        cin>>arr[i].sec;
    ll low = 0,high = 1e18;
    ll ans = -1;
    while(low<=high)
    {
        ll mid = (low+high)/2;
        lol.clear();
        for(i=0;i<n;i++){
        lol.insert(mp(arr[i].fi/arr[i].sec,i));
        }
        if(func(mid))
            ans = mid,high = mid-1;
        else
            low = mid+1;
    }
    cout<<ans;
}


#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
typedef long long ll;
typedef long double  ld;
#define pii pair<ll,ll>
#define pic pair<ll,char>
#define vi vector< ll >
#define vvi vector< vi >
#define vpi vector< pii >
#define vvpi vector< vpi >
#define st  set <ll, greater <ll> >
#define mst  multiset <ll, greater <ll> >
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mapp  unordered_map <ll, ll>
#define ppii pair< pii, pii >
#define test(t) ll t;cin>>t;while(t--)
#define inarr(n) ll arr[n];for(ll i=0;i<n;i++)cin>>arr[i];
#define ingra(m) vvi arr(100005);for(ll i=0;i<m;i++){ll u,v;cin>>u>>v;arr[u].pb(v);arr[v].pb(u);}
#define mem(a,b) memset(a,b,sizeof(a))
#define inn freopen("input.txt", "r", stdin)
#define outt freopen("output.txt", "w", stdout)
#define all(arr) arr.begin(),arr.end()
ll power(ll x,ll y){ll res = 1;while(y){if(y&1) res = (res*x)%mod;y=y/2,x=(x*x)%mod;}return res%mod;}
ll n,k;
pair<  ll ,ll > arr[200001];
priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > > lol;
bool func(ll x)
{
    ll cnt = 0;
    ll haha[n];
    for(ll i=0;i<n;i++)
        haha[i] = arr[i].fi;
    while(cnt<k and !lol.empty())
    {
        pii temp= lol.top();
        if(temp.fi>=k-1)
            return 1;
        if(temp.fi<cnt)
            return 0;
        lol.pop();
        haha[temp.sec]+=x;
        // if(haha[temp.sec]<=(k-1)*arr[temp.sec].sec)
            lol.push(mp(haha[temp.sec]/arr[temp.sec].sec,temp.sec));
        cnt++;
    }
    return true;
}
signed main()
{
    fast;
    cin>>n>>k;
    ll i;
    for(i=0;i<n;i++)
        cin>>arr[i].fi;
    for(i=0;i<n;i++)
        cin>>arr[i].sec;
    ll low = 0,high = 2e12;
    ll ans = -1;
    while(low<=high)
    {
        ll mid = (low+high)/2;
        for(i=0;i<n;i++){
        lol.push(mp(arr[i].fi/arr[i].sec,i));
        }
        if(func(mid))
            ans = mid,high = mid-1;
        else
            low = mid+1;
        while(!lol.empty())
            lol.pop();
    }
    cout<<ans;
}


#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
typedef long long ll;
typedef long double  ld;
#define pii pair<ll,ll>
#define pic pair<ll,char>
#define vi vector< ll >
#define vvi vector< vi >
#define vpi vector< pii >
#define vvpi vector< vpi >
#define st  set <ll, greater <ll> >
#define mst  multiset <ll, greater <ll> >
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mapp  unordered_map <ll, ll>
#define ppii pair< pii, pii >
#define test(t) ll t;cin>>t;while(t--)
#define inarr(n) ll arr[n];for(ll i=0;i<n;i++)cin>>arr[i];
#define ingra(m) vvi arr(100005);for(ll i=0;i<m;i++){ll u,v;cin>>u>>v;arr[u].pb(v);arr[v].pb(u);}
#define mem(a,b) memset(a,b,sizeof(a))
#define inn freopen("input.txt", "r", stdin)
#define outt freopen("output.txt", "w", stdout)
#define all(arr) arr.begin(),arr.end()
ll power(ll x,ll y){ll res = 1;while(y){if(y&1) res = (res*x)%mod;y=y/2,x=(x*x)%mod;}return res%mod;}
ll n,k;
pair<  ll ,ll > arr[200001];
priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > > lol;
bool func(ll x)
{
    ll cnt = 1;
    ll haha[n];
    for(ll i=0;i<n;i++)
        haha[i] = arr[i].fi;
    while(cnt<=k and !lol.empty())
    {
        pii temp= lol.top();
        if(temp.fi>=k)
            return 1;
        if(temp.fi<cnt-1)
            return 0;
        lol.pop();
        haha[temp.sec]+=x;
        if(haha[temp.sec]<(k+1)*arr[temp.sec].sec)
            lol.push(mp(haha[temp.sec]/arr[temp.sec].sec,temp.sec));
        cnt++;
    }
    return true;
}
signed main()
{
    fast;
    cin>>n>>k;
    ll i;
    for(i=0;i<n;i++)
        cin>>arr[i].fi;
    for(i=0;i<n;i++)
        cin>>arr[i].sec;
    ll low = 0,high = 1e14;
    ll ans = -1;
    while(low<=high)
    {
        ll mid = (low+high)/2;
        for(i=0;i<n;i++){
        lol.push(mp(arr[i].fi/arr[i].sec,i));
        }
        if(func(mid))
            ans = mid,high = mid-1;
        else
            low = mid+1;
        while(!lol.empty())
            lol.pop();
    }
    cout<<ans;
}


#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
typedef long long ll;
typedef long double  ld;
#define pii pair<ll,ll>
#define pic pair<ll,char>
#define vi vector< ll >
#define vvi vector< vi >
#define vpi vector< pii >
#define vvpi vector< vpi >
#define st  set <ll, greater <ll> >
#define mst  multiset <ll, greater <ll> >
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mapp  unordered_map <ll, ll>
#define ppii pair< pii, pii >
#define test(t) ll t;cin>>t;while(t--)
#define inarr(n) ll arr[n];for(ll i=0;i<n;i++)cin>>arr[i];
#define ingra(m) vvi arr(100005);for(ll i=0;i<m;i++){ll u,v;cin>>u>>v;arr[u].pb(v);arr[v].pb(u);}
#define mem(a,b) memset(a,b,sizeof(a))
#define inn freopen("input.txt", "r", stdin)
#define outt freopen("output.txt", "w", stdout)
#define all(arr) arr.begin(),arr.end()
ll power(ll x,ll y){ll res = 1;while(y){if(y&1) res = (res*x)%mod;y=y/2,x=(x*x)%mod;}return res%mod;}
ll n,k;
pair<  ll ,ll > arr[200001];
priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > > lol;
bool func(ll x)
{
    ll cnt = 0;
    ll haha[n];
    for(ll i=0;i<n;i++)
        haha[i] = arr[i].fi;
    while(cnt<k and !lol.empty())
    {
        pii temp= lol.top();
        if(temp.fi>=k-1)
            return 1;
        if(temp.fi<cnt)
            return 0;
        lol.pop();
        haha[temp.sec]+=x;
        if(haha[temp.sec]<=(k-1)*arr[temp.sec].sec)
            lol.push(mp(haha[temp.sec]/arr[temp.sec].sec,temp.sec));
        cnt++;
    }
    return true;
}
signed main()
{
    fast;
    cin>>n>>k;
    ll i;
    for(i=0;i<n;i++)
        cin>>arr[i].fi;
    for(i=0;i<n;i++)
        cin>>arr[i].sec;
    ll low = 0,high = 2e12;
    ll ans = -1;
    while(low<=high)
    {
        ll mid = (low+high)/2;
        for(i=0;i<n;i++){
        lol.push(mp(arr[i].fi/arr[i].sec,i));
        }
        if(func(mid))
            ans = mid,high = mid-1;
        else
            low = mid+1;
        while(!lol.empty())
            lol.pop();
    }
    cout<<ans;
}


#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
typedef long long ll;
typedef long double  ld;
#define pii pair<ll,ll>
#define pic pair<ll,char>
#define vi vector< ll >
#define vvi vector< vi >
#define vpi vector< pii >
#define vvpi vector< vpi >
#define st  set <ll, greater <ll> >
#define mst  multiset <ll, greater <ll> >
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mapp  unordered_map <ll, ll>
#define ppii pair< pii, pii >
#define test(t) ll t;cin>>t;while(t--)
#define inarr(n) ll arr[n];for(ll i=0;i<n;i++)cin>>arr[i];
#define ingra(m) vvi arr(100005);for(ll i=0;i<m;i++){ll u,v;cin>>u>>v;arr[u].pb(v);arr[v].pb(u);}
#define mem(a,b) memset(a,b,sizeof(a))
#define inn freopen("input.txt", "r", stdin)
#define outt freopen("output.txt", "w", stdout)
#define all(arr) arr.begin(),arr.end()
ll power(ll x,ll y){ll res = 1;while(y){if(y&1) res = (res*x)%mod;y=y/2,x=(x*x)%mod;}return res%mod;}
ll n,k;
pair<  ll ,ll > arr[200001];
priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > > lol;
bool func(ll x)
{
    ll cnt = 1;
    ll haha[n];
    for(ll i=0;i<n;i++)
        haha[i] = arr[i].fi;
    while(cnt<=k and !lol.empty())
    {
        pii temp= lol.top();
        if(temp.fi>=k)
            return 1;
        lol.pop();
        haha[temp.sec]+=x;
        if(haha[temp.sec]<cnt*arr[temp.sec].sec)
            return false;
        if(haha[temp.sec]<(k+1)*arr[temp.sec].sec)
            lol.push(mp(haha[temp.sec]/arr[temp.sec].sec,temp.sec));
        cnt++;
    }
    return true;
}
signed main()
{
    fast;
    cin>>n>>k;
    ll i;
    for(i=0;i<n;i++)
        cin>>arr[i].fi;
    for(i=0;i<n;i++)
        cin>>arr[i].sec;
    ll low = 0,high = 1e14;
    ll ans = -1;
    while(low<=high)
    {
        ll mid = (low+high)/2;
        for(i=0;i<n;i++){
        lol.push(mp(arr[i].fi/arr[i].sec,i));
        }
        if(func(mid))
            ans = mid,high = mid-1;
        else
            low = mid+1;
        while(!lol.empty())
            lol.pop();
    }
    cout<<ans;
}


#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
typedef long long ll;
typedef long double  ld;
#define pii pair<ll,ll>
#define pic pair<ll,char>
#define vi vector< ll >
#define vvi vector< vi >
#define vpi vector< pii >
#define vvpi vector< vpi >
#define st  set <ll, greater <ll> >
#define mst  multiset <ll, greater <ll> >
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mapp  unordered_map <ll, ll>
#define ppii pair< pii, pii >
#define test(t) ll t;cin>>t;while(t--)
#define inarr(n) ll arr[n];for(ll i=0;i<n;i++)cin>>arr[i];
#define ingra(m) vvi arr(100005);for(ll i=0;i<m;i++){ll u,v;cin>>u>>v;arr[u].pb(v);arr[v].pb(u);}
#define mem(a,b) memset(a,b,sizeof(a))
#define inn freopen("input.txt", "r", stdin)
#define outt freopen("output.txt", "w", stdout)
#define all(arr) arr.begin(),arr.end()
ll power(ll x,ll y){ll res = 1;while(y){if(y&1) res = (res*x)%mod;y=y/2,x=(x*x)%mod;}return res%mod;}
ll n,k;
pair<  ll ,ll > arr[200001];
priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > > lol;
bool func(ll x)
{
    ll cnt = 0;
    ll haha[n];
    for(ll i=0;i<n;i++)
        haha[i] = arr[i].fi;
    while(cnt<k and !lol.empty())
    {
        pii temp= lol.top();
        if(temp.fi>=k-1)
            return 1;
        if(temp.fi<cnt)
            return 0;
        lol.pop();
        // haha[temp.sec]+=x;
        haha[temp.sec] = min(haha[temp.sec]+x,1000000000000000LL);
        if(haha[temp.sec]<=(k)*arr[temp.sec].sec)
            lol.push(mp(haha[temp.sec]/arr[temp.sec].sec,temp.sec));
        cnt++;
    }
    return true;
}
signed main()
{
    fast;
    cin>>n>>k;
    ll i;
    for(i=0;i<n;i++)
        cin>>arr[i].fi;
    for(i=0;i<n;i++)
        cin>>arr[i].sec;
    ll low = 0,high = 2e12;
    ll ans = -1;
    while(low<=high)
    {
        ll mid = (low+high)/2;
        for(i=0;i<n;i++){
        lol.push(mp(arr[i].fi/arr[i].sec,i));
        }
        if(func(mid))
            ans = mid,high = mid-1;
        else
            low = mid+1;
        while(!lol.empty())
            lol.pop();
    }
    cout<<ans;
}


#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
typedef long long ll;
typedef long double  ld;
#define pii pair<ll,ll>
#define pic pair<ll,char>
#define vi vector< ll >
#define vvi vector< vi >
#define vpi vector< pii >
#define vvpi vector< vpi >
#define st  set <ll, greater <ll> >
#define mst  multiset <ll, greater <ll> >
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mapp  unordered_map <ll, ll>
#define ppii pair< pii, pii >
#define test(t) ll t;cin>>t;while(t--)
#define inarr(n) ll arr[n];for(ll i=0;i<n;i++)cin>>arr[i];
#define ingra(m) vvi arr(100005);for(ll i=0;i<m;i++){ll u,v;cin>>u>>v;arr[u].pb(v);arr[v].pb(u);}
#define mem(a,b) memset(a,b,sizeof(a))
#define inn freopen("input.txt", "r", stdin)
#define outt freopen("output.txt", "w", stdout)
#define all(arr) arr.begin(),arr.end()
ll power(ll x,ll y){ll res = 1;while(y){if(y&1) res = (res*x)%mod;y=y/2,x=(x*x)%mod;}return res%mod;}
ll n,k;
pair<  ll ,ll > arr[200001];
set < pair < ll , ll > > lol;
bool func(ll x)
{
    ll cnt = 1;
    ll haha[n];
    for(ll i=0;i<n;i++)
        haha[i] = arr[i].fi;
    while(cnt<=k-1 and !lol.empty())
    {
        pii temp= *lol.begin();
        lol.erase(lol.begin());
        haha[temp.sec]+=x;
        // cout<<temp.fi<<" "<<temp.sec<<endl;
        if((haha[temp.sec])<(cnt*arr[temp.sec].sec))
            return false;
        if(lol.empty()==false)
        {
            pii soch = *lol.begin();
            if(haha[soch.sec]<(cnt*arr[soch.sec].sec))
                return false;
        }
        if(haha[temp.sec]<k*arr[temp.sec].sec)
            lol.insert(mp(haha[temp.sec]/arr[temp.sec].sec,temp.sec));
        cnt++;
    }
    return true;
}
signed main()
{
    fast;
    cin>>n>>k;
    ll i;
    for(i=0;i<n;i++)
        cin>>arr[i].fi;
    for(i=0;i<n;i++)
        cin>>arr[i].sec;
    ll low = 0,high = 1e18;
    ll ans = -1;
    while(low<=high)
    {
        ll mid = (low+high)/2;
        lol.clear();
        for(i=0;i<n;i++){
        lol.insert(mp(arr[i].fi/arr[i].sec,i));
        }
        if(func(mid))
            ans = mid,high = mid-1;
        else
            low = mid+1;
    }
    cout<<ans;
}


#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
typedef long long ll;
typedef long double  ld;
#define pii pair<ll,ll>
#define pic pair<ll,char>
#define vi vector< ll >
#define vvi vector< vi >
#define vpi vector< pii >
#define vvpi vector< vpi >
#define st  set <ll, greater <ll> >
#define mst  multiset <ll, greater <ll> >
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mapp  unordered_map <ll, ll>
#define ppii pair< pii, pii >
#define test(t) ll t;cin>>t;while(t--)
#define inarr(n) ll arr[n];for(ll i=0;i<n;i++)cin>>arr[i];
#define ingra(m) vvi arr(100005);for(ll i=0;i<m;i++){ll u,v;cin>>u>>v;arr[u].pb(v);arr[v].pb(u);}
#define mem(a,b) memset(a,b,sizeof(a))
#define inn freopen("input.txt", "r", stdin)
#define outt freopen("output.txt", "w", stdout)
#define all(arr) arr.begin(),arr.end()
ll power(ll x,ll y){ll res = 1;while(y){if(y&1) res = (res*x)%mod;y=y/2,x=(x*x)%mod;}return res%mod;}
ll n,k;
pair<  ll ,ll > arr[200001];
set < pair < ll , ll > > lol;
bool func(ll x)
{
    ll cnt = 1;
    ll haha[n];
    for(ll i=0;i<n;i++)
        haha[i] = arr[i].fi;
    while(cnt<=k-1 and !lol.empty())
    {
        pii temp= *lol.begin();
        lol.erase(lol.begin());
        haha[temp.sec]+=x;
        if((haha[temp.sec])<(cnt*arr[temp.sec].sec))
            return false;
        if(lol.empty()==false)
        {
            pii soch = *lol.begin();
            if(haha[soch.sec]<(cnt*arr[soch.sec].sec))
                return false;
        }
        if(haha[temp.sec]<(k-cnt+1)*arr[temp.sec].sec)
            lol.insert(mp(haha[temp.sec]/arr[temp.sec].sec,temp.sec));
        cnt++;
    }
    return true;
}
signed main()
{
    fast;
    cin>>n>>k;
    ll i;
    for(i=0;i<n;i++)
        cin>>arr[i].fi;
    for(i=0;i<n;i++)
        cin>>arr[i].sec;
    ll low = 0,high = 1e18;
    ll ans = -1;
    while(low<=high)
    {
        ll mid = (low+high)/2;
        lol.clear();
        for(i=0;i<n;i++){
        lol.insert(mp(arr[i].fi/arr[i].sec,i));
        }
        if(func(mid))
            ans = mid,high = mid-1;
        else
            low = mid+1;
    }
    cout<<ans;
}


#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
typedef long long ll;
typedef long double  ld;
#define pii pair<ll,ll>
#define pic pair<ll,char>
#define vi vector< ll >
#define vvi vector< vi >
#define vpi vector< pii >
#define vvpi vector< vpi >
#define st  set <ll, greater <ll> >
#define mst  multiset <ll, greater <ll> >
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mapp  unordered_map <ll, ll>
#define ppii pair< pii, pii >
#define test(t) ll t;cin>>t;while(t--)
#define inarr(n) ll arr[n];for(ll i=0;i<n;i++)cin>>arr[i];
#define ingra(m) vvi arr(100005);for(ll i=0;i<m;i++){ll u,v;cin>>u>>v;arr[u].pb(v);arr[v].pb(u);}
#define mem(a,b) memset(a,b,sizeof(a))
#define inn freopen("input.txt", "r", stdin)
#define outt freopen("output.txt", "w", stdout)
#define all(arr) arr.begin(),arr.end()
ll power(ll x,ll y){ll res = 1;while(y){if(y&1) res = (res*x)%mod;y=y/2,x=(x*x)%mod;}return res%mod;}
ll n,k;
pair<  ll ,ll > arr[200001];
set < pair < ll , ll > > lol;
bool func(ll x)
{
    ll cnt = 1;
    ll haha[n];
    for(ll i=0;i<n;i++)
        haha[i] = arr[i].fi;
    while(cnt<=k-1 and !lol.empty())
    {
        pii temp= *lol.begin();
        if(temp.fi>=k-1)
            return 1;
        if(temp.fi<cnt-1)
            return 0;
        lol.erase(lol.begin());
        haha[temp.sec]+=x;
        if((haha[temp.sec])<(cnt*arr[temp.sec].sec))
            return false;
        if(haha[temp.sec]<(k)*arr[temp.sec].sec)
            lol.insert(mp(haha[temp.sec]/arr[temp.sec].sec,temp.sec));
        cnt++;
    }
    return true;
}
signed main()
{
    fast;
    cin>>n>>k;
    ll i;
    for(i=0;i<n;i++)
        cin>>arr[i].fi;
    for(i=0;i<n;i++)
        cin>>arr[i].sec;
    ll low = 0,high = 1e18;
    ll ans = -1;
    while(low<=high)
    {
        ll mid = (low+high)/2;
        lol.clear();
        for(i=0;i<n;i++){
        lol.insert(mp(arr[i].fi/arr[i].sec,i));
        }
        if(func(mid))
            ans = mid,high = mid-1;
        else
            low = mid+1;
    }
    cout<<ans;
}


#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
typedef long long ll;
typedef long double  ld;
#define pii pair<ll,ll>
#define pic pair<ll,char>
#define vi vector< ll >
#define vvi vector< vi >
#define vpi vector< pii >
#define vvpi vector< vpi >
#define st  set <ll, greater <ll> >
#define mst  multiset <ll, greater <ll> >
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mapp  unordered_map <ll, ll>
#define ppii pair< pii, pii >
#define test(t) ll t;cin>>t;while(t--)
#define inarr(n) ll arr[n];for(ll i=0;i<n;i++)cin>>arr[i];
#define ingra(m) vvi arr(100005);for(ll i=0;i<m;i++){ll u,v;cin>>u>>v;arr[u].pb(v);arr[v].pb(u);}
#define mem(a,b) memset(a,b,sizeof(a))
#define inn freopen("input.txt", "r", stdin)
#define outt freopen("output.txt", "w", stdout)
#define all(arr) arr.begin(),arr.end()
ll power(ll x,ll y){ll res = 1;while(y){if(y&1) res = (res*x)%mod;y=y/2,x=(x*x)%mod;}return res%mod;}
ll n,k;
pair<  ll ,ll > arr[200001];
priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > > lol;
bool func(ll x)
{
    ll cnt = 1;
    ll haha[n];
    for(ll i=0;i<n;i++)
        haha[i] = arr[i].fi;
    while(cnt<=k and !lol.empty())
    {
        pii temp= lol.top();
        if(temp.fi>=k-1)
            return 1;
        if(temp.fi<cnt-1)
            return 0;
        lol.pop();
        haha[temp.sec]+=x;
        if(haha[temp.sec]<(k)*arr[temp.sec].sec)
            lol.push(mp(haha[temp.sec]/arr[temp.sec].sec,temp.sec));
        cnt++;
    }
    return true;
}
signed main()
{
    fast;
    cin>>n>>k;
    ll i;
    for(i=0;i<n;i++)
        cin>>arr[i].fi;
    for(i=0;i<n;i++)
        cin>>arr[i].sec;
    ll low = 0,high = 1e14;
    ll ans = -1;
    while(low<=high)
    {
        ll mid = (low+high)/2;
        for(i=0;i<n;i++){
        lol.push(mp(arr[i].fi/arr[i].sec,i));
        }
        if(func(mid))
            ans = mid,high = mid-1;
        else
            low = mid+1;
        while(!lol.empty())
            lol.pop();
    }
    cout<<ans;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long LL;

const int N = 2e5 + 10;
const LL INFL = 1e9;

typedef pair <LL, LL> PLL;

int n, m;
int b[N];

LL a[N], c[N];

struct State {
	LL minute, needed, idx;
	State () {}
	State (LL minute, LL needed, LL idx) : minute(minute), needed(needed), idx(idx) {}
	bool operator < (const State &that) const {
		if (minute != that.minute) return minute < that.minute;
		if (needed != that.needed) return needed > that.needed;
		return idx < that.idx;
	}
};

bool Check(LL charge) {
	set <State> S;
	for (int i = 1; i <= n; ++i) c[i] = a[i];
	for (int i = 1; i <= n; ++i) {
		LL q = c[i] / b[i], r = c[i] % b[i];
		S.insert(State(q, b[i] - r, i));
	}
	for (int i = 1; i <= m; ++i) {
		LL minute = S.begin() -> minute, needed = S.begin() -> needed, idx = S.begin() -> idx;
		S.erase(S.begin());
		if (minute < (i - 1)) return false;
		c[idx] += charge;
		LL q = c[idx] / b[idx], r = c[idx] % b[idx];
		S.insert(State(q, b[idx] - r, idx));
	}
	return true;
}

int main() {
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; ++i) scanf("%lld", &a[i]);
	for (int i = 1; i <= n; ++i) scanf("%d", &b[i]);
	LL l = 0, r = INFL, f = -1;
	while (l <= r) {
		LL m = (l + r) >> 1;
		if (Check(m)) {
			f = m;
			r = m - 1;
		} else l = m + 1;
	}
	printf("%lld\n", f);
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long LL;

const int N = 2e5 + 10;
const LL INFL = 5e8;

typedef pair <LL, LL> PLL;

int n, m;
int b[N];

LL a[N], c[N];

struct State {
	LL minute, needed, idx;
	State () {}
	State (LL minute, LL needed, LL idx) : minute(minute), needed(needed), idx(idx) {}
	bool operator < (const State &that) const {
		if (minute != that.minute) return minute < that.minute;
		if (needed != that.needed) return needed > that.needed;
		return idx < that.idx;
	}
};

bool Check(LL charge) {
	set <State> S;
	for (int i = 1; i <= n; ++i) c[i] = a[i];
	for (int i = 1; i <= n; ++i) {
		LL q = c[i] / b[i], r = c[i] % b[i];
		if (q >= m - 1) continue;
		S.insert(State(q, b[i] - r, i));
	}
	for (int i = 1; i <= m; ++i) {
		if (S.size() == 0) return true;
		LL minute = S.begin() -> minute, needed = S.begin() -> needed, idx = S.begin() -> idx;
		S.erase(S.begin());
		if (minute < (i - 1)) return false;
		c[idx] += charge;
		LL q = c[idx] / b[idx], r = c[idx] % b[idx];
		if (q < (m - 1)) S.insert(State(q, b[idx] - r, idx));
	}
	return true;
}

int main() {
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; ++i) scanf("%lld", &a[i]);
	for (int i = 1; i <= n; ++i) scanf("%d", &b[i]);
	LL l = 0, r = INFL, f = -1;
	while (l <= r) {
		LL m = (l + r) >> 1;
		if (Check(m)) {
			f = m;
			r = m - 1;
		} else l = m + 1;
	}
	printf("%lld\n", f);
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long LL;

const int N = 2e5 + 10;
const LL INFL = 2e12 + 10;

typedef pair <LL, LL> PLL;

int n, m;
int b[N];

LL a[N], c[N];

struct State {
	int minute, needed, idx;
	State () {}
	State (int minute, int needed, int idx) : minute(minute), needed(needed), idx(idx) {}
	bool operator < (const State &that) const {
		if (minute != that.minute) return minute < that.minute;
		if (needed != that.needed) return needed > that.needed;
		return idx < that.idx;
	}
};

bool Check(LL charge) {
	set <State> S;
	for (int i = 1; i <= n; ++i) c[i] = a[i];
	for (int i = 1; i <= n; ++i) {
		LL q = c[i] / b[i], r = c[i] % b[i];
		if (q >= m - 1) continue;
		S.insert(State(q, b[i] - r, i));
	}
	for (int i = 1; i <= m; ++i) {
		if (S.size() == 0) return true;
		int minute = S.begin() -> minute, needed = S.begin() -> needed, idx = S.begin() -> idx;
		S.erase(S.begin());
		if (minute < (i - 1)) return false;
		c[idx] += charge;
		LL q = c[idx] / b[idx], r = c[idx] % b[idx];
		if (q < (m - 1)) S.insert(State(q, b[idx] - r, idx));
	}
	return true;
}

int main() {
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; ++i) scanf("%lld", &a[i]);
	for (int i = 1; i <= n; ++i) scanf("%d", &b[i]);
	LL l = 0, r = INFL, f = -1;
	while (l <= r) {
		LL m = (l + r) >> 1;
		if (Check(m)) {
			f = m;
			r = m - 1;
		} else l = m + 1;
	}
	printf("%lld\n", f);
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long LL;

const int N = 2e5 + 10;
const LL INFL = 2e12 + 10;

typedef pair <LL, LL> PLL;

int n, m;
int b[N];

LL a[N], c[N];

struct State {
	int minute, needed, idx;
	State () {}
	State (int minute, int needed, int idx) : minute(minute), needed(needed), idx(idx) {}
	bool operator < (const State &that) const {
		if (minute != that.minute) return minute > that.minute;
		if (needed != that.needed) return needed < that.needed;
		return idx < that.idx;
	}
};

bool Check(LL charge) {
	priority_queue <State> pq;
	for (int i = 1; i <= n; ++i) c[i] = a[i];
	for (int i = 1; i <= n; ++i) {
		LL q = c[i] / b[i], r = c[i] % b[i];
		if (q >= m - 1) continue;
		pq.push(State(q, b[i] - r, i));
	}
	for (int i = 1; i <= m; ++i) {
		if (pq.size() == 0) return true;
		int minute = pq.top().minute, needed = pq.top().needed, idx = pq.top().idx;
		pq.pop();
		if (minute < (i - 1)) return false;
		c[idx] += charge;
		LL q = c[idx] / b[idx], r = c[idx] % b[idx];
		if (q < (m - 1)) pq.push(State(q, b[idx] - r, idx));
	}
	return true;
}

int main() {
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; ++i) scanf("%lld", &a[i]);
	for (int i = 1; i <= n; ++i) scanf("%d", &b[i]);
	LL l = 0, r = INFL, f = -1;
	while (l <= r) {
		LL m = (l + r) >> 1;
		if (Check(m)) {
			f = m;
			r = m - 1;
		} else l = m + 1;
	}
	printf("%lld\n", f);
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long LL;

const int N = 2e5 + 10;
const LL INFL = 1e7;

typedef pair <LL, LL> PLL;

int n, m;
int b[N];

LL a[N], c[N];

struct State {
	LL minute, needed, idx;
	State () {}
	State (LL minute, LL needed, LL idx) : minute(minute), needed(needed), idx(idx) {}
	bool operator < (const State &that) const {
		if (minute != that.minute) return minute < that.minute;
		if (needed != that.needed) return needed > that.needed;
		return idx < that.idx;
	}
};

bool Check(LL charge) {
	set <State> S;
	for (int i = 1; i <= n; ++i) c[i] = a[i];
	for (int i = 1; i <= n; ++i) {
		LL q = c[i] / b[i], r = c[i] % b[i];
		S.insert(State(q, b[i] - r, i));
	}
	for (int i = 1; i <= m; ++i) {
		LL minute = S.begin() -> minute, needed = S.begin() -> needed, idx = S.begin() -> idx;
		S.erase(S.begin());
		if (minute < (i - 1)) return false;
		c[idx] += charge;
		LL q = c[idx] / b[idx], r = c[idx] % b[idx];
		S.insert(State(q, b[idx] - r, idx));
	}
	return true;
}

int main() {
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; ++i) scanf("%lld", &a[i]);
	for (int i = 1; i <= n; ++i) scanf("%d", &b[i]);
	LL l = 0, r = INFL, f = -1;
	while (l <= r) {
		LL m = (l + r) >> 1;
		if (Check(m)) {
			f = m;
			r = m - 1;
		} else l = m + 1;
	}
	printf("%lld\n", f);
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long LL;

const int N = 2e5 + 10;
const LL INFL = 5e8;

typedef pair <LL, LL> PLL;

int n, m;
int b[N];

LL a[N], c[N];

struct State {
	LL minute, needed, idx;
	State () {}
	State (LL minute, LL needed, LL idx) : minute(minute), needed(needed), idx(idx) {}
	bool operator < (const State &that) const {
		if (minute != that.minute) return minute < that.minute;
		if (needed != that.needed) return needed > that.needed;
		return idx < that.idx;
	}
};

bool Check(LL charge) {
	set <State> S;
	for (int i = 1; i <= n; ++i) c[i] = a[i];
	for (int i = 1; i <= n; ++i) {
		LL q = c[i] / b[i], r = c[i] % b[i];
		if (q >= m - 1) continue;
		S.insert(State(q, b[i] - r, i));
	}
	for (int i = 1; i <= m; ++i) {
		LL minute = S.begin() -> minute, needed = S.begin() -> needed, idx = S.begin() -> idx;
		S.erase(S.begin());
		if (minute < (i - 1)) return false;
		c[idx] += charge;
		LL q = c[idx] / b[idx], r = c[idx] % b[idx];
		if (q < (m - 1)) S.insert(State(q, b[idx] - r, idx));
	}
	return true;
}

int main() {
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; ++i) scanf("%lld", &a[i]);
	for (int i = 1; i <= n; ++i) scanf("%d", &b[i]);
	LL l = 0, r = INFL, f = -1;
	while (l <= r) {
		LL m = (l + r) >> 1;
		if (Check(m)) {
			f = m;
			r = m - 1;
		} else l = m + 1;
	}
	printf("%lld\n", f);
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long LL;

const int N = 2e5 + 10;
const LL INFL = 2e12 + 10;

typedef pair <LL, LL> PLL;

int n, m;
int b[N];

LL a[N], c[N];

struct State {
	LL minute, needed, idx;
	State () {}
	State (LL minute, LL needed, LL idx) : minute(minute), needed(needed), idx(idx) {}
	bool operator < (const State &that) const {
		if (minute != that.minute) return minute < that.minute;
		if (needed != that.needed) return needed > that.needed;
		return idx < that.idx;
	}
};

bool Check(LL charge) {
	set <State> S;
	for (int i = 1; i <= n; ++i) c[i] = a[i];
	for (int i = 1; i <= n; ++i) {
		LL q = c[i] / b[i], r = c[i] % b[i];
		if (q >= m - 1) continue;
		S.insert(State(q, b[i] - r, i));
	}
	for (int i = 1; i <= m; ++i) {
		if (S.size() == 0) return true;
		LL minute = S.begin() -> minute, needed = S.begin() -> needed, idx = S.begin() -> idx;
		S.erase(S.begin());
		if (minute < (i - 1)) return false;
		c[idx] += charge;
		LL q = c[idx] / b[idx], r = c[idx] % b[idx];
		if (q < (m - 1)) S.insert(State(q, b[idx] - r, idx));
	}
	return true;
}

int main() {
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; ++i) scanf("%lld", &a[i]);
	for (int i = 1; i <= n; ++i) scanf("%d", &b[i]);
	LL l = 0, r = INFL, f = -1;
	while (l <= r) {
		LL m = (l + r) >> 1;
		if (Check(m)) {
			f = m;
			r = m - 1;
		} else l = m + 1;
	}
	printf("%lld\n", f);
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long LL;

const int N = 2e5 + 10;
const LL INFL = 1e17;

typedef pair <LL, LL> PLL;

int n, m;
int b[N];

LL a[N], c[N];

struct State {
	LL minute, needed, idx;
	State () {}
	State (LL minute, LL needed, LL idx) : minute(minute), needed(needed), idx(idx) {}
	bool operator < (const State &that) const {
		if (minute != that.minute) return minute < that.minute;
		if (needed != that.needed) return needed > that.needed;
		return idx < that.idx;
	}
};

bool Check(LL charge) {
	set <State> S;
	for (int i = 1; i <= n; ++i) c[i] = a[i];
	for (int i = 1; i <= n; ++i) {
		LL q = c[i] / b[i], r = c[i] % b[i];
		S.insert(State(q, b[i] - r, i));
	}
	for (int i = 1; i <= m; ++i) {
		LL minute = S.begin() -> minute, needed = S.begin() -> needed, idx = S.begin() -> idx;
		S.erase(S.begin());
		if (minute < (i - 1)) return false;
		c[idx] += charge;
		LL q = c[idx] / b[idx], r = c[idx] % b[idx];
		S.insert(State(q, b[idx] - r, idx));
	}
	return true;
}

int main() {
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; ++i) scanf("%lld", &a[i]);
	for (int i = 1; i <= n; ++i) scanf("%d", &b[i]);
	LL l = 1, r = INFL, f = -1;
	while (l <= r) {
		LL m = (l + r) >> 1;
		if (Check(m)) {
			f = m;
			r = m - 1;
		} else l = m + 1;
	}
	printf("%lld\n", f);
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long LL;

const int N = 2e5 + 10;
const LL INFL = 1e15;

typedef pair <LL, LL> PLL;

int n, m;
int b[N];

LL a[N], c[N];

struct State {
	LL minute, needed, idx;
	State () {}
	State (LL minute, LL needed, LL idx) : minute(minute), needed(needed), idx(idx) {}
	bool operator < (const State &that) const {
		if (minute != that.minute) return minute < that.minute;
		if (needed != that.needed) return needed > that.needed;
		return idx < that.idx;
	}
};

bool Check(LL charge) {
	set <State> S;
	for (int i = 1; i <= n; ++i) c[i] = a[i];
	for (int i = 1; i <= n; ++i) {
		LL q = c[i] / b[i], r = c[i] % b[i];
		if (q >= m - 1) continue;
		S.insert(State(q, b[i] - r, i));
	}
	for (int i = 1; i <= m; ++i) {
		if (S.size() == 0) return true;
		LL minute = S.begin() -> minute, needed = S.begin() -> needed, idx = S.begin() -> idx;
		S.erase(S.begin());
		if (minute < (i - 1)) return false;
		c[idx] += charge;
		LL q = c[idx] / b[idx], r = c[idx] % b[idx];
		if (q < (m - 1)) S.insert(State(q, b[idx] - r, idx));
	}
	return true;
}

int main() {
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; ++i) scanf("%lld", &a[i]);
	for (int i = 1; i <= n; ++i) scanf("%d", &b[i]);
	LL l = 0, r = INFL, f = -1;
	while (l <= r) {
		LL m = (l + r) >> 1;
		if (Check(m)) {
			f = m;
			r = m - 1;
		} else l = m + 1;
	}
	printf("%lld\n", f);
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long LL;

const int N = 2e5 + 10;
const LL INFL = 1e13;

typedef pair <LL, LL> PLL;

int n, m;
int b[N];

LL a[N], c[N];

struct State {
	LL minute, needed, idx;
	State () {}
	State (LL minute, LL needed, LL idx) : minute(minute), needed(needed), idx(idx) {}
	bool operator < (const State &that) const {
		if (minute != that.minute) return minute < that.minute;
		if (needed != that.needed) return needed > that.needed;
		return idx < that.idx;
	}
};

bool Check(LL charge) {
	set <State> S;
	for (int i = 1; i <= n; ++i) c[i] = a[i];
	for (int i = 1; i <= n; ++i) {
		LL q = c[i] / b[i], r = c[i] % b[i];
		S.insert(State(q, b[i] - r, i));
	}
	for (int i = 1; i <= m; ++i) {
		LL minute = S.begin() -> minute, needed = S.begin() -> needed, idx = S.begin() -> idx;
		S.erase(S.begin());
		if (minute < (i - 1)) return false;
		c[idx] += charge;
		LL q = c[idx] / b[idx], r = c[idx] % b[idx];
		S.insert(State(q, b[idx] - r, idx));
	}
	return true;
}

int main() {
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; ++i) scanf("%lld", &a[i]);
	for (int i = 1; i <= n; ++i) scanf("%d", &b[i]);
	LL l = 0, r = INFL, f = -1;
	while (l <= r) {
		LL m = (l + r) >> 1;
		if (Check(m)) {
			f = m;
			r = m - 1;
		} else l = m + 1;
	}
	printf("%lld\n", f);
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long LL;

const int N = 2e5 + 10;
const LL INFL = 1e13;

typedef pair <LL, LL> PLL;

int n, m;
int b[N];

LL a[N], c[N];

struct State {
	LL minute, needed, idx;
	State () {}
	State (LL minute, LL needed, LL idx) : minute(minute), needed(needed), idx(idx) {}
	bool operator < (const State &that) const {
		if (minute != that.minute) return minute < that.minute;
		if (needed != that.needed) return needed > that.needed;
		return idx < that.idx;
	}
};

bool Check(LL charge) {
	set <State> S;
	for (int i = 1; i <= n; ++i) c[i] = a[i];
	for (int i = 1; i <= n; ++i) {
		LL q = c[i] / b[i], r = c[i] % b[i];
		if (q >= m - 1) continue;
		S.insert(State(q, b[i] - r, i));
	}
	for (int i = 1; i <= m; ++i) {
		if (S.size() == 0) return true;
		LL minute = S.begin() -> minute, needed = S.begin() -> needed, idx = S.begin() -> idx;
		S.erase(S.begin());
		if (minute < (i - 1)) return false;
		c[idx] += charge;
		LL q = c[idx] / b[idx], r = c[idx] % b[idx];
		if (q < (m - 1)) S.insert(State(q, b[idx] - r, idx));
	}
	return true;
}

int main() {
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; ++i) scanf("%lld", &a[i]);
	for (int i = 1; i <= n; ++i) scanf("%d", &b[i]);
	LL l = 0, r = INFL, f = -1;
	while (l <= r) {
		LL m = (l + r) >> 1;
		if (Check(m)) {
			f = m;
			r = m - 1;
		} else l = m + 1;
	}
	printf("%lld\n", f);
	return 0;
}