#include <bits/stdc++.h>
using namespace std;
long long a[100004], b[100004];
long long n, k;
long long hh(long long l, long long r) {
  long long sum, mid;
  while (l <= r) {
    mid = (l + r) / 2;
    sum = 0;
    for (int i = 1; i <= n; i++) {
      if (b[i] < a[i] * mid) sum += (a[i] * mid - b[i]);
      if (sum > k) break;
    }
    if (sum == k) {
      return mid;
    }
    if (sum > k)
      r = mid - 1;
    else
      l = mid + 1;
  }
  return l - 1;
}
int main() {
  int i, j;
  while (cin >> n >> k) {
    int t = 0;
    for (i = 1; i <= n; i++) cin >> a[i];
    for (i = 1; i <= n; i++) cin >> b[i];
    long long l = 1, r = 2 * 1000000000;
    long long xx = hh(l, r);
    cout << xx << endl;
  }
}
