#include <bits/stdc++.h>
using namespace std;
long long n, k;
long long a[100010], b[100010];
int pot(long long x) {
  int res = 0;
  while (x) {
    res++;
    x /= 10;
  }
  return res;
}
bool test(long long mid) {
  long long lef = k;
  for (int i = 0; i < n; ++i) {
    int qnt1 = pot(a[i]);
    int qnt2 = pot(mid);
    if (qnt1 + qnt2 >= 15) {
      return 0;
    }
    if (b[i] < a[i] * mid) {
      lef -= (a[i] * mid - b[i]);
      if (lef < 0) return 0;
    }
  }
  return (lef >= 0);
}
long long bs(long long lo, long long hi) {
  while (hi - lo > 1) {
    long long mid = (hi + lo) / 2;
    if (test(mid)) {
      lo = mid;
    } else {
      hi = mid;
    }
  }
  if (test(hi)) return hi;
  return lo;
}
int main(void) {
  ios ::sync_with_stdio(false);
  cin >> n >> k;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  for (int i = 0; i < n; ++i) {
    cin >> b[i];
  }
  cout << bs(0, 5000000000LL) << "\n";
  return 0;
}
