#include <bits/stdc++.h>
using namespace std;
long long int a[1000001];
long long int b[1000001];
bool prime[1000001];
void debug(long long int a) { cout << a << endl; }
long long int sieve(long long int a) {
  memset(prime, true, sizeof(prime));
  long long int p;
  long long int i;
  for (p = 2; p * p <= a; p++) {
    if (prime[p] == true) {
      for (i = p * 2; i <= a; i += p) prime[i] = false;
    }
  }
  return 0;
}
long long int solve(long long int x, long long int k, long long int n) {
  long long int i;
  long long int flag = 0;
  for (i = 0; i < n; i++) {
    if (a[i] * x > b[i]) k -= abs(b[i] - a[i] * x);
    if (k < 0) flag = 1;
  }
  if (flag == 1)
    return 0;
  else
    return 1;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int i, j;
  long long int n, k;
  cin >> n >> k;
  for (i = 0; i < n; i++) cin >> a[i];
  for (i = 0; i < n; i++) cin >> b[i];
  set<long long int> answer;
  for (i = 0; i < n; i++) answer.insert(b[i] / a[i]);
  vector<long long int> answer1(answer.begin(), answer.end());
  long long int l = 0;
  long long int r = 2 * 1000000007 - 13;
  long long int mid;
  long long int ans;
  while (l <= r) {
    mid = (l + r) >> 1;
    if (solve(mid, k, n) == 1) {
      l = mid + 1;
      ans = mid;
    } else {
      r = mid - 1;
    }
  }
  cout << ans << endl;
}
