#include <bits/stdc++.h>
using namespace std;
const int maxn = 100000;
long long a[maxn], b[maxn];
int main() {
  long long n, k, r = 0;
  while (cin >> n >> k) {
    for (int i = 1; i <= n; i++) cin >> a[i];
    for (int i = 1; i <= n; i++) cin >> b[i];
    long long l = 0, r = 2e9;
    long long ans = 0;
    while (l <= r) {
      long long ansl = k;
      long long m = (l + r) / 2;
      for (int i = 1; i <= n; i++) {
        if (a[i] * m > b[i]) ansl += b[i] - a[i] * m;
        if (ansl < 0) break;
      }
      if (ansl < 0) r = m - 1;
      if (ansl >= 0) l = m + 1;
    }
    cout << r << endl;
  }
  return 0;
}
