#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int i, n, t;
  long long sumx = 0, cumsum = 0, k, tmpsum, nextVal;
  vector<int> a;
  vector<int> b;
  vector<pair<int, int>> c;
  vector<int> x;
  scanf("%d %I64d", &n, &k);
  for (i = 0; i < n; i++) {
    scanf("%d", &t);
    a.push_back(t);
  }
  for (i = 0; i < n; i++) {
    scanf("%d", &t);
    b.push_back(t);
  }
  for (i = 0; i < n; i++) {
    c.push_back(make_pair(b[i] / a[i], i));
    int tmp = b[i] % a[i];
    if (tmp != 0) tmp = a[i] - tmp;
    x.push_back(tmp);
  }
  sort(c.begin(), c.end());
  for (auto j : x) sumx = sumx + static_cast<long long>(j);
  auto ans = c[0].first;
  for (i = 0; i < n; i++) {
    int left = i, right = left;
    while (right + 1 < n && c[right + 1].first == c[left].first) right++;
    tmpsum = 0;
    for (auto j = left; j <= right; j++) {
      if (x[c[j].second])
        tmpsum += x[c[j].second];
      else
        tmpsum += a[c[j].second];
    }
    if (right + 1 < n)
      nextVal = c[right + 1].first;
    else
      nextVal = -1;
    long long next, as;
    next = cumsum + tmpsum;
    if (k >= next) {
      k -= next;
      if (next > 0) ans++;
      for (auto j = left; j <= right; j++) cumsum += a[c[j].second];
      if (k > 0) {
        if (nextVal != -1) {
          as = min(nextVal - ans, k / cumsum);
          k -= as * cumsum;
          ans += as;
        } else {
          as = k / cumsum;
          k -= as * cumsum;
          ans += as;
          printf("%ld", ans);
          return 0;
        }
      }
    } else {
      printf("%ld", ans);
      return 0;
    }
    i = right;
  }
  printf("%ld", ans);
  return 0;
}
