#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const double eps = 1e-11;
bool cmp() { return true; }
int do_search(int x, int y) {
  int l = 0, h = 0;
  return l;
}
long long a[1000001], b[1000001];
vector<pair<long long, pair<long long, long long> > > v;
int main() {
  ios::sync_with_stdio(false);
  long long n, k;
  cin >> n >> k;
  long long a_sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> b[i];
    v.push_back(make_pair(b[i] / a[i], make_pair(b[i] % a[i], a[i])));
  }
  sort(v.begin(), v.end());
  long long res = v[0].first;
  long long p_sum = 0, l = 0, tot_sum = 0, cur_sum = 0, temp_res = 0;
  for (int i = 0; k && (i < v.size()); i++) {
    temp_res = v[i].first;
    cur_sum += v[i].second.second - v[i].second.first;
    tot_sum += v[i].second.second;
    v[i].second.first = 0;
    if ((i < v.size() - 1) && v[i].first != v[i + 1].first) {
      long long d = cur_sum + p_sum;
      if (k >= d) {
        k -= d;
        temp_res++;
        d = (v[i + 1].first - temp_res) * tot_sum;
        if (k >= d) {
          k -= d;
          temp_res = v[i + 1].first;
        } else {
          temp_res += k / tot_sum;
          k = 0;
        }
        res = temp_res;
      } else {
        k = 0;
      }
      cur_sum = 0;
      p_sum = tot_sum;
    }
  }
  if (k && (k >= (cur_sum + p_sum))) {
    k -= cur_sum + p_sum;
    temp_res++;
  }
  res = temp_res;
  cout << res + (k / tot_sum) << endl;
  return 0;
}
