#define _rep(i,a,b) for(int i=a;i<=b;++i)
#include <iostream>
#include <vector>
#include <queue>
#include <cassert>
#include <algorithm>
typedef unsigned long long LL;
using namespace std;
const int MAXN = 2e5;
LL a[MAXN+4],b[MAXN+4];
int n,k;
struct node{
  LL a,b;
  node(LL a=0,LL b=0):a(a),b(b) {}
  bool operator<(const node &rhs) const {
    return a*rhs.b > rhs.a*b;
  }
};
struct heap{
  node a[MAXN+4];
  int r = 0;
  void push(node x) {
    a[r++] = x;
    push_heap(a,a+r);
  }
  node top() {
    return a[0];
  }
  void pop() {
    assert( !empty() );
    pop_heap(a,a+r--);
  }
  bool empty() {
    return r == 0;
  }
}Q;

bool check(LL mid) {
  if( !mid ) {
    if( Q.empty() ) return true;
    else return false;
  }
  heap bq = Q;
  LL t = 1;
  while( t < (LL)k ) {
    //!!!
    if( bq.empty() ) return true;
    //!!!
    auto x = bq.top(); bq.pop();
    if( !bq.empty() ) {
      auto y = bq.top();
      if( y.a < y.b*t ) return false;
    }
    LL del = x.a/x.b - (t-1);
    x.a += mid*del;
    if( x.a < x.b*t ) return false;
    if( x.b*k > x.a ) bq.push( x );
    t += del;
  }
  return true;
}

int main() {
//  freopen("in","r",stdin);
//  ios::sync_with_stdio(false);
//  cin.tie(0)
  cin >> n >> k;
  LL r = 0;
  _rep(i,1,n) cin >> a[i];
  _rep(i,1,n) {
    cin >> b[i];
    if( b[i]*k > a[i] )
      Q.push( node(a[i],b[i]) );
    r = max( (LL)r , b[i]*k );
  }
  LL l = 0 , mid , ans = -1;
  while( l <= r ) {
    mid = l + ((r-l)>>1);
    if( check(mid) )
      ans = mid , r = mid-1;
    else l = mid+1;
  }
  if( ans == LL(-1) )
      cout << "-1\n";
  else cout << ans << '\n';
  return 0;
}


#define _rep(i,a,b) for(int i=a;i<=b;++i)
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
typedef unsigned long long LL;
using namespace std;
const int MAXN = 2e5;
LL a[MAXN+4],b[MAXN+4];
int n,k;
struct node{
  LL a,b;
  node(LL a=0,LL b=0):a(a),b(b) {}
  bool operator<(const node &rhs) const {
    return a*rhs.b > rhs.a*b;
  }
};
struct heap{
  node a[MAXN+4];
  int r = 0;
  void push(node x) {
    a[r++] = x;
    push_heap(a,a+r);
  }
  node top() {
    return a[0];
  }
  void pop() {
    pop_heap(a,a+r--);
  }
  bool empty() {
    return r == 0;
  }
}Q;

bool check(int mid) {
  heap bq = Q;
  LL t = 1;
  while( t < (LL)k ) {
    auto x = bq.top(); bq.pop();
    if( !bq.empty() ) {
      auto y = bq.top();
      if( y.a < y.b*t ) return false;
    }
    x.a += mid;
    if( x.a < x.b*t ) return false;
    if( x.b*k > x.a ) bq.push( x );
    ++t;
  }
  return true;
}

int main() {
//  freopen("in","r",stdin);
//  ios::sync_with_stdio(false);
//  cin.tie(0)
  cin >> n >> k;
  LL r = 0;
  _rep(i,1,n) cin >> a[i];
  _rep(i,1,n) {
    cin >> b[i];
    if( b[i]*k > a[i] )
      Q.push( node(a[i],b[i]) );
    r = max( (LL)r , b[i]*k );
  }
  LL l = 0 , mid , ans = -1;
  while( l <= r ) {
    mid = l + ((r-l)>>1);
    if( check(mid) )
      ans = mid , r = mid-1;
    else l = mid+1;
  }
  if( ans == LL(-1) )
      cout << "-1\n";
  else cout << ans << '\n';
  return 0;
}


#define _for(i,a,b) for(int i=a;i< b;++i)
#define _rep(i,a,b) for(int i=a;i<=b;++i)
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <algorithm>
typedef long long LL;
using namespace std;
const int MAXN = 2e5;
LL n,k,a[MAXN+4],b[MAXN];
struct node{
  LL a,b;
  node(LL a=0,LL b=0):a(a),b(b) {}
  bool operator<(const node &rhs) const {
    return a*rhs.b > rhs.a*b;
  }
};
struct heap{
  node a[MAXN+4];
  int r = 0;
  void push(node x) {
    a[r++] = x;
    push_heap(a,a+r);
  }
  node top() {
    return a[0];
  }
  void pop() {
    pop_heap(a,a+r--);
  }
  bool empty() {
    return r == 0;
  }
}Q;

bool check(int mid) {
  heap bq = Q;
  int t = 1;
  while( t < k ) {
    auto x = bq.top(); bq.pop();
    if( !bq.empty() ) {
      auto y = bq.top();
      if( y.a < y.b*t ) return false;
    }
    x.a += mid;
    if( x.a < x.b*t ) return false;
    if( x.b*k > x.a ) bq.push( x );
    ++t;
  }
  return true;
}

int main() {
 // freopen("in","r",stdin);
//  ios::sync_with_stdio(false);
//  cin.tie(0)
  cin >> n >> k;
  LL r = 0;
  _rep(i,1,n) cin >> a[i];
  _rep(i,1,n) {
    cin >> b[i];
    if( b[i]*k > a[i] )
      Q.push( node(a[i],b[i]) );
    r = max( (LL)r , b[i]*k );
  }
  LL l = 0 , mid , ans = -1;
  while( l <= r ) {
    mid = l + ((r-l)>>1);
    if( check(mid) )
      ans = mid , r = mid-1;
    else l = mid+1;
  }
  cout << ans << '\n';
  return 0;
}


#define _rep(i,a,b) for(int i=a;i<=b;++i)
#include <iostream>
#include <vector>
#include <queue>
#include <cassert>
#include <algorithm>
typedef unsigned long long LL;
using namespace std;
const int MAXN = 2e5;
LL a[MAXN+4],b[MAXN+4];
int n,k;
struct node{
  LL a,b;
  node(LL a=0,LL b=0):a(a),b(b) {}
  bool operator<(const node &rhs) const {
    return a*rhs.b > rhs.a*b;
  }
};
struct heap{
  node a[MAXN+4];
  int r = 0;
  void push(node x) {
    a[r++] = x;
    push_heap(a,a+r);
  }
  node top() {
    return a[0];
  }
  void pop() {
    assert( !empty() );
    pop_heap(a,a+r--);
  }
  bool empty() {
    return r == 0;
  }
}Q;

bool check(LL mid) {
  if( !mid ) {
    if( Q.empty() ) return true;
    else return false;
  }
  heap bq = Q;
  LL t = 1;
  while( t < (LL)k ) {
    //!!!
    if( bq.empty() ) return true;
    //!!!
    auto x = bq.top(); bq.pop();
    if( !bq.empty() ) {
      auto y = bq.top();
      if( y.a < y.b*t ) return false;
    }
    LL del = x.a/x.b - (t-1);
    if( !del ) ++del;
    x.a += mid*del;
    if( x.a < x.b*t ) return false;
    if( x.b*k > x.a ) bq.push( x );
    t += del;
  }
  return true;
}

int main() {
//  freopen("in","r",stdin);
//  ios::sync_with_stdio(false);
//  cin.tie(0)
  cin >> n >> k;
  LL r = 0;
  _rep(i,1,n) cin >> a[i];
  _rep(i,1,n) {
    cin >> b[i];
    if( b[i]*k > a[i] )
      Q.push( node(a[i],b[i]) );
    r = max( (LL)r , b[i]*k );
  }
  LL l = 0 , mid , ans = -1;
  while( l <= r ) {
    mid = l + ((r-l)>>1);
    if( check(mid) )
      ans = mid , r = mid-1;
    else l = mid+1;
  }
  if( ans == LL(-1) )
      cout << "-1\n";
  else cout << ans << '\n';
  return 0;
}


#include <iostream>
#include <bitset>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;
using ll = unsigned long long;
int n, k;
ll a[200001], b[200001];
vector<pair<int, int>> t[200001];

bool check() {
    for (int i = 0; i < n; ++i) {
        int e = a[i] / b[i];
        if (e < k - 1) {
            t[e].push_back(make_pair(i, a[i] % b[i]));
        }
    }
    int sum = 0;
    for (int i = 0; i < k; ++i) {
        sum += t[i].size();
        if (sum > i + 1) {
            return false;
        }
    }
    return true;
}

bool solve(ll x) {
    for (int i = 0; i < k; ++i) t[i].clear();
    for (int i = 0; i < n; ++i) {
        int e = a[i] / b[i];
        if (e < k - 1) {
            t[e].push_back(make_pair(i, a[i] % b[i]));
        }
    }

    int nxt = 0;
    for (int i = 0; i < k; ++i) {
        while (t[nxt].empty() && nxt < k) nxt++;
        if (nxt == k) return true;
        auto &p = t[nxt].back();
        t[nxt].pop_back();
        ll u = p.first;
        ll v = p.second;
        v = v + (nxt - i) * b[u] + x - b[u];
        if (v >= 0) {
            ll e = i + 1 + v / b[u];
            if (e < k - 1) {
                t[e].push_back(make_pair(u, v % b[u]));
                // cout << i << " " << e << " " << u << " " << v << endl;
            }
        } else {
            return false;
        }

        if (!t[i].empty()) {
            return false;
        }
    }
    return true;
}

int main() {
    cin >> n >> k;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    for (int i = 0; i < n; ++i) {
        cin >> b[i];
    }
    if (!check()) {
        cout << "-1\n";
        return 0;
    }
    ll l = 0, r = 1 << 12;
    while (l < r) {
        ll mid = (l + r) >> 1;
        if (solve(mid)) {
            r = mid;
        } else {
            l = mid + 1;
        }
    }
    cout << l << endl;
    // cout << solve(1) << endl;
    return 0;
}


#include <iostream>
#include <bitset>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;
using ll = long long;
ll n, k;
ll a[200001], b[200001];
vector<pair<int, ll>> t[200001];

bool check() {
    for (int i = 0; i < n; ++i) {
        ll e = a[i] / b[i];
        if (e < k - 1) {
            t[e].push_back(make_pair(i, a[i] % b[i]));
        }
    }
    int sum = 0;
    for (int i = 0; i < k; ++i) {
        sum += t[i].size();
        if (sum > i + 1) {
            return false;
        }
    }
    return true;
}

bool solve(ll x) {
    for (int i = 0; i < k; ++i) t[i].clear();
    for (int i = 0; i < n; ++i) {
        ll e = a[i] / b[i];
        if (e < k - 1) {
            t[e].push_back(make_pair(i, a[i] % b[i]));
        }
    }

    ll nxt = 0;
    for (ll i = 0; i < k; ++i) {
        while (t[nxt].empty() && nxt < k - 1) {
            nxt++;
        }
        if (nxt == k - 1) return true;
        auto &p = t[nxt].back();
        t[nxt].pop_back();
        ll u = p.first;
        ll v = p.second;
        v = v + (nxt - i) * b[u] + x - b[u];
        if (v >= 0) {
            ll e = (i + 1) + v / b[u];
            if (e < k - 1) {
                t[e].push_back(make_pair(u, v % b[u]));
            }
        } else {
            return false;
        }

        if (!t[i].empty()) {
            return false;
        }
    }
    return true;
}

int main() {
    cin >> n >> k;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    for (int i = 0; i < n; ++i) {
        cin >> b[i];
    }
    if (!check()) {
        cout << "-1\n";
        return 0;
    }
    ll l = 0, r = 1 << 12;
    while (l < r) {
        ll mid = (l + r) >> 1;
        if (solve(mid)) {
            r = mid;
        } else {
            l = mid + 1;
        }
    }
    cout << l << endl;
    // cout << solve(1) << endl;
    return 0;
}


#include <iostream>
#include <bitset>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;
using ll = long long;
int n, k;
ll a[200001], b[200001];
vector<pair<int, int>> t[200001];

