#include <bits/stdc++.h>
using namespace std;
int abso(int a, int b) {
  if (a < b)
    return b - a;
  else
    return a - b;
}
long long power(long long x, long long e) {
  long long temp;
  if (e == 0) return 1;
  if (e % 2 == 0) {
    temp = power(x, e / 2);
    return temp * temp;
  } else {
    temp = power(x, e / 2);
    return temp * temp * x;
  }
}
bool cmp(pair<pair<int, int>, int> x, pair<pair<int, int>, int> y) {
  if (x.first.first == y.first.first) {
    if (x.first.second == y.first.second)
      return x.second < y.second;
    else
      return x.first.second > y.first.second;
  }
  return x.first.first > y.first.first;
}
bool cmp1(pair<int, int> x, pair<int, int> y) {
  if (x.second == y.second) return x.first < y.first;
  return x.second < y.second;
}
long long abso(long long a, long long b) {
  if (a < b)
    return b - a;
  else
    return a - b;
}
int main() {
  unsigned long long n, k;
  cin >> n >> k;
  unsigned long long arr[n + 1], pre[n + 1];
  for (int i = 1; i <= n; i++) cin >> arr[i];
  for (int i = 1; i <= n; i++) cin >> pre[i];
  unsigned long long lo = 0, hi = 1000000000000;
  unsigned long long mid, cur, temp, req, ans, flag;
  while (hi - lo > 1) {
    mid = (lo + hi) / 2;
    temp = 0;
    flag = 0;
    for (int i = 1; i <= n; i++) {
      cur = mid * arr[i];
      if (pre[i] >= cur)
        req = 0;
      else
        req = cur - pre[i];
      temp += req;
      if (temp > k || temp < 0) {
        flag = 1;
        break;
      }
    }
    if (flag == 0) {
      lo = mid;
    } else {
      hi = mid;
    }
  }
  cout << lo << endl;
  return 0;
}
