#include <bits/stdc++.h>
using namespace std;
bool go(int n, long long k, int a[], int b[], long long val);
int main() {
  ios_base::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  int a[n], b[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) cin >> b[i];
  int cookies = 1e9;
  for (int i = 0; i < n; i++) cookies = min(cookies, b[i] / a[i]);
  for (int i = 0; i < n; i++) b[i] -= a[i] * cookies;
  int low = 0, high = k;
  while (low < high) {
    int mid = (low + high + 1) / 2;
    if (go(n, k, a, b, mid))
      low = mid;
    else
      high = mid - 1;
  }
  cout << cookies + low;
  return 0;
}
bool go(int n, long long k, int a[], int b[], long long int val) {
  for (int i = 0; i < n; i++) {
    long long int temp = val * 1ll * a[i] - b[i];
    if (k >= 0 && temp > 0) k -= temp;
    if (k < 0) return false;
  }
  return true;
}
