#include <bits/stdc++.h>
using namespace std;
int n, k, a[100000 + 1], b[100000 + 1], minR, maxR;
int binarySearch() {
  int lo = minR, hi = maxR + k;
  while (lo < hi) {
    int mid = lo + (hi - lo + 1) / 2;
    int s = k;
    bool check = true;
    for (int i = 1; i <= n; i++) {
      int x = b[i] / a[i], re;
      if (x >= mid) continue;
      re = a[i] - (b[i] % a[i]);
      if (re > s) {
        check = false;
        break;
      }
      s -= re;
      if ((long long)(mid - (x + 1)) * a[i] > s) {
        check = false;
        break;
      }
      s -= (mid - x - 1) * a[i];
    }
    if (check)
      lo = mid;
    else
      hi = mid - 1;
  }
  return lo;
}
int main() {
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> a[i];
  cin >> b[1];
  minR = maxR = b[1] / a[1];
  for (int i = 2; i <= n; i++) {
    cin >> b[i];
    int t = b[i] / a[i];
    minR = min(minR, t);
    maxR = max(maxR, t);
  }
  int answer = binarySearch();
  cout << answer << endl;
}