bool check() {
    for (int i = 0; i < n; ++i) {
        int e = a[i] / b[i];
        if (e < k - 1) {
            t[e].push_back(make_pair(i, a[i] % b[i]));
        }
    }
    int sum = 0;
    for (int i = 0; i < k; ++i) {
        sum += t[i].size();
        if (sum > i + 1) {
            return false;
        }
    }
    return true;
}

bool solve(ll x) {
    for (int i = 0; i < k; ++i) t[i].clear();
    for (int i = 0; i < n; ++i) {
        int e = a[i] / b[i];
        if (e < k - 1) {
            t[e].push_back(make_pair(i, a[i] % b[i]));
        }
    }

    int nxt = 0;
    for (int i = 0; i < k; ++i) {
        while (t[nxt].empty() && nxt < k - 1) nxt++;
        if (nxt == k - 1) return true;
        auto &p = t[nxt].back();
        t[nxt].pop_back();
        ll u = p.first;
        ll v = p.second;
        v = v + (ll)(nxt - i) * b[u] + x - b[u];
        // cout << endl;
        if (v >= 0) {
            ll e = (ll)(i + 1) + v / b[u];
            // cout << e << " ";
            if (e < k - 1) {
                t[e].push_back(make_pair(u, v % b[u]));
                // cout << i << " " << e << " " << u << " " << v << endl;
            }
        } else {
            return false;
        }

        if (!t[i].empty()) {
            return false;
        }
    }
    return true;
}

int main() {
    cin >> n >> k;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    for (int i = 0; i < n; ++i) {
        cin >> b[i];
    }
    if (!check()) {
        cout << "-1\n";
        return 0;
    }
    ll l = 0, r = 1 << 12;
    while (l < r) {
        ll mid = (l + r) >> 1;
        if (solve(mid)) {
            r = mid;
        } else {
            l = mid + 1;
        }
    }
    cout << l << endl;
    // cout << solve(1) << endl;
    return 0;
}


#include <iostream>
#include <bitset>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;
using ll = long long;
int n, k;
ll a[200001], b[200001];
vector<pair<int, ll>> t[200001];

bool check() {
    for (int i = 0; i < n; ++i) {
        int e = a[i] / b[i];
        if (e < k - 1) {
            t[e].push_back(make_pair(i, a[i] % b[i]));
        }
    }
    int sum = 0;
    for (int i = 0; i < k; ++i) {
        sum += t[i].size();
        if (sum > i + 1) {
            return false;
        }
    }
    for (int i = 0; i < k; ++i) t[i].clear();
    return true;
}

bool solve(ll x) {
    for (int i = 0; i < k; ++i) t[i].clear();
    for (int i = 0; i < n; ++i) {
        ll e = a[i] / b[i];
        if (e < k - 1) {
            t[e].push_back(make_pair(i, a[i] % b[i]));
        }
    }

    ll nxt = 0;
    for (ll i = 0; i < k; ++i) {
        while (t[nxt].empty() && nxt < k - 1) nxt++;
        if (nxt == k - 1) return true;
        auto &p = t[nxt].back();
        t[nxt].pop_back();
        ll u = p.first;
        ll v = p.second;
        v = v + (nxt - i) * b[u] + x - b[u];
        // cout << endl;
        if (v >= 0) {
            ll e = (i + 1) + v / b[u];
            // cout << e << " ";
            if (e < k - 1) {
                t[e].push_back(make_pair(u, v % b[u]));
                // cout << i << " " << e << " " << u << " " << v << endl;
            }
        } else {
            return false;
        }

        if (!t[i].empty()) {
            return false;
        }
    }
    return true;
}

int main() {
    cin >> n >> k;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    for (int i = 0; i < n; ++i) {
        cin >> b[i];
    }
    if (!check()) {
        cout << "-1\n";
        return 0;
    }
    ll l = 0, r = 1 << 12;
    while (l < r) {
        ll mid = (l + r) >> 1;
        if (solve(mid)) {
            r = mid;
        } else {
            l = mid + 1;
        }
    }
    cout << l << endl;
    // cout << solve(1) << endl;
    return 0;
}


#include <iostream>
#include <bitset>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;
using ll = long long;
int n, k;
ll a[200001], b[200001];
vector<pair<int, ll>> t[200001];

bool check() {
    for (int i = 0; i < n; ++i) {
        int e = a[i] / b[i];
        if (e < k - 1) {
            t[e].push_back(make_pair(i, a[i] % b[i]));
        }
    }
    int sum = 0;
    for (int i = 0; i < k; ++i) {
        sum += t[i].size();
        if (sum > i + 1) {
            return false;
        }
    }
    return true;
}

bool solve(ll x) {
    for (int i = 0; i < k; ++i) t[i].clear();
    for (int i = 0; i < n; ++i) {
        ll e = a[i] / b[i];
        if (e < k - 1) {
            t[e].push_back(make_pair(i, a[i] % b[i]));
        }
    }

    int nxt = 0;
    for (int i = 0; i < k; ++i) {
        while (t[nxt].empty() && nxt < k - 1) nxt++;
        if (nxt == k - 1) return true;
        auto &p = t[nxt].back();
        t[nxt].pop_back();
        ll u = p.first;
        ll v = p.second;
        v = v + (ll)(nxt - i) * b[u] + x - b[u];
        // cout << endl;
        if (v >= 0) {
            ll e = (ll)(i + 1) + v / b[u];
            // cout << e << " ";
            if (e < k - 1) {
                t[e].push_back(make_pair(u, v % b[u]));
                // cout << i << " " << e << " " << u << " " << v << endl;
            }
        } else {
            return false;
        }

        if (!t[i].empty()) {
            return false;
        }
    }
    return true;
}

int main() {
    cin >> n >> k;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    for (int i = 0; i < n; ++i) {
        cin >> b[i];
    }
    if (!check()) {
        cout << "-1\n";
        return 0;
    }
    ll l = 0, r = 1 << 12;
    while (l < r) {
        ll mid = (l + r) >> 1;
        if (solve(mid)) {
            r = mid;
        } else {
            l = mid + 1;
        }
    }
    cout << l << endl;
    // cout << solve(1) << endl;
    return 0;
}


#include <iostream>
#include <bitset>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;
using ll = unsigned long long;
ll n, k;
ll a[200001], b[200001];
vector<pair<int, ll>> t[200001];

bool check() {
    for (int i = 0; i < n; ++i) {
        ll e = a[i] / b[i];
        if (e < k - 1) {
            t[e].push_back(make_pair(i, a[i] % b[i]));
        }
    }
    int sum = 0;
    for (int i = 0; i < k; ++i) {
        sum += t[i].size();
        if (sum > i + 1) {
            return false;
        }
    }
    return true;
}

bool solve(ll x) {
    for (int i = 0; i < k; ++i) t[i].clear();
    for (int i = 0; i < n; ++i) {
        ll e = a[i] / b[i];
        if (e < k - 1) {
            t[e].push_back(make_pair(i, a[i] % b[i]));
        }
    }

    ll nxt = 0;
    for (ll i = 0; i < k - 1; ++i) {
        while (t[nxt].empty() && nxt < k - 1) {
            nxt++;
        }
        if (nxt == k - 1) return true;
        auto &p = t[nxt].back();
        t[nxt].pop_back();
        ll u = p.first;
        long long v = p.second;
        v = v + (nxt - i) * b[u] + x - b[u];
        if (v >= 0) {
            ll e = (i + 1) + v / b[u];
            if (e < k - 1) {
                t[e].push_back(make_pair(u, v % b[u]));
            }
        } else {
            return false;
        }

        if (!t[i].empty()) {
            return false;
        }
    }
    return true;
}

int main() {
    cin >> n >> k;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    for (int i = 0; i < n; ++i) {
        cin >> b[i];
    }
    if (!check()) {
        cout << "-1\n";
        return 0;
    }
    ll l = 0, r = 1 << 12;
    while (l < r) {
        ll mid = (l + r) >> 1;
        if (n == 1000 && k == 1000) {
            cerr << l << " " << r << " " << mid << endl;
        }
        if (solve(mid)) {
            r = mid;
        } else {
            l = mid + 1;
        }
    }
    cout << l << endl;
    // cout << solve(1) << endl;
    return 0;
}


#include <iostream>
#include <bitset>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;
using ll = unsigned long long;
ll n, k;
ll a[200001], b[200001];
vector<pair<int, ll>> t[200001];

bool check() {
    for (int i = 0; i < n; ++i) {
        ll e = a[i] / b[i];
        if (e < k - 1) {
            t[e].push_back(make_pair(i, a[i] % b[i]));
        }
    }
    int sum = 0;
    for (int i = 0; i < k; ++i) {
        sum += t[i].size();
        if (sum > i + 1) {
            return false;
        }
    }
    return true;
}

bool solve(ll x) {
    for (int i = 0; i < k; ++i) t[i].clear();
    for (int i = 0; i < n; ++i) {
        ll e = a[i] / b[i];
        if (e < k - 1) {
            t[e].push_back(make_pair(i, a[i] % b[i]));
        }
    }

    ll nxt = 0;
    for (ll i = 0; i < k - 1; ++i) {
        while (t[nxt].empty() && nxt < k - 1) {
            nxt++;
        }
        if (nxt < i) {
            cout << "Omegalul" << endl;
        }
        if (nxt == k - 1) return true;
        auto &p = t[nxt].back();
        t[nxt].pop_back();
        ll u = p.first;
        long long v = p.second;
        v = v + (nxt - i) * b[u] + x - b[u];
        if (v >= 0) {
            ll e = (i + 1) + v / b[u];
            if (e < k - 1) {
                t[e].push_back(make_pair(u, v % b[u]));
            }
        } else {
            return false;
        }

        if (!t[i].empty()) {
            return false;
        }
    }
    return true;
}

int main() {
    cin >> n >> k;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    for (int i = 0; i < n; ++i) {
        cin >> b[i];
    }
    if (!check()) {
        cout << "-1\n";
        return 0;
    }
    ll l = 0, r = 1 << 12;
    while (l < r) {
        ll mid = (l + r) >> 1;
        if (solve(mid)) {
            r = mid;
        } else {
            l = mid + 1;
        }
    }
    cout << l << endl;
    // cout << solve(1) << endl;
    return 0;
}


#include <iostream>
#include <bitset>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;
using ll = long long;
int n, k;
ll a[200001], b[200001];
vector<pair<int, ll>> t[200001];

bool check() {
    for (int i = 0; i < n; ++i) {
        int e = a[i] / b[i];
        if (e < k - 1) {
            t[e].push_back(make_pair(i, a[i] % b[i]));
        }
    }
    int sum = 0;
    for (int i = 0; i < k; ++i) {
        sum += t[i].size();
        if (sum > i + 1) {
            return false;
        }
    }
    return true;
}

bool solve(ll x) {
    for (int i = 0; i < k; ++i) t[i].clear();
    for (int i = 0; i < n; ++i) {
        ll e = a[i] / b[i];
        if (e < k - 1) {
            t[e].push_back(make_pair(i, a[i] % b[i]));
        }
    }

    ll nxt = 0;
    for (ll i = 0; i < k; ++i) {
        while (t[nxt].empty() && nxt < k - 1) nxt++;
        if (nxt == k - 1) return true;
        auto &p = t[nxt].back();
        t[nxt].pop_back();
        ll u = p.first;
        ll v = p.second;
        v = v + (nxt - i) * b[u] + x - b[u];
        // cout << endl;
        if (v >= 0) {
            ll e = (ll)(i + 1) + v / b[u];
            // cout << e << " ";
            if (e < k - 1) {
                t[e].push_back(make_pair(u, v % b[u]));
                // cout << i << " " << e << " " << u << " " << v << endl;
            }
        } else {
            return false;
        }

        if (!t[i].empty()) {
            return false;
        }
    }
    return true;
}

int main() {
    cin >> n >> k;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    for (int i = 0; i < n; ++i) {
        cin >> b[i];
    }
    if (!check()) {
        cout << "-1\n";
        return 0;
    }
    ll l = 0, r = 1 << 12;
    while (l < r) {
        ll mid = (l + r) >> 1;
        if (solve(mid)) {
            r = mid;
        } else {
            l = mid + 1;
        }
    }
    cout << l << endl;
    // cout << solve(1) << endl;
    return 0;
}


#include <iostream>
#include <bitset>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;
using ll = unsigned long long;
ll n, k;
ll a[200001], b[200001];
vector<pair<int, ll>> t[200001];

