#include <bits/stdc++.h>
using namespace std;
bool compare(pair<long long, long long> a1, pair<long long, long long> b1) {
  if (a1.second / a1.first != b1.second / b1.first)
    return (a1.second / a1.first < b1.second / b1.first);
  return a1.second < b1.second;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  long long n, k;
  cin >> n >> k;
  long long a[n];
  long long b[n];
  for (long long i = 0; i < n; i++) cin >> a[i];
  for (long long i = 0; i < n; i++) cin >> b[i];
  vector<pair<long long, long long>> v1;
  for (long long i = 0; i < n; i++) {
    v1.push_back({a[i], b[i]});
  }
  sort(v1.begin(), v1.end(), compare);
  long long ans = (v1[0].second) / (v1[0].first);
  long long sum1 = v1[0].first;
  long long sum2 = v1[0].second;
  long long fl = 0;
  for (long long i = 1; i < n; i++) {
    long long r1 = ans;
    long long r2 = v1[i].second / v1[i].first;
    if (r1 == r2) {
      sum1 = sum1 + v1[i].first;
      sum2 = sum2 + v1[i].second;
      continue;
    }
    if (k >= r2 * (sum1)-sum2) {
      k = k - (r2 * (sum1)-sum2);
      sum2 = r2 * sum1;
      ans = r2;
      sum1 = sum1 + v1[i].first;
      sum2 = sum2 + v1[i].second;
    } else {
      ans = max(ans, (k + sum2) / sum1);
      fl = 1;
      break;
    }
  }
  if (k > 0 && fl == 0) {
    ans = max(ans, (k + sum2) / sum1);
    cout << ans << endl;
  } else {
    cout << ans << endl;
  }
}
