#include <bits/stdc++.h>
using namespace std;
const long double PI = 3.141592653589793;
const int eps = 1e-10;
const int base = 1e9;
const int N = 100005;
int A[N], B[N];
bool func(long long n, long long k, long long m) {
  for (int i = 1; i <= n; i++) {
    long long cnt = B[i] / A[i];
    if (cnt < m) {
      long long add = (m - cnt) * A[i] - (B[i] % A[i]);
      k -= add;
      if (k < 0) return false;
    }
  }
  return true;
}
int main() {
  long long n, k, ans = 0;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> A[i];
  for (int i = 1; i <= n; i++) cin >> B[i];
  long long l = 0, r = base * 2, m;
  while (r - l > 1) {
    m = (l + r) / 2;
    if (func(n, k, m))
      l = m;
    else
      r = m;
  }
  if (func(n, k, r))
    cout << r << endl;
  else
    cout << l << endl;
  return 0;
}