bool check() {
    for (int i = 0; i < n; ++i) {
        ll e = a[i] / b[i];
        if (e < k - 1) {
            t[e].push_back(make_pair(i, a[i] % b[i]));
        }
    }
    int sum = 0;
    for (int i = 0; i < k; ++i) {
        sum += t[i].size();
        if (sum > i + 1) {
            return false;
        }
    }
    return true;
}

bool solve(ll x) {
    for (int i = 0; i < k; ++i) t[i].clear();
    for (int i = 0; i < n; ++i) {
        ll e = a[i] / b[i];
        if (e < k - 1) {
            t[e].push_back(make_pair(i, a[i] % b[i]));
        }
    }

    ll nxt = 0;
    for (ll i = 0; i < k; ++i) {
        while (t[nxt].empty() && nxt < k - 1) {
            nxt++;
        }
        if (nxt == k - 1) return true;
        auto &p = t[nxt].back();
        t[nxt].pop_back();
        ll u = p.first;
        long long v = p.second;
        v = v + (nxt - i) * b[u] + x - b[u];
        if (v >= 0) {
            ll e = (i + 1) + v / b[u];
            if (e < k - 1) {
                t[e].push_back(make_pair(u, v % b[u]));
            }
        } else {
            return false;
        }

        if (!t[i].empty()) {
            return false;
        }
    }
    return true;
}

int main() {
    cin >> n >> k;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    for (int i = 0; i < n; ++i) {
        cin >> b[i];
    }
    if (!check()) {
        cout << "-1\n";
        return 0;
    }
    ll l = 0, r = 1 << 12;
    while (l < r) {
        ll mid = (l + r) >> 1;
        if (solve(mid)) {
            r = mid;
        } else {
            l = mid + 1;
        }
    }
    cout << l << endl;
    // cout << solve(1) << endl;
    return 0;
}


#include <iostream>
#include <bitset>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;
using ll = unsigned long long;
ll n, k;
ll a[200001], b[200001];
vector<pair<int, ll>> t[200001];

bool check() {
    for (int i = 0; i < n; ++i) {
        ll e = a[i] / b[i];
        if (e < k - 1) {
            t[e].push_back(make_pair(i, a[i] % b[i]));
        }
    }
    int sum = 0;
    for (int i = 0; i < k; ++i) {
        sum += t[i].size();
        if (sum > i + 1) {
            return false;
        }
    }
    return true;
}

bool solve(ll x) {
    for (int i = 0; i < k; ++i) t[i].clear();
    for (int i = 0; i < n; ++i) {
        ll e = a[i] / b[i];
        if (e < k - 1) {
            t[e].push_back(make_pair(i, a[i] % b[i]));
        }
    }

    ll nxt = 0;
    for (ll i = 0; i < k - 1; ++i) {
        while (t[nxt].empty() && nxt < k - 1) {
            nxt++;
        }
        if (nxt == k - 1) return true;
        auto &p = t[nxt].back();
        t[nxt].pop_back();
        ll u = p.first;
        long long v = p.second;
        v = v + (nxt - i) * b[u] + x - b[u];
        if (v >= 0) {
            ll e = (i + 1) + v / b[u];
            if (e < k - 1) {
                t[e].push_back(make_pair(u, v % b[u]));
            }
        } else {
            return false;
        }

        if (!t[i].empty()) {
            return false;
        }
    }
    return true;
}

int main() {
    cin >> n >> k;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    for (int i = 0; i < n; ++i) {
        cin >> b[i];
    }
    if (!check()) {
        cout << "-1\n";
        return 0;
    }
    ll l = 0, r = 1 << 12;
    while (l < r) {
        ll mid = (l + r) >> 1;
        if (n == 1000 && k == 1000 && mid == 4096) {
            cout << "Omegalul" << endl;
        }
        if (solve(mid)) {
            r = mid;
        } else {
            l = mid + 1;
        }
    }
    cout << l << endl;
    // cout << solve(1) << endl;
    return 0;
}


#include <iostream>
#include <bitset>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;
using ll = unsigned long long;
ll n, k;
ll a[200001], b[200001];
vector<pair<int, ll>> t[200001];

bool check() {
    for (int i = 0; i < n; ++i) {
        ll e = a[i] / b[i];
        if (e < k - 1) {
            t[e].push_back(make_pair(i, a[i] % b[i]));
        }
    }
    int sum = 0;
    for (int i = 0; i < k; ++i) {
        sum += t[i].size();
        if (sum > i + 1) {
            return false;
        }
    }
    return true;
}

bool solve(ll x) {
    for (int i = 0; i < k; ++i) t[i].clear();
    for (int i = 0; i < n; ++i) {
        ll e = a[i] / b[i];
        if (e < k - 1) {
            t[e].push_back(make_pair(i, a[i] % b[i]));
        }
    }

    ll nxt = 0;
    for (ll i = 0; i < k; ++i) {
        while (t[nxt].empty() && nxt < k - 1) {
            nxt++;
        }
        if (nxt == k - 1) return true;
        auto &p = t[nxt].back();
        t[nxt].pop_back();
        ll u = p.first;
        long long v = p.second;
        v = v + (nxt - i) * b[u] + x - b[u];
        if (v >= 0) {
            ll e = (i + 1) + v / b[u];
            if (e < k - 1) {
                t[e].push_back(make_pair(u, v % b[u]));
            }
        }

        if (!t[i].empty()) {
            return false;
        }
    }
    return true;
}

int main() {
    cin >> n >> k;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    for (int i = 0; i < n; ++i) {
        cin >> b[i];
    }
    if (!check()) {
        cout << "-1\n";
        return 0;
    }
    ll l = 0, r = 1 << 12;
    while (l < r) {
        ll mid = (l + r) >> 1;
        if (solve(mid)) {
            r = mid;
        } else {
            l = mid + 1;
        }
    }
    cout << l << endl;
    // cout << solve(1) << endl;
    return 0;
}


#include <iostream>
#include <bitset>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;
using ll = long long;
int n, k;
ll a[200001], b[200001];
vector<pair<int, ll>> t[200001];

bool check() {
    for (int i = 0; i < n; ++i) {
        int e = a[i] / b[i];
        if (e < k - 1) {
            t[e].push_back(make_pair(i, a[i] % b[i]));
        }
    }
    int sum = 0;
    for (int i = 0; i < k; ++i) {
        sum += t[i].size();
        if (sum > i + 1) {
            return false;
        }
    }
    return true;
}

bool solve(ll x) {
    for (int i = 0; i < k; ++i) t[i].clear();
    for (int i = 0; i < n; ++i) {
        int e = a[i] / b[i];
        if (e < k - 1) {
            t[e].push_back(make_pair(i, a[i] % b[i]));
        }
    }

    int nxt = 0;
    for (int i = 0; i < k; ++i) {
        while (t[nxt].empty() && nxt < k - 1) nxt++;
        if (nxt == k - 1) return true;
        auto &p = t[nxt].back();
        t[nxt].pop_back();
        ll u = p.first;
        ll v = p.second;
        v = v + (ll)(nxt - i) * b[u] + x - b[u];
        // cout << endl;
        if (v >= 0) {
            ll e = (ll)(i + 1) + v / b[u];
            // cout << e << " ";
            if (e < k - 1) {
                t[e].push_back(make_pair(u, v % b[u]));
                // cout << i << " " << e << " " << u << " " << v << endl;
            }
        } else {
            return false;
        }

        if (!t[i].empty()) {
            return false;
        }
    }
    return true;
}

int main() {
    cin >> n >> k;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    for (int i = 0; i < n; ++i) {
        cin >> b[i];
    }
    if (!check()) {
        cout << "-1\n";
        return 0;
    }
    ll l = 0, r = 1 << 12;
    while (l < r) {
        ll mid = (l + r) >> 1;
        if (solve(mid)) {
            r = mid;
        } else {
            l = mid + 1;
        }
    }
    cout << l << endl;
    // cout << solve(1) << endl;
    return 0;
}


#include <iostream>
#include <bitset>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;
using ll = unsigned long long;
int n, k;
ll a[200001], b[200001];
vector<pair<int, int>> t[200001];

bool check() {
    for (int i = 0; i < n; ++i) {
        int e = a[i] / b[i];
        if (e < k - 1) {
            t[e].push_back(make_pair(i, a[i] % b[i]));
        }
    }
    int sum = 0;
    for (int i = 0; i < k; ++i) {
        sum += t[i].size();
        if (sum > i + 1) {
            return false;
        }
    }
    return true;
}

bool solve(ll x) {
    for (int i = 0; i < k; ++i) t[i].clear();
    for (int i = 0; i < n; ++i) {
        int e = a[i] / b[i];
        if (e < k - 1) {
            t[e].push_back(make_pair(i, a[i] % b[i]));
        }
    }

    int nxt = 0;
    for (int i = 0; i < k; ++i) {
        while (t[nxt].empty() && nxt < k) nxt++;
        if (nxt == k) return true;
        auto &p = t[nxt].back();
        t[nxt].pop_back();
        ll u = p.first;
        ll v = p.second;
        v = v + (nxt - i) * b[u] + x - b[u];
        if (v >= 0) {
            int e = i + 1 + v / b[u];
            if (e < k - 1) {
                t[e].push_back(make_pair(u, v % b[u]));
                // cout << i << " " << e << " " << u << " " << v << endl;
            }
        } else {
            return false;
        }

        if (!t[i].empty()) {
            return false;
        }
    }
    return true;
}

int main() {
    cin >> n >> k;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    for (int i = 0; i < n; ++i) {
        cin >> b[i];
    }
    if (!check()) {
        cout << "-1\n";
        return 0;
    }
    ll l = 0, r = 1 << 12;
    while (l < r) {
        ll mid = (l + r) >> 1;
        if (solve(mid)) {
            r = mid;
        } else {
            l = mid + 1;
        }
    }
    cout << l << endl;
    // cout << solve(1) << endl;
    return 0;
}


#include <iostream>
#include <bitset>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;
using ll = unsigned long long;
ll n, k;
ll a[200001], b[200001];
vector<pair<int, ll>> t[200001];

bool check() {
    for (int i = 0; i < n; ++i) {
        ll e = a[i] / b[i];
        if (e < k - 1) {
            t[e].push_back(make_pair(i, a[i] % b[i]));
        }
    }
    int sum = 0;
    for (int i = 0; i < k; ++i) {
        sum += t[i].size();
        if (sum > i + 1) {
            return false;
        }
    }
    return true;
}

bool solve(ll x) {
    for (int i = 0; i < k; ++i) t[i].clear();
    for (int i = 0; i < n; ++i) {
        ll e = a[i] / b[i];
        if (e < k - 1) {
            t[e].push_back(make_pair(i, a[i] % b[i]));
        }
    }

    ll nxt = 0;
    for (ll i = 0; i < k - 1; ++i) {
        while (t[nxt].empty() && nxt < k - 1) {
            nxt++;
        }
        if (nxt == k - 1 && x == 4096) {
            cout << "Omegalul" << endl;
        }
        if (nxt == k - 1) return true;
        auto &p = t[nxt].back();
        t[nxt].pop_back();
        ll u = p.first;
        long long v = p.second;
        v = v + (nxt - i) * b[u] + x - b[u];
        if (v >= 0) {
            ll e = (i + 1) + v / b[u];
            if (e < k - 1) {
                t[e].push_back(make_pair(u, v % b[u]));
            }
        } else {
            return false;
        }

        if (!t[i].empty()) {
            return false;
        }
    }
    return true;
}

int main() {
    cin >> n >> k;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    for (int i = 0; i < n; ++i) {
        cin >> b[i];
    }
    if (!check()) {
        cout << "-1\n";
        return 0;
    }
    ll l = 0, r = 1 << 12;
    while (l < r) {
        ll mid = (l + r) >> 1;
        if (solve(mid)) {
            r = mid;
        } else {
            l = mid + 1;
        }
    }
    cout << l << endl;
    // cout << solve(1) << endl;
    return 0;
}


#include <iostream>
#include <bitset>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;
using ll = long long;
int n, k;
ll a[200001], b[200001];
vector<pair<int, int>> t[200001];

bool check() {
    for (int i = 0; i < n; ++i) {
        int e = a[i] / b[i];
        if (e < k - 1) {
            t[e].push_back(make_pair(i, a[i] % b[i]));
        }
    }
    int sum = 0;
    for (int i = 0; i < k; ++i) {
        sum += t[i].size();
        if (sum > i + 1) {
            return false;
        }
    }
    return true;
}

