#include <bits/stdc++.h>
using namespace std;
long long int pow(long long int a, long long int b) {
  if (a == 0) return 0;
  long long int x = 1;
  while (b > 0) {
    if (b & 1) x = x * a;
    b = b >> 1;
    a = a * a;
  }
  return x;
}
long long int gcdext(long long int a, long long int b, long long int &x,
                     long long int &y) {
  if (b == 0) {
    x = 1, y = 0;
    return a;
  }
  long long int x1, y1, z;
  z = gcdext(b, a % b, x1, y1);
  x = y1;
  y = x1 - (a / b) * y1;
  return z;
}
bool fun(vector<long long int> a, vector<long long int> b, long long int n,
         long long int k, long long int m) {
  for (long long int i = 0; i <= n - 1; i++) {
    if (b[i] / a[i] >= m)
      continue;
    else {
      long long int x = b[i] / a[i];
      k = k + (b[i] % a[i]) - (m - x) * a[i];
      if (k < 0) return false;
    }
  }
  return true;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int a, b, c, d, i, j, k, l, m, n, p, q, r, s, x, y, z, ans = 0,
                                                                   ind = -1;
  string s1, s2;
  cin >> n >> k;
  vector<long long int> v(n, 0), v1(n, 0);
  for (long long int i = 0; i <= n - 1; i++) {
    cin >> v[i];
  }
  for (long long int i = 0; i <= n - 1; i++) {
    cin >> v1[i];
  }
  l = 0, r = 2000000000;
  while (l <= r) {
    m = (l + r) / 2;
    if (fun(v, v1, n, k, m)) {
      l = m + 1;
      ans = m;
    } else
      r = m - 1;
  }
  cout << ans;
  return 0;
}
