#include <bits/stdc++.h>
using namespace std;
int dx[] = {1, 0, -1, 0, -1, 1, -1, 1};
int dy[] = {0, 1, 0, -1, -1, 1, 1, -1};
void moha() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}
const long double eps = 1e-10;
const int N = 1e5 + 1;
long long n, k;
long long a[N];
long long b[N];
bool ok(long long x) {
  long long z = k;
  for (int i = 0; i < n; i++) {
    if (a[i] * x > b[i]) {
      if (a[i] * x <= b[i] + z && z > 0) {
        z = z - ((a[i] * x) - b[i]);
      } else {
        return false;
      }
    } else
      continue;
  }
  return true;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) cin >> b[i];
  long long a = 0, b = 1e10;
  while (a < b - 1) {
    long long mid = (a + b) / 2;
    if (ok(mid)) {
      a = mid;
    } else {
      b = mid;
    }
  }
  cout << a << endl;
  return 0;
}