bool solve(ll x) {
    for (int i = 0; i < k; ++i) t[i].clear();
    for (int i = 0; i < n; ++i) {
        int e = a[i] / b[i];
        if (e < k - 1) {
            t[e].push_back(make_pair(i, a[i] % b[i]));
        }
    }

    int nxt = 0;
    for (int i = 0; i < k; ++i) {
        while (t[nxt].empty() && nxt < k) nxt++;
        if (nxt == k) return true;
        auto &p = t[nxt].back();
        t[nxt].pop_back();
        ll u = p.first;
        ll v = p.second;
        v = v + (nxt - i) * b[u] + x - b[u];
        // cout << endl;
        if (v >= 0) {
            ll e = (ll)(i + 1) + v / b[u];
            // cout << e << " ";
            if (e < k - 1) {
                t[e].push_back(make_pair(u, v % b[u]));
                // cout << i << " " << e << " " << u << " " << v << endl;
            }
        } else {
            return false;
        }

        if (!t[i].empty()) {
            return false;
        }
    }
    return true;
}

int main() {
    cin >> n >> k;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    for (int i = 0; i < n; ++i) {
        cin >> b[i];
    }
    if (!check()) {
        cout << "-1\n";
        return 0;
    }
    ll l = 0, r = 1 << 12;
    while (l < r) {
        ll mid = (l + r) >> 1;
        if (solve(mid)) {
            r = mid;
        } else {
            l = mid + 1;
        }
    }
    cout << l << endl;
    // cout << solve(1) << endl;
    return 0;
}


#include <iostream>
#include <bitset>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;
using ll = unsigned long long;
ll n, k;
ll a[200001], b[200001];
vector<pair<int, ll>> t[200001];

bool check() {
    for (int i = 0; i < n; ++i) {
        ll e = a[i] / b[i];
        if (e < k - 1) {
            t[e].push_back(make_pair(i, a[i] % b[i]));
        }
    }
    int sum = 0;
    for (int i = 0; i < k; ++i) {
        sum += t[i].size();
        if (sum > i + 1) {
            return false;
        }
    }
    return true;
}

bool solve(ll x) {
    for (int i = 0; i < k; ++i) t[i].clear();
    for (int i = 0; i < n; ++i) {
        ll e = a[i] / b[i];
        if (e < k - 1) {
            t[e].push_back(make_pair(i, a[i] % b[i]));
        }
    }

    ll nxt = 0;
    for (ll i = 0; i < k - 1; ++i) {
        while (t[nxt].empty() && nxt < k - 1) {
            nxt++;
        }
        if (nxt == k - 1) return true;
        auto &p = t[nxt].back();
        t[nxt].pop_back();
        ll u = p.first;
        long long v = p.second;
        v = v + (nxt - i) * b[u] + x - b[u];
        if (v >= 0) {
            ll e = (i + 1) + v / b[u];
            if (e < k - 1) {
                t[e].push_back(make_pair(u, v % b[u]));
            }
        } else {
            return false;
        }

        if (!t[i].empty()) {
            return false;
        }
    }
    return true;
}

int main() {
    cin >> n >> k;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    for (int i = 0; i < n; ++i) {
        cin >> b[i];
    }
    if (!check()) {
        cout << "-1\n";
        return 0;
    }
    ll l = 0, r = 1 << 12;
    while (l < r) {
        ll mid = (l + r) >> 1;
        if (n == 1000 && k == 1000) {
            cout << mid << endl;
        }
        if (solve(mid)) {
            r = mid;
        } else {
            l = mid + 1;
        }
    }
    cout << l << endl;
    // cout << solve(1) << endl;
    return 0;
}


#include <iostream>
#include <bitset>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;
using ll = unsigned long long;
ll n, k;
ll a[200001], b[200001];
vector<pair<int, ll>> t[200001];

bool check() {
    for (int i = 0; i < n; ++i) {
        ll e = a[i] / b[i];
        if (e < k - 1) {
            t[e].push_back(make_pair(i, a[i] % b[i]));
        }
    }
    int sum = 0;
    for (int i = 0; i < k; ++i) {
        sum += t[i].size();
        if (sum > i + 1) {
            return false;
        }
    }
    return true;
}

bool solve(ll x) {
    for (int i = 0; i < k; ++i) t[i].clear();
    for (int i = 0; i < n; ++i) {
        ll e = a[i] / b[i];
        if (e < k - 1) {
            t[e].push_back(make_pair(i, a[i] % b[i]));
        }
    }

    ll nxt = 0;
    for (ll i = 0; i < k - 1; ++i) {
        while (t[nxt].empty() && nxt < k - 1) {
            nxt++;
        }
        if (nxt == k - 1) return true;
        auto &p = t[nxt].back();
        t[nxt].pop_back();
        ll u = p.first;
        long long v = p.second;
        v = v + (nxt - i) * b[u] + x - b[u];
        if (v >= 0) {
            ll e = (i + 1) + v / b[u];
            if (e < k - 1) {
                t[e].push_back(make_pair(u, v % b[u]));
            }
        } else {
            return false;
        }

        if (!t[i].empty()) {
            return false;
        }
    }
    return true;
}

int main() {
    cin >> n >> k;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    for (int i = 0; i < n; ++i) {
        cin >> b[i];
    }
    if (!check()) {
        cout << "-1\n";
        return 0;
    }
    ll l = 0, r = (unsigned long long)1 << 41;
    int cnt = 0;
    while (l < r) {
        ll mid = (l + r) >> 1;
        // if (n == 1000 && k == 1000) {
        //     cout << cnt++ << " " << l << " " << r << " " << mid << endl;
        // }
        if (solve(mid)) {
            r = mid;
        } else {
            l = mid + 1;
        }
    }
    cout << l << endl;
    // cout << solve(1) << endl;
    return 0;
}


#include <iostream>
#include <bitset>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;
using ll = unsigned long long;
ll n, k;
ll a[200001], b[200001];
vector<pair<int, ll>> t[200001];

bool check() {
    for (int i = 0; i < n; ++i) {
        ll e = a[i] / b[i];
        if (e < k - 1) {
            t[e].push_back(make_pair(i, a[i] % b[i]));
        }
    }
    int sum = 0;
    for (int i = 0; i < k; ++i) {
        sum += t[i].size();
        if (sum > i + 1) {
            return false;
        }
    }
    return true;
}

bool solve(ll x) {
    for (int i = 0; i < k; ++i) t[i].clear();
    for (int i = 0; i < n; ++i) {
        ll e = a[i] / b[i];
        if (e < k - 1) {
            t[e].push_back(make_pair(i, a[i] % b[i]));
        }
    }

    ll nxt = 0;
    for (ll i = 0; i < k - 1; ++i) {
        while (t[nxt].empty() && nxt < k - 1) {
            nxt++;
        }
        if (nxt == k - 1) return true;
        auto &p = t[nxt].back();
        t[nxt].pop_back();
        ll u = p.first;
        long long v = p.second;
        v = v + (nxt - i) * b[u] + x - b[u];
        if (v >= 0) {
            ll e = (i + 1) + v / b[u];
            if (e < k - 1) {
                t[e].push_back(make_pair(u, v % b[u]));
            }
        } else {
            return false;
        }

        if (!t[i].empty()) {
            return false;
        }
    }
    return true;
}

int main() {
    cin >> n >> k;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    for (int i = 0; i < n; ++i) {
        cin >> b[i];
    }
    if (!check()) {
        cout << "-1\n";
        return 0;
    }
    ll l = 0, r = (unsigned long long)1 << 40;
    int cnt = 0;
    while (l < r) {
        ll mid = (l + r) >> 1;
        // if (n == 1000 && k == 1000) {
        //     cout << cnt++ << " " << l << " " << r << " " << mid << endl;
        // }
        if (solve(mid)) {
            r = mid;
        } else {
            l = mid + 1;
        }
    }
    cout << l << endl;
    // cout << solve(1) << endl;
    return 0;
}


#include <iostream>
#include <bitset>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;
using ll = unsigned long long;
ll n, k;
ll a[200001], b[200001];
vector<pair<int, ll>> t[200001];

bool check() {
    for (int i = 0; i < n; ++i) {
        ll e = a[i] / b[i];
        if (e < k - 1) {
            t[e].push_back(make_pair(i, a[i] % b[i]));
        }
    }
    int sum = 0;
    for (int i = 0; i < k; ++i) {
        sum += t[i].size();
        if (sum > i + 1) {
            return false;
        }
    }
    return true;
}

bool solve(ll x) {
    for (int i = 0; i < k; ++i) t[i].clear();
    for (int i = 0; i < n; ++i) {
        ll e = a[i] / b[i];
        if (e < k - 1) {
            t[e].push_back(make_pair(i, a[i] % b[i]));
        }
    }

    ll nxt = 0;
    for (ll i = 0; i < k - 1; ++i) {
        while (t[nxt].empty() && nxt < k - 1) {
            nxt++;
        }
        if (nxt == k - 1) return true;
        auto &p = t[nxt].back();
        t[nxt].pop_back();
        ll u = p.first;
        long long v = p.second;
        v = v + (nxt - i) * b[u] + x - b[u];
        if (v >= 0) {
            ll e = (i + 1) + v / b[u];
            if (e < k - 1) {
                t[e].push_back(make_pair(u, v % b[u]));
            }
        } else {
            return false;
        }

        if (!t[i].empty()) {
            return false;
        }
    }
    return true;
}

int main() {
    cin >> n >> k;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    for (int i = 0; i < n; ++i) {
        cin >> b[i];
    }
    if (!check()) {
        cout << "-1\n";
        return 0;
    }
    ll l = 0, r = 1 << 11;
    int cnt = 0;
    while (l < r) {
        ll mid = (l + r) >> 1;
        if (n == 1000 && k == 1000) {
            cout << cnt++ << " " << l << " " << r << " " << mid << endl;
        }
        if (solve(mid)) {
            r = mid;
        } else {
            l = mid + 1;
        }
    }
    cout << l << endl;
    // cout << solve(1) << endl;
    return 0;
}


#include <iostream>
#include <bitset>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;
using ll = unsigned long long;
ll n, k;
ll a[200001], b[200001];
vector<pair<int, ll>> t[200001];

bool check() {
    for (int i = 0; i < n; ++i) {
        ll e = a[i] / b[i];
        if (e < k - 1) {
            t[e].push_back(make_pair(i, a[i] % b[i]));
        }
    }
    int sum = 0;
    for (int i = 0; i < k; ++i) {
        sum += t[i].size();
        if (sum > i + 1) {
            return false;
        }
    }
    return true;
}

bool solve(ll x) {
    for (int i = 0; i < k; ++i) t[i].clear();
    for (int i = 0; i < n; ++i) {
        ll e = a[i] / b[i];
        if (e < k - 1) {
            t[e].push_back(make_pair(i, a[i] % b[i]));
        }
    }

    ll nxt = 0;
    for (ll i = 0; i < k; ++i) {
        while (t[nxt].empty() && nxt < k - 1) {
            nxt++;
        }
        if (nxt == k - 1) return true;
        auto &p = t[nxt].back();
        t[nxt].pop_back();
        ll u = p.first;
        ll v = p.second;
        v = v + (nxt - i) * b[u] + x - b[u];
        if (v >= 0) {
            ll e = (i + 1) + v / b[u];
            if (e < k - 1) {
                t[e].push_back(make_pair(u, v % b[u]));
            }
        } else {
            return false;
        }

        if (!t[i].empty()) {
            return false;
        }
    }
    return true;
}

int main() {
    cin >> n >> k;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    for (int i = 0; i < n; ++i) {
        cin >> b[i];
    }
    if (!check()) {
        cout << "-1\n";
        return 0;
    }
    ll l = 0, r = 1 << 12;
    while (l < r) {
        ll mid = (l + r) >> 1;
        if (solve(mid)) {
            r = mid;
        } else {
            l = mid + 1;
        }
    }
    cout << l << endl;
    // cout << solve(1) << endl;
    return 0;
}


#include <iostream>
#include <bitset>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;
using ll = unsigned long long;
ll n, k;
ll a[200001], b[200001];
vector<pair<int, ll>> t[200001];

