#include <bits/stdc++.h>
using namespace std;
unsigned long long int power(unsigned long long int a,
                             unsigned long long int b) {
  unsigned long long int res = 1;
  a = a % 1000000007;
  while (b > 0) {
    if (b & 1) {
      res = (res * a) % 1000000007;
      b--;
    }
    a = (a * a) % 1000000007;
    b >>= 1;
  }
  return res;
}
unsigned long long int gcd(unsigned long long int a, unsigned long long int b) {
  return (b == 0) ? a : gcd(b, a % b);
}
unsigned long long int n, k;
vector<unsigned long long int> a(200005);
vector<unsigned long long int> b(200005);
bool check(unsigned long long int x) {
  unsigned long long int anss = 0;
  for (unsigned long long int i = 0; i < n; i++) {
    if (b[i] > a[i] * x) continue;
    anss += a[i] * x - b[i];
  }
  return anss <= k;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> k;
  for (unsigned long long int i = 0; i < n; i++) cin >> a[i];
  for (unsigned long long int i = 0; i < n; i++) cin >> b[i];
  unsigned long long int l = 0, r = 1e10;
  unsigned long long int ans = 0;
  while (l <= r) {
    unsigned long long int mid = l + (r - l) / 2;
    if (check(mid)) {
      ans = mid;
      l = mid + 1;
    } else
      r = mid - 1;
  }
  cout << ans << "\n";
}
