#include <bits/stdc++.h>
using namespace std;
template <class T1, class T2>
inline void gmax(T1& a, T2 b) {
  if (b > a) a = b;
}
template <class T1, class T2>
inline void gmin(T1& a, T2 b) {
  if (b < a) a = b;
}
const long long inf = 0x3f3f3f3f;
const long long maxn = 1e6 + 5;
struct no {
  int a;
  int b;
  int c;
} node[maxn];
int sum[maxn];
bool cmp(const no& a, const no& b) { return a.c < b.c; }
void solve() {
  int n, k;
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &node[i].a);
  }
  for (int i = 0; i < n; ++i) {
    scanf("%d", &node[i].b);
  }
  for (int i = 0; i < n; ++i) {
    node[i].c = node[i].b / node[i].a;
  }
  sort(node, node + n, cmp);
  sum[0] = node[0].a;
  for (int i = 1; i < n; ++i) {
    sum[i] = sum[i - 1] + node[i].a;
  }
  int i = 0;
  int res = node[0].c;
  while (i <= n - 1 && k > 0) {
    k += (node[i].b % node[i].a);
    if (k >= (sum[i] * (node[i + 1].c - node[i].c)) && node[i + 1].c != 0 &&
        node[i + 1].c > node[i].c) {
      k -= (sum[i] * (node[i + 1].c - node[i].c));
      res += node[i + 1].c - node[i].c;
    } else if (k < (sum[i] * (node[i + 1].c - node[i].c)) &&
               node[i + 1].c != 0 && node[i + 1].c > node[i].c) {
      res += k / (sum[i]);
      break;
    } else if (node[i + 1].a == 0) {
      res += k / (sum[i]);
      break;
    }
    i++;
  }
  cout << res << endl;
}
int main() {
  solve();
  return 0;
}