bool check() {
    for (int i = 0; i < n; ++i) {
        ll e = a[i] / b[i];
        if (e < k - 1) {
            t[e].push_back(make_pair(i, a[i] % b[i]));
        }
    }
    int sum = 0;
    for (int i = 0; i < k; ++i) {
        sum += t[i].size();
        if (sum > i + 1) {
            return false;
        }
    }
    return true;
}

bool solve(ll x) {
    for (int i = 0; i < k; ++i) t[i].clear();
    for (int i = 0; i < n; ++i) {
        ll e = a[i] / b[i];
        if (e < k - 1) {
            t[e].push_back(make_pair(i, a[i] % b[i]));
        }
    }

    ll nxt = 0;
    for (ll i = 0; i < k - 1; ++i) {
        while (t[nxt].empty() && nxt < k - 1) {
            nxt++;
        }
        if (nxt == k - 1) return true;
        auto &p = t[nxt].back();
        t[nxt].pop_back();
        ll u = p.first;
        long long v = p.second;
        v = v + (nxt - i) * b[u] + x - b[u];
        if (v >= 0) {
            ll e = (i + 1) + v / b[u];
            if (e < k - 1) {
                t[e].push_back(make_pair(u, v % b[u]));
            }
        } else {
            return false;
        }

        if (!t[i].empty()) {
            return false;
        }
    }
    return true;
}

int main() {
    cin >> n >> k;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    for (int i = 0; i < n; ++i) {
        cin >> b[i];
    }
    if (!check()) {
        cout << "-1\n";
        return 0;
    }
    ll l = 0, r = 1 << 12;
    int cnt = 0;
    while (l < r) {
        ll mid = (l + r) >> 1;
        if (n == 1000 && k == 1000) {
            cout << cnt++ << " " << l << " " << r << " " << mid << endl;
        }
        if (solve(mid)) {
            r = mid;
        } else {
            l = mid + 1;
        }
    }
    cout << l << endl;
    // cout << solve(1) << endl;
    return 0;
}


#include <iostream>
#include <bitset>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;
using ll = unsigned long long;
ll n, k;
ll a[200001], b[200001];
vector<pair<int, ll>> t[200001];

bool check() {
    for (int i = 0; i < n; ++i) {
        ll e = a[i] / b[i];
        if (e < k - 1) {
            t[e].push_back(make_pair(i, a[i] % b[i]));
        }
    }
    int sum = 0;
    for (int i = 0; i < k; ++i) {
        sum += t[i].size();
        if (sum > i + 1) {
            return false;
        }
    }
    return true;
}

bool solve(ll x) {
    for (int i = 0; i < k; ++i) t[i].clear();
    for (int i = 0; i < n; ++i) {
        ll e = a[i] / b[i];
        if (e < k - 1) {
            t[e].push_back(make_pair(i, a[i] % b[i]));
        }
    }

    ll nxt = 0;
    for (ll i = 0; i < k - 1; ++i) {
        while (t[nxt].empty() && nxt < k - 1) {
            nxt++;
        }
        if (nxt == k - 1) return true;
        auto &p = t[nxt].back();
        t[nxt].pop_back();
        ll u = p.first;
        long long v = p.second;
        v = v + (nxt - i) * b[u] + x - b[u];
        if (v >= 0) {
            ll e = (i + 1) + v / b[u];
            if (e < k - 1) {
                t[e].push_back(make_pair(u, v % b[u]));
            }
        } else {
            return false;
        }

        if (!t[i].empty()) {
            return false;
        }
    }
    return true;
}

int main() {
    cin >> n >> k;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    for (int i = 0; i < n; ++i) {
        cin >> b[i];
    }
    if (!check()) {
        cout << "-1\n";
        return 0;
    }
    ll l = 0, r = 1 << 40;
    int cnt = 0;
    while (l < r) {
        ll mid = (l + r) >> 1;
        // if (n == 1000 && k == 1000) {
        //     cout << cnt++ << " " << l << " " << r << " " << mid << endl;
        // }
        if (solve(mid)) {
            r = mid;
        } else {
            l = mid + 1;
        }
    }
    cout << l << endl;
    // cout << solve(1) << endl;
    return 0;
}


#include <iostream>
#include <bitset>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;
using ll = long long;
ll n, k;
ll a[200001], b[200001];
vector<pair<int, ll>> t[200001];

bool check() {
    for (int i = 0; i < n; ++i) {
        ll e = a[i] / b[i];
        if (e < k - 1) {
            t[e].push_back(make_pair(i, a[i] % b[i]));
        }
    }
    int sum = 0;
    for (int i = 0; i < k; ++i) {
        sum += t[i].size();
        if (sum > i + 1) {
            return false;
        }
    }
    return true;
}

bool solve(ll x) {
    for (int i = 0; i < k; ++i) t[i].clear();
    for (int i = 0; i < n; ++i) {
        ll e = a[i] / b[i];
        if (e < k - 1) {
            t[e].push_back(make_pair(i, a[i] % b[i]));
        }
    }

    ll nxt = 0;
    for (ll i = 0; i < k; ++i) {
        while (t[nxt].empty() && nxt < k - 1) nxt++;
        if (nxt == k - 1) return true;
        auto &p = t[nxt].back();
        t[nxt].pop_back();
        ll u = p.first;
        ll v = p.second;
        v = v + (nxt - i) * b[u] + x - b[u];
        if (v >= 0) {
            ll e = (i + 1) + v / b[u];
            if (e < k - 1) {
                t[e].push_back(make_pair(u, v % b[u]));
            }
        } else {
            return false;
        }

        if (!t[i].empty()) {
            return false;
        }
    }
    return true;
}

int main() {
    cin >> n >> k;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    for (int i = 0; i < n; ++i) {
        cin >> b[i];
    }
    if (!check()) {
        cout << "-1\n";
        return 0;
    }
    ll l = 0, r = 1 << 12;
    while (l < r) {
        ll mid = (l + r) >> 1;
        if (solve(mid)) {
            r = mid;
        } else {
            l = mid + 1;
        }
    }
    cout << l << endl;
    // cout << solve(1) << endl;
    return 0;
}


#include <iostream>
#include <bitset>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;
using ll = long long;
int n, k;
ll a[200001], b[200001];
vector<pair<int, int>> t[200001];

bool check() {
    for (int i = 0; i < n; ++i) {
        int e = a[i] / b[i];
        if (e < k - 1) {
            t[e].push_back(make_pair(i, a[i] % b[i]));
        }
    }
    int sum = 0;
    for (int i = 0; i < k; ++i) {
        sum += t[i].size();
        if (sum > i + 1) {
            return false;
        }
    }
    return true;
}

bool solve(ll x) {
    for (int i = 0; i < k; ++i) t[i].clear();
    for (int i = 0; i < n; ++i) {
        int e = a[i] / b[i];
        if (e < k - 1) {
            t[e].push_back(make_pair(i, a[i] % b[i]));
        }
    }

    int nxt = 0;
    for (int i = 0; i < k; ++i) {
        while (t[nxt].empty() && nxt < k - 1) nxt++;
        if (nxt == k - 1) return true;
        auto &p = t[nxt].back();
        t[nxt].pop_back();
        ll u = p.first;
        ll v = p.second;
        v = v + (nxt - i) * b[u] + x - b[u];
        // cout << endl;
        if (v >= 0) {
            ll e = (ll)(i + 1) + v / b[u];
            // cout << e << " ";
            if (e < k - 1) {
                t[e].push_back(make_pair(u, v % b[u]));
                // cout << i << " " << e << " " << u << " " << v << endl;
            }
        } else {
            return false;
        }

        if (!t[i].empty()) {
            return false;
        }
    }
    return true;
}

int main() {
    cin >> n >> k;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    for (int i = 0; i < n; ++i) {
        cin >> b[i];
    }
    if (!check()) {
        cout << "-1\n";
        return 0;
    }
    ll l = 0, r = 1 << 12;
    while (l < r) {
        ll mid = (l + r) >> 1;
        if (solve(mid)) {
            r = mid;
        } else {
            l = mid + 1;
        }
    }
    cout << l << endl;
    // cout << solve(1) << endl;
    return 0;
}


#include <iostream>
#include <bitset>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;
using ll = long long;
int n, k;
ll a[200001], b[200001];
vector<pair<int, int>> t[200001];

bool check() {
    for (int i = 0; i < n; ++i) {
        int e = a[i] / b[i];
        if (e < k - 1) {
            t[e].push_back(make_pair(i, a[i] % b[i]));
        }
    }
    int sum = 0;
    for (int i = 0; i < k; ++i) {
        sum += t[i].size();
        if (sum > i + 1) {
            return false;
        }
    }
    return true;
}

bool solve(ll x) {
    for (int i = 0; i < k; ++i) t[i].clear();
    for (int i = 0; i < n; ++i) {
        int e = a[i] / b[i];
        if (e < k - 1) {
            t[e].push_back(make_pair(i, a[i] % b[i]));
        }
    }

    int nxt = 0;
    for (int i = 0; i < k; ++i) {
        while (t[nxt].empty() && nxt < k) nxt++;
        if (nxt > k) return true;
        auto &p = t[nxt].back();
        t[nxt].pop_back();
        ll u = p.first;
        ll v = p.second;
        v = v + (nxt - i) * b[u] + x - b[u];
        // cout << endl;
        if (v >= 0) {
            ll e = (ll)(i + 1) + v / b[u];
            // cout << e << " ";
            if (e < k - 1) {
                t[e].push_back(make_pair(u, v % b[u]));
                // cout << i << " " << e << " " << u << " " << v << endl;
            }
        } else {
            return false;
        }

        if (!t[i].empty()) {
            return false;
        }
    }
    return true;
}

int main() {
    cin >> n >> k;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    for (int i = 0; i < n; ++i) {
        cin >> b[i];
    }
    if (!check()) {
        cout << "-1\n";
        return 0;
    }
    ll l = 0, r = 1 << 12;
    while (l < r) {
        ll mid = (l + r) >> 1;
        if (solve(mid)) {
            r = mid;
        } else {
            l = mid + 1;
        }
    }
    cout << l << endl;
    // cout << solve(1) << endl;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <queue>
using namespace std;

typedef long long ll;
typedef pair<ll,ll> pll;
const ll INF = 1e18;
const int N = 2e5;

int n, T;
ll a[N], b[N];

ll calc(ll a, ll b)
{
    return a / b;
}
bool check(ll x)
{
    priority_queue< pair<ll,pll> > Q;
    for (int i = 0; i < n; ++i)
        Q.push({-calc(a[i], b[i]), {a[i], b[i]}});

    for (int t = 0; t < T; ++t)
    {
        auto e = Q.top();
        Q.pop();
        static ll a, b;
        a = e.second.first;
        b = e.second.second;
        if (a - t * b < 0)
            return false;
        a += x;
        Q.push({-calc(a, b), {a, b}});
    }

    return true;
}

int main()
{

#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
#endif

    scanf("%d%d", &n, &T);

    for (int i = 0; i < n; ++i)
        scanf("%lld", a + i);
    for (int i = 0; i < n; ++i)
        scanf("%lld", b + i);

    ll l = 0, r = INF, m;
    while(r - l > 1)
    {
        m = (l + r) / 2;
        if (check(m))
            r = m;
        else
            l = m;
    }

    if (r == INF)
        printf("-1");
    else
        printf("%lld", r);
}


#include <iostream>
#include <cstdio>
#include <queue>
using namespace std;

typedef long long ll;
typedef pair<ll,ll> pll;
const ll INF = 1e12 + 5;
const int N = 2e5;

int n, T;
ll a[N], b[N];

ll calc(ll a, ll b)
{
    return a / b;
}
bool check(ll x)
{
    priority_queue< pair<ll,pll> > Q;
    for (ll *it = a, *e = a + n, *jt = b; it != e; ++it, ++jt)
        Q.push({-calc(*it, *jt), {*it, *jt}});

    for (int t = 0; t < T; ++t)
    {
        pair<ll,pll> e = Q.top();
        Q.pop();
        static ll a, b;
        a = e.second.first;
        b = e.second.second;
        if (a < t * b)
            return false;
        a += x;
        Q.push({-calc(a, b), {a, b}});
    }

    return true;
}

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

    for (ll *it = a, *e = a + n; it != e; ++it)
        scanf("%lld", it);
    for (ll *it = b, *e = b + n; it != e; ++it)
        scanf("%lld", it);

    ll l = -1, r = INF, m;
    while(r - l > 1)
    {
        m = (l + r) / 2;
        if (check(m))
            r = m;
        else
            l = m;
    }

    if (r == INF)
        printf("-1");
    else
        printf("%lld", r);
}


#include <cassert>
#include <cstdio>

/** Interface */

inline int readInt();
inline int readUInt();
inline void readWord( char *s );
inline int fast_readchar(); // you may use readchar() instead of it

inline void writeInt( int x );
inline void fast_writechar( int x ); // you may use putchar() instead of it
inline void writeWord( const char *s );
inline void fast_flush();

/** Read */

static const int buf_size = 4096;

inline int fast_readchar() {
  static char buf[buf_size];
  static int len = 0, pos = 0;
  if (pos == len)
    pos = 0, len = fread(buf, 1, buf_size, stdin);
  if (pos == len)
    return -1;
  return buf[pos++];
}

inline int readUInt() {
  int c = fast_readchar(), x = 0;
  while (c <= 32)
    c = fast_readchar();
  while ('0' <= c && c <= '9')
    x = x * 10 + c - '0', c = fast_readchar();
  return x;
}

inline int readInt() {
  int s = 1, c = fast_readchar();
  int x = 0;
  while (c <= 32)
    c = fast_readchar();
  if (c == '-')
    s = -1, c = fast_readchar();
  while ('0' <= c && c <= '9')
    x = x * 10 + c - '0', c = fast_readchar();
  return x * s;
}

inline void readWord( char *s ) {
  int c = fast_readchar();
  while (c <= 32)
    c = fast_readchar();
  while (c > 32)
    *s++ = c, c = fast_readchar();
  *s = 0;
}

/** Write */

static int write_pos = 0;
static char write_buf[buf_size];

inline void fast_writechar( int x ) {
  if (write_pos == buf_size)
    fwrite(write_buf, 1, buf_size, stdout), write_pos = 0;
  write_buf[write_pos++] = x;
}

inline void fast_flush() {
  if (write_pos)
    fwrite(write_buf, 1, write_pos, stdout), write_pos = 0;
}

inline void writeInt( int x ) {
  if (x < 0)
    fast_writechar('-'), x = -x;

  char s[24];
  int n = 0;
  while (x || !n)
    s[n++] = '0' + x % 10, x /= 10;
  while (n--)
    fast_writechar(s[n]);
}

inline void writeWord( const char *s ) {
  while (*s)
    fast_writechar(*s++);
}

#include <iostream>
#include <cstdio>
#include <queue>
using namespace std;

typedef long long ll;
typedef pair<ll,ll> pll;
const ll INF = 2e12 + 5;
const int N = 2e5;

int n, T;
ll a[N], b[N];

ll calc(ll a, ll b)
{
    return a / b;
}
bool check(ll x)
{
    priority_queue< pair<ll,pll> > Q;
    for (int i = 0; i < n; ++i)
        Q.push({-calc(a[i], b[i]), {a[i], b[i]}});

    for (int t = 0; t < T; ++t)
    {
        auto e = Q.top();
        Q.pop();
        static ll a, b;
        a = e.second.first;
        b = e.second.second;
        if (a - t * b < 0)
            return false;
        a += x;
        Q.push({-calc(a, b), {a, b}});
    }

    return true;
}

int main()
{
    n = readInt();
    T = readInt();

    for (ll *it = a, *e = a + n; it != e; ++it)
        *it = readInt();
    for (ll *it = b, *e = b + n; it != e; ++it)
        *it = readInt();

    ll l = -1, r = INF, m;
    while(r - l > 1)
    {
        m = (l + r) / 2;
        if (check(m))
            r = m;
        else
            l = m;
    }

    if (r == INF)
        writeInt(-1);
    else
        writeInt(r);
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <cstring>
#include<string>
#include <unordered_map>
#include <queue>
#include <complex>
#include<map>
#include<deque>
#include <cstdio>
#include <cstdlib>
#include <utility>
#include <cmath>
#include<random>
#include <cassert>
#include <unordered_set>
#include<ctime>
#include <queue>
//#pragma once
#define VERSION "0.1.4"

#include <cassert>
#include <cstdio>
#include <algorithm>

/** Fast allocation */

int allocator_pos = 0;
char allocator_memory[(int)4e7];
inline void * operator new (size_t n) {
	char *res = allocator_memory + allocator_pos;
	allocator_pos += n;
	//assert(allocator_pos <= (int)FAST_ALLOCATOR_MEMORY);
	return (void *)res;
}
inline void operator delete (void *) noexcept { }

template <class T = long long> inline T readInt();
inline double readDouble();
inline long long readUInt();
inline int readChar(); // first non-blank character
inline void readWord(char *s);
inline bool readLine(char *s); // do not save '\n'
inline bool isEof();
inline int getChar();
inline int peekChar();
inline bool seekEof();
inline void skipBlanks();

template <class T> inline void writeInt(T x, char end = 0, int len = -1);
inline void writeChar(int x);
inline void writeWord(const char *s);
inline void writeDouble(double x, int len = 0);
inline void flush();

static struct buffer_flusher_t {
	~buffer_flusher_t() {
		flush();
	}
} buffer_flusher;

/** Read */

static const int buf_size = 4096;

static unsigned char buf[buf_size];
static int buf_len = 0, buf_pos = 0;

inline bool isEof() {
	if (buf_pos == buf_len) {
		buf_pos = 0, buf_len = fread(buf, 1, buf_size, stdin);
		if (buf_pos == buf_len)
			return 1;
	}
	return 0;
}

inline int getChar() {
	return isEof() ? -1 : buf[buf_pos++];
}

inline int peekChar() {
	return isEof() ? -1 : buf[buf_pos];
}

inline bool seekEof() {
	int c;
	while ((c = peekChar()) != -1 && c <= 32)
		buf_pos++;
	return c == -1;
}

inline void skipBlanks() {
	while (!isEof() && buf[buf_pos] <= 32U)
		buf_pos++;
}

inline int readChar() {
	int c = getChar();
	while (c != -1 && c <= 32)
		c = getChar();
	return c;
}

inline long long readUInt() {
	int c = readChar(), x = 0;
	while ('0' <= c && c <= '9')
		x = x * 10 + c - '0', c = getChar();
	return x;
}

template <class T>
inline T readInt() {
	int s = 1, c = readChar();
	T x = 0;
	if (c == '-')
		s = -1, c = getChar();
	else if (c == '+')
		c = getChar();
	while ('0' <= c && c <= '9')
		x = x * 10 + c - '0', c = getChar();
	return s == 1 ? x : -x;
}

inline double readDouble() {
	int s = 1, c = readChar();
	double x = 0;
	if (c == '-')
		s = -1, c = getChar();
	while ('0' <= c && c <= '9')
		x = x * 10 + c - '0', c = getChar();
	if (c == '.') {
		c = getChar();
		double coef = 1;
		while ('0' <= c && c <= '9')
			x += (c - '0') * (coef *= 1e-1), c = getChar();
	}
	return s == 1 ? x : -x;
}

inline void readWord(char *s) {
	int c = readChar();
	while (c > 32)
		*s++ = c, c = getChar();
	*s = 0;
}

inline bool readLine(char *s) {
	int c = getChar();
	while (c != '\n' && c != -1)
		*s++ = c, c = getChar();
	*s = 0;
	return c != -1;
}

/** Write */

static int write_buf_pos = 0;
static char write_buf[buf_size];

inline void writeChar(int x) {
	if (write_buf_pos == buf_size)
		fwrite(write_buf, 1, buf_size, stdout), write_buf_pos = 0;
	write_buf[write_buf_pos++] = x;
}

inline void flush() {
	if (write_buf_pos)
		fwrite(write_buf, 1, write_buf_pos, stdout), write_buf_pos = 0;
}

template <class T>
inline void writeInt(T x, char end, int output_len) {
	if (x < 0)
		writeChar('-'), x = -x;

	char s[24];
	int n = 0;
	while (x || !n)
		s[n++] = '0' + x % 10, x /= 10;
	while (n < output_len)
		s[n++] = '0';
	while (n--)
		writeChar(s[n]);
	if (end)
		writeChar(end);
}

inline void writeWord(const char *s) {
	while (*s)
		writeChar(*s++);
}

inline void writeDouble(double x, int output_len) {
	if (x < 0)
		writeChar('-'), x = -x;
	int t = (int)x;
	writeInt(t), x -= t;
	writeChar('.');
	for (int i = output_len - 1; i > 0; i--) {
		x *= 10;
		t = std::min(9, (int)x);
		writeChar('0' + t), x -= t;
	}
	x *= 10;
	t = std::min(9, (int)(x + 0.5));
	writeChar('0' + t);
}

using namespace std;

typedef long long ll;
typedef pair<ll,ll> pll;
const ll INF = 1e13;
const int N = 2e5;

int n, T;
ll a[N], b[N];

ll calc(ll a, ll b)
{
    return a / b;
}
bool check(ll x)
{
    priority_queue< pair<ll,pll> > Q;
    for (int i = 0; i < n; ++i)
        Q.push({-calc(a[i], b[i]), {a[i], b[i]}});

    for (int t = 0; t < T; ++t)
    {
        auto e = Q.top();
        Q.pop();
        static ll a, b;
        a = e.second.first;
        b = e.second.second;
        if (a - t * b < 0)
            return false;
        a += x;
        Q.push({-calc(a, b), {a, b}});
    }

    return true;
}

int main()
{

#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
#endif

    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    n = readInt();
    T = readInt();

    for (int i = 0; i < n; ++i)
        a[i] = readInt();
    for (int i = 0; i < n; ++i)
        b[i] = readInt();

    ll l = -1, r = INF, m;
    while(r - l > 1)
    {
        m = (l + r) / 2;
        if (check(m))
            r = m;
        else
            l = m;
    }

    if (r == INF)
        writeInt(-1);
    else
        writeInt(r);
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <cstring>
#include<string>
#include <unordered_map>
#include <queue>
#include <complex>
#include<map>
#include<deque>
#include <cstdio>
#include <cstdlib>
#include <utility>
#include <cmath>
#include<random>
#include <cassert>
#include <unordered_set>
#include<ctime>
#include <queue>
//#pragma once
#define VERSION "0.1.4"

#include <cassert>
#include <cstdio>
#include <algorithm>

/** Fast allocation */

int allocator_pos = 0;
char allocator_memory[(int)4e7];
inline void * operator new (size_t n) {
	char *res = allocator_memory + allocator_pos;
	allocator_pos += n;
	//assert(allocator_pos <= (int)FAST_ALLOCATOR_MEMORY);
	return (void *)res;
}
inline void operator delete (void *) noexcept { }

template <class T = long long> inline T readInt();
inline double readDouble();
inline long long readUInt();
inline int readChar(); // first non-blank character
inline void readWord(char *s);
inline bool readLine(char *s); // do not save '\n'
inline bool isEof();
inline int getChar();
inline int peekChar();
inline bool seekEof();
inline void skipBlanks();

template <class T> inline void writeInt(T x, char end = 0, int len = -1);
inline void writeChar(int x);
inline void writeWord(const char *s);
inline void writeDouble(double x, int len = 0);
inline void flush();

static struct buffer_flusher_t {
	~buffer_flusher_t() {
		flush();
	}
} buffer_flusher;

/** Read */

static const int buf_size = 4096;

static unsigned char buf[buf_size];
static int buf_len = 0, buf_pos = 0;

inline bool isEof() {
	if (buf_pos == buf_len) {
		buf_pos = 0, buf_len = fread(buf, 1, buf_size, stdin);
		if (buf_pos == buf_len)
			return 1;
	}
	return 0;
}

inline int getChar() {
	return isEof() ? -1 : buf[buf_pos++];
}

inline int peekChar() {
	return isEof() ? -1 : buf[buf_pos];
}

inline bool seekEof() {
	int c;
	while ((c = peekChar()) != -1 && c <= 32)
		buf_pos++;
	return c == -1;
}

inline void skipBlanks() {
	while (!isEof() && buf[buf_pos] <= 32U)
		buf_pos++;
}

inline int readChar() {
	int c = getChar();
	while (c != -1 && c <= 32)
		c = getChar();
	return c;
}

inline long long readUInt() {
	int c = readChar(), x = 0;
	while ('0' <= c && c <= '9')
		x = x * 10 + c - '0', c = getChar();
	return x;
}

template <class T>
inline T readInt() {
	int s = 1, c = readChar();
	T x = 0;
	if (c == '-')
		s = -1, c = getChar();
	else if (c == '+')
		c = getChar();
	while ('0' <= c && c <= '9')
		x = x * 10 + c - '0', c = getChar();
	return s == 1 ? x : -x;
}

inline double readDouble() {
	int s = 1, c = readChar();
	double x = 0;
	if (c == '-')
		s = -1, c = getChar();
	while ('0' <= c && c <= '9')
		x = x * 10 + c - '0', c = getChar();
	if (c == '.') {
		c = getChar();
		double coef = 1;
		while ('0' <= c && c <= '9')
			x += (c - '0') * (coef *= 1e-1), c = getChar();
	}
	return s == 1 ? x : -x;
}

inline void readWord(char *s) {
	int c = readChar();
	while (c > 32)
		*s++ = c, c = getChar();
	*s = 0;
}

inline bool readLine(char *s) {
	int c = getChar();
	while (c != '\n' && c != -1)
		*s++ = c, c = getChar();
	*s = 0;
	return c != -1;
}

/** Write */

static int write_buf_pos = 0;
static char write_buf[buf_size];

inline void writeChar(int x) {
	if (write_buf_pos == buf_size)
		fwrite(write_buf, 1, buf_size, stdout), write_buf_pos = 0;
	write_buf[write_buf_pos++] = x;
}

inline void flush() {
	if (write_buf_pos)
		fwrite(write_buf, 1, write_buf_pos, stdout), write_buf_pos = 0;
}

template <class T>
inline void writeInt(T x, char end, int output_len) {
	if (x < 0)
		writeChar('-'), x = -x;

	char s[24];
	int n = 0;
	while (x || !n)
		s[n++] = '0' + x % 10, x /= 10;
	while (n < output_len)
		s[n++] = '0';
	while (n--)
		writeChar(s[n]);
	if (end)
		writeChar(end);
}

inline void writeWord(const char *s) {
	while (*s)
		writeChar(*s++);
}

inline void writeDouble(double x, int output_len) {
	if (x < 0)
		writeChar('-'), x = -x;
	int t = (int)x;
	writeInt(t), x -= t;
	writeChar('.');
	for (int i = output_len - 1; i > 0; i--) {
		x *= 10;
		t = std::min(9, (int)x);
		writeChar('0' + t), x -= t;
	}
	x *= 10;
	t = std::min(9, (int)(x + 0.5));
	writeChar('0' + t);
}

using namespace std;

typedef long long ll;
typedef pair<ll,ll> pll;
const ll INF = 1e12 + 5;
const int N = 2e5;

int n, T;
ll a[N], b[N];

ll calc(ll a, ll b)
{
    return a / b;
}
bool check(ll x)
{
    priority_queue< pair<ll,pll> > Q;
    for (int i = 0; i < n; ++i)
        Q.push({-calc(a[i], b[i]), {a[i], b[i]}});

    for (int t = 0; t < T; ++t)
    {
        auto e = Q.top();
        Q.pop();
        static ll a, b;
        a = e.second.first;
        b = e.second.second;
        if (a - t * b < 0)
            return false;
        a += x;
        Q.push({-calc(a, b), {a, b}});
    }

    return true;
}

int main()
{

#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
#endif

    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    cin >> n >> T;

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

    ll l = -1, r = INF, m;
    while(r - l > 1)
    {
        m = (l + r) / 2;
        if (check(m))
            r = m;
        else
            l = m;
    }

    if (r == INF)
        cout << -1;
    else
        cout << r;
}


#include <iostream>
#include <cstdio>
#include <queue>
using namespace std;

typedef long long ll;
typedef pair<ll,ll> pll;
const ll INF = 1e13;
const int N = 2e5;

int n, T;
ll a[N], b[N];

ll calc(ll a, ll b)
{
    return a / b;
}
bool check(ll x)
{
    priority_queue< pair<ll,pll> > Q;
    for (int i = 0; i < n; ++i)
        Q.push({-calc(a[i], b[i]), {a[i], b[i]}});

    for (int t = 0; t < T; ++t)
    {
        auto e = Q.top();
        Q.pop();
        static ll a, b;
        a = e.second.first;
        b = e.second.second;
        if (a - t * b < 0)
            return false;
        a += x;
        Q.push({-calc(a, b), {a, b}});
    }

    return true;
}

int main()
{

#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
#endif

    scanf("%d%d", &n, &T);

    for (int i = 0; i < n; ++i)
        scanf("%lld", a + i);
    for (int i = 0; i < n; ++i)
        scanf("%lld", b + i);

    ll l = -1, r = INF, m;
    while(r - l > 1)
    {
        m = (l + r) / 2;
        if (check(m))
            r = m;
        else
            l = m;
    }

    if (r == INF)
        printf("-1");
    else
        printf("%lld", r);
}


#include <iostream>
#include <cstdio>
#include <queue>
using namespace std;

typedef long long ll;
typedef pair<ll,ll> pll;
const ll INF = 1e12 + 5;
const int N = 2e5;

int n, T;
ll a[N], b[N];

ll calc(ll a, ll b)
{
    return a / b;
}
bool check(ll x)
{
    priority_queue< pair<ll,pll> > Q;
    for (ll *it = a, *e = a + n, *jt = b; it != e; ++it, ++jt)
        Q.push({-calc(*it, *jt), {*it, *jt}});

    for (int t = 0; t < T; ++t)
    {
        auto e = Q.top();
        Q.pop();
        static ll a, b;
        a = e.second.first;
        b = e.second.second;
        if (a < t * b)
            return false;
        a += x;
        Q.push({-calc(a, b), {a, b}});
    }

    return true;
}

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

    for (ll *it = a, *e = a + n; it != e; ++it)
        scanf("%lld", it);
    for (ll *it = b, *e = b + n; it != e; ++it)
        scanf("%lld", it);

    ll l = -1, r = INF, m;
    while(r - l > 1)
    {
        m = (l + r) / 2;
        if (check(m))
            r = m;
        else
            l = m;
    }

    if (r == INF)
        printf("-1");
    else
        printf("%lld", r);
}


#include <iostream>
#include <cstdio>
#include <queue>
using namespace std;

typedef long long ll;

/*<-------------------------------------------------------------->*/

#include <cassert>
#include <cstdio>

/** Interface */

inline ll readInt();
inline int readUInt();
inline void readWord( char *s );
inline int fast_readchar(); // you may use readchar() instead of it

inline void writeInt( int x );
inline void fast_writechar( int x ); // you may use putchar() instead of it
inline void writeWord( const char *s );
inline void fast_flush();

/** Read */

static const int buf_size = 4096;

inline int fast_readchar() {
  static char buf[buf_size];
  static int len = 0, pos = 0;
  if (pos == len)
    pos = 0, len = fread(buf, 1, buf_size, stdin);
  if (pos == len)
    return -1;
  return buf[pos++];
}

inline int readUInt() {
  int c = fast_readchar(), x = 0;
  while (c <= 32)
    c = fast_readchar();
  while ('0' <= c && c <= '9')
    x = x * 10 + c - '0', c = fast_readchar();
  return x;
}

inline ll readInt() {
  int s = 1, c = fast_readchar();
  ll x = 0;
  while (c <= 32)
    c = fast_readchar();
  if (c == '-')
    s = -1, c = fast_readchar();
  while ('0' <= c && c <= '9')
    x = x * 10 + c - '0', c = fast_readchar();
  return x * s;
}

inline void readWord( char *s ) {
  int c = fast_readchar();
  while (c <= 32)
    c = fast_readchar();
  while (c > 32)
    *s++ = c, c = fast_readchar();
  *s = 0;
}

/** Write */

static int write_pos = 0;
static char write_buf[buf_size];

inline void fast_writechar( int x ) {
  if (write_pos == buf_size)
    fwrite(write_buf, 1, buf_size, stdout), write_pos = 0;
  write_buf[write_pos++] = x;
}

inline void fast_flush() {
  if (write_pos)
    fwrite(write_buf, 1, write_pos, stdout), write_pos = 0;
}

inline void writeInt( ll x ) {
  if (x < 0)
    fast_writechar('-'), x = -x;

  char s[24];
  int n = 0;
  while (x || !n)
    s[n++] = '0' + x % 10, x /= 10;
  while (n--)
    fast_writechar(s[n]);
}

inline void writeWord( const char *s ) {
  while (*s)
    fast_writechar(*s++);
}

/*<-------------------------------------------------------------->*/

typedef pair<ll,ll> pll;
const ll INF = 2e12 + 5;
const int N = 2e5;

int n, T;
ll a[N], b[N];

ll calc(ll a, ll b)
{
    return a / b;
}
bool check(ll x)
{
    priority_queue< pair<ll,pll> > Q;
    for (int i = 0; i < n; ++i)
        Q.push({-calc(a[i], b[i]), {a[i], b[i]}});

    for (int t = 0; t < T; ++t)
    {
        auto e = Q.top();
        Q.pop();
        static ll a, b;
        a = e.second.first;
        b = e.second.second;
        if (a - b * t < 0)
            return false;
        a += x;
        Q.push({-calc(a, b), {a, b}});
    }

    return true;
}

int main()
{

#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
#endif // ONLINE_JUDGE

    n = readInt();
    T = readInt();

    for (ll *it = a, *e = a + n; it != e; ++it)
        *it = readInt();
    for (ll *it = b, *e = b + n; it != e; ++it)
        *it = readInt();

    ll l = -1, r = INF, m;
    while(r - l > 1)
    {
        m = (l + r) / 2;
        if (check(m))
            r = m;
        else
            l = m;
    }

    if (r == INF)
        writeInt(-1LL);
    else
        writeInt(r);

    fast_flush();
}


#include <iostream>
#include <cstdio>
#include <queue>
using namespace std;

typedef long long ll;
typedef pair<ll,ll> pll;
const ll INF = 1e13;
const int N = 2e5;

int n, T;
ll a[N], b[N];

ll calc(ll a, ll b)
{
    return a / b;
}
bool check(ll x)
{
    priority_queue< pair<ll,pll> > Q;
    for (int i = 0; i < n; ++i)
        Q.push({-((a[i] + b[i] - 1) / b[i]), {a[i], b[i]}});

    for (int t = 0; t < T; ++t)
    {
        auto e = Q.top();
        Q.pop();
        static ll a, b;
        a = e.second.first;
        b = e.second.second;
        if (a - t * b < 0)
            return false;
        a += x;
        Q.push({-calc(a, b), {a, b}});
    }

    return true;
}

int main()
{

#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
#endif

    scanf("%d%d", &n, &T);

    for (int i = 0; i < n; ++i)
        scanf("%lld", a + i);
    for (int i = 0; i < n; ++i)
        scanf("%lld", b + i);

    ll l = 0, r = INF, m;
    while(r - l > 1)
    {
        m = (l + r) / 2;
        if (check(m))
            r = m;
        else
            l = m;
    }

    if (r == INF)
        printf("-1");
    else
        printf("%lld", r);
}


#include <iostream>
#include <cstdio>
#include <queue>
using namespace std;

typedef long long ll;
typedef pair<ll,ll> pll;
const ll INF = 1e18;
const int N = 2e5;

int n, T;
ll a[N], b[N];

ll calc(ll a, ll b)
{
    return a / b;
}
bool check(ll x)
{
    priority_queue< pair<ll,pll> > Q;
    for (int i = 0; i < n; ++i)
        Q.push({-((a[i] + b[i] - 1) / b[i]), {a[i], b[i]}});

    for (int t = 0; t < T; ++t)
    {
        auto e = Q.top();
        Q.pop();
        static ll a, b;
        a = e.second.first;
        b = e.second.second;
        if (a - t * b < 0)
            return false;
        a += x;
        Q.push({-calc(a, b), {a, b}});
    }

    return true;
}

int main()
{

#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
#endif

    scanf("%d%d", &n, &T);

    for (int i = 0; i < n; ++i)
        scanf("%lld", a + i);
    for (int i = 0; i < n; ++i)
        scanf("%lld", b + i);

    ll l = 0, r = INF, m;
    while(r - l > 1)
    {
        m = (l + r) / 2;
        if (check(m))
            r = m;
        else
            l = m;
    }

    if (r == INF)
        printf("-1");
    else
        printf("%lld", r);
}


#include <iostream>
#include <cstdio>
#include <queue>
using namespace std;

typedef long long ll;
typedef pair<ll,ll> pll;
const ll INF = 1e12 + 5;
const int N = 2e5;

int n, T;
ll a[N], b[N];

ll calc(ll a, ll b)
{
    return a / b;
}
bool check(ll x)
{
    priority_queue< pair<ll,pll> > Q;
    for (int i = 0; i < n; ++i)
        Q.push({-calc(a[i], b[i]), {a[i], b[i]}});

    for (int t = 0; t < T; ++t)
    {
        auto e = Q.top();
        Q.pop();
        static ll a, b;
        a = e.second.first;
        b = e.second.second;
        if (a - t * b < 0)
            return false;
        a += x;
        Q.push({-calc(a, b), {a, b}});
    }

    return true;
}

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

    for (ll *it = a, *e = a + n; it != e; ++it)
        scanf("%lld", it);
    for (ll *it = b, *e = b + n; it != e; ++it)
        scanf("%lld", it);

    ll l = -1, r = INF, m;
    while(r - l > 1)
    {
        m = (l + r) / 2;
        if (check(m))
            r = m;
        else
            l = m;
    }

    if (r == INF)
        printf("-1");
    else
        printf("%lld", r);
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <cstring>
#include<string>
#include <unordered_map>
#include <queue>
#include <complex>
#include<map>
#include<deque>
#include <cstdio>
#include <cstdlib>
#include <utility>
#include <cmath>
#include<random>
#include <cassert>
#include <unordered_set>
#include<ctime>
#include <queue>
//#pragma once
#define VERSION "0.1.4"

#include <cassert>
#include <cstdio>
#include <algorithm>

/** Fast allocation */

int allocator_pos = 0;
char allocator_memory[(int)4e7];
inline void * operator new (size_t n) {
	char *res = allocator_memory + allocator_pos;
	allocator_pos += n;
	//assert(allocator_pos <= (int)FAST_ALLOCATOR_MEMORY);
	return (void *)res;
}
inline void operator delete (void *) noexcept { }

template <class T = long long> inline T readInt();
inline double readDouble();
inline long long readUInt();
inline int readChar(); // first non-blank character
inline void readWord(char *s);
inline bool readLine(char *s); // do not save '\n'
inline bool isEof();
inline int getChar();
inline int peekChar();
inline bool seekEof();
inline void skipBlanks();

template <class T> inline void writeInt(T x, char end = 0, int len = -1);
inline void writeChar(int x);
inline void writeWord(const char *s);
inline void writeDouble(double x, int len = 0);
inline void flush();

static struct buffer_flusher_t {
	~buffer_flusher_t() {
		flush();
	}
} buffer_flusher;

/** Read */

static const int buf_size = 4096;

static unsigned char buf[buf_size];
static int buf_len = 0, buf_pos = 0;

inline bool isEof() {
	if (buf_pos == buf_len) {
		buf_pos = 0, buf_len = fread(buf, 1, buf_size, stdin);
		if (buf_pos == buf_len)
			return 1;
	}
	return 0;
}

inline int getChar() {
	return isEof() ? -1 : buf[buf_pos++];
}

inline int peekChar() {
	return isEof() ? -1 : buf[buf_pos];
}

inline bool seekEof() {
	int c;
	while ((c = peekChar()) != -1 && c <= 32)
		buf_pos++;
	return c == -1;
}

inline void skipBlanks() {
	while (!isEof() && buf[buf_pos] <= 32U)
		buf_pos++;
}

inline int readChar() {
	int c = getChar();
	while (c != -1 && c <= 32)
		c = getChar();
	return c;
}

inline long long readUInt() {
	int c = readChar(), x = 0;
	while ('0' <= c && c <= '9')
		x = x * 10 + c - '0', c = getChar();
	return x;
}

template <class T>
inline T readInt() {
	int s = 1, c = readChar();
	T x = 0;
	if (c == '-')
		s = -1, c = getChar();
	else if (c == '+')
		c = getChar();
	while ('0' <= c && c <= '9')
		x = x * 10 + c - '0', c = getChar();
	return s == 1 ? x : -x;
}

inline double readDouble() {
	int s = 1, c = readChar();
	double x = 0;
	if (c == '-')
		s = -1, c = getChar();
	while ('0' <= c && c <= '9')
		x = x * 10 + c - '0', c = getChar();
	if (c == '.') {
		c = getChar();
		double coef = 1;
		while ('0' <= c && c <= '9')
			x += (c - '0') * (coef *= 1e-1), c = getChar();
	}
	return s == 1 ? x : -x;
}

inline void readWord(char *s) {
	int c = readChar();
	while (c > 32)
		*s++ = c, c = getChar();
	*s = 0;
}

inline bool readLine(char *s) {
	int c = getChar();
	while (c != '\n' && c != -1)
		*s++ = c, c = getChar();
	*s = 0;
	return c != -1;
}

/** Write */

static int write_buf_pos = 0;
static char write_buf[buf_size];

inline void writeChar(int x) {
	if (write_buf_pos == buf_size)
		fwrite(write_buf, 1, buf_size, stdout), write_buf_pos = 0;
	write_buf[write_buf_pos++] = x;
}

inline void flush() {
	if (write_buf_pos)
		fwrite(write_buf, 1, write_buf_pos, stdout), write_buf_pos = 0;
}

template <class T>
inline void writeInt(T x, char end, int output_len) {
	if (x < 0)
		writeChar('-'), x = -x;

	char s[24];
	int n = 0;
	while (x || !n)
		s[n++] = '0' + x % 10, x /= 10;
	while (n < output_len)
		s[n++] = '0';
	while (n--)
		writeChar(s[n]);
	if (end)
		writeChar(end);
}

inline void writeWord(const char *s) {
	while (*s)
		writeChar(*s++);
}

inline void writeDouble(double x, int output_len) {
	if (x < 0)
		writeChar('-'), x = -x;
	int t = (int)x;
	writeInt(t), x -= t;
	writeChar('.');
	for (int i = output_len - 1; i > 0; i--) {
		x *= 10;
		t = std::min(9, (int)x);
		writeChar('0' + t), x -= t;
	}
	x *= 10;
	t = std::min(9, (int)(x + 0.5));
	writeChar('0' + t);
}

using namespace std;

typedef long long ll;
typedef pair<ll,ll> pll;
const ll INF = 1e13;
const int N = 2e5;

int n, T;
ll a[N], b[N];

ll calc(ll a, ll b)
{
    return a / b;
}
bool check(ll x)
{
    priority_queue< pair<ll,pll> > Q;
    for (int i = 0; i < n; ++i)
        Q.push({-calc(a[i], b[i]), {a[i], b[i]}});

    for (int t = 0; t < T; ++t)
    {
        auto e = Q.top();
        Q.pop();
        static ll a, b;
        a = e.second.first;
        b = e.second.second;
        if (a - t * b < 0)
            return false;
        a += x;
        Q.push({-calc(a, b), {a, b}});
    }

    return true;
}

int main()
{

#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
#endif

    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    n = readInt();
    T = readInt();

    for (int i = 0; i < n; ++i)
        a[i] = readInt();
    for (int i = 0; i < n; ++i)
        b[i] = readInt();

    ll l = -1, r = INF, m;
    while(r - l > 1)
    {
        m = (l + r) / 2;
        if (check(m))
            r = m;
        else
            l = m;
    }

    if (r == INF)
        cout << -1;
    else
        cout << r;
}


#include <iostream>
#include <cstdio>
#include <queue>
using namespace std;

typedef long long ll;
typedef pair<ll,ll> pll;
const ll INF = 1e12 + 5;
const int N = 2e5;

int n, T;
ll a[N], b[N];

ll calc(ll a, ll b)
{
    return a / b;
}
bool check(ll x)
{
    priority_queue< pair<ll,pll> > Q;
    for (ll *it = a, *e = a + n, *jt = b; it != e; ++it, ++jt)
        Q.push({-calc(*it, *jt), {*it, *jt}});

    pair<ll,pll> e;
    ll a, b;
    for (int t = 0; t < T; ++t)
    {
        e = Q.top();
        Q.pop();
        a = e.second.first;
        b = e.second.second;
        if (a < t * b)
            return false;
        a += x;
        Q.push({-calc(a, b), {a, b}});
    }

    return true;
}

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

    for (ll *it = a, *e = a + n; it != e; ++it)
        scanf("%lld", it);
    for (ll *it = b, *e = b + n; it != e; ++it)
        scanf("%lld", it);

    ll l = -1, r = INF, m;
    while(r - l > 1)
    {
        m = (l + r) / 2;
        if (check(m))
            r = m;
        else
            l = m;
    }

    if (r == INF)
        printf("-1");
    else
        printf("%lld", r);
}


#include <iostream>
#include <cstdio>
#include <queue>
using namespace std;

typedef long long ll;
typedef pair<ll,ll> pll;
const ll INF = 1e15;
const int N = 2e5;

int n, T;
ll a[N], b[N];

ll calc(ll a, ll b)
{
    return (a + b - 1) / b;
}
bool check(ll x)
{
    priority_queue< pair<ll,pll> > Q;
    for (int i = 0; i < n; ++i)
        Q.push({-((a[i] + b[i] - 1) / b[i]), {a[i], b[i]}});

    for (int t = 0; t < T; ++t)
    {
        auto e = Q.top();
        Q.pop();
        static ll a, b;
        a = e.second.first;
        b = e.second.second;
        if (a - t * b < 0)
            return false;
        a += x;
        Q.push({-calc(a, b), {a, b}});
    }

    return true;
}

int main()
{

#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
#endif

    scanf("%d%d", &n, &T);

    for (int i = 0; i < n; ++i)
        scanf("%lld", a + i);
    for (int i = 0; i < n; ++i)
        scanf("%lld", b + i);

    ll l = 0, r = INF, m;
    while(r - l > 1)
    {
        m = (l + r) / 2;
        if (check(m))
            r = m;
        else
            l = m;
    }

    if (r == INF)
        printf("-1");
    else
        printf("%lld", r);
}


#include <iostream>
#include <cstdio>
#include <queue>
using namespace std;

typedef long long ll;
typedef pair<ll,ll> pll;
const ll INF = 2e12 + 5;
const int N = 2e5;

int n, T;
ll a[N], b[N];

ll calc(ll a, ll b)
{
    return a / b;
}
bool check(ll x)
{
    priority_queue< pair<ll,pll> > Q;
    for (int i = 0; i < n; ++i)
        Q.push({-calc(a[i], b[i]), {a[i], b[i]}});

    for (int t = 0; t < T; ++t)
    {
        auto e = Q.top();
        Q.pop();
        static ll a, b;
        a = e.second.first;
        b = e.second.second;
        if (a - t * b < 0)
            return false;
        a += x;
        Q.push({-calc(a, b), {a, b}});
    }

    return true;
}

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

    for (ll *it = a, *e = a + n; it != e; ++it)
        scanf("%lld", it);
    for (ll *it = b, *e = b + n; it != e; ++it)
        scanf("%lld", it);

    ll l = -1, r = INF, m;
    while(r - l > 1)
    {
        m = (l + r) / 2;
        if (check(m))
            r = m;
        else
            l = m;
    }

    if (r == INF)
        printf("-1");
    else
        printf("%lld", r);
}


#include <iostream>
#include <cstdio>
#include <queue>
using namespace std;

typedef long long ll;
typedef pair<ll,ll> pll;
const ll INF = 1e13;
const int N = 2e5;

int n, T;
ll a[N], b[N];

ll calc(ll a, ll b)
{
    return a / b;
}
bool check(ll x)
{
    priority_queue< pair<ll,pll> > Q;
    for (int i = 0; i < n; ++i)
        Q.push({-calc(a[i], b[i]), {a[i], b[i]}});

    for (int t = 0; t < T; ++t)
    {
        auto e = Q.top();
        Q.pop();
        static ll a, b;
        a = e.second.first;
        b = e.second.second;
        if (a - t * b < 0)
            return false;
        a += x;
        Q.push({-calc(a, b), {a, b}});
    }

    return true;
}

int main()
{

#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
#endif

    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    cin >> n >> T;

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

    ll l = -1, r = INF, m;
    while(r - l > 1)
    {
        m = (l + r) / 2;
        if (check(m))
            r = m;
        else
            l = m;
    }

    if (r == INF)
        cout << -1;
    else
        cout << r;
}