#include <bits/stdc++.h>
using namespace std;
const long long int M = 1000000007;
long long int power(long long int x, long long int y, long long int p) {
  long long int res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res % p;
}
long long int modinver(long long int a, long long int b) {
  return (power(a, 1, M) * power(b, M - 2, M)) % M;
}
void SieveOfEratosthenes(int n) {
  bool prime[10005];
  memset(prime, true, sizeof(prime));
  for (int p = 2; p * p <= n; p++) {
    if (prime[p] == true) {
      for (int i = p * p; i <= n; i += p) prime[i] = false;
    }
  }
}
std::vector<long long int> a, b;
long long int n, k;
long long int check(long long int num) {
  long long int k1 = k;
  for (int i = 0; i < n; ++i) {
    if (a[i] * num > b[i]) {
      if (k1 < a[i] * num - b[i]) {
        return 0;
      } else {
        k1 -= (a[i] * num - b[i]);
      }
    }
  }
  return 1;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  for (int i = 0; i < n; ++i) {
    long long int c;
    cin >> c;
    a.push_back(c);
  }
  for (int i = 0; i < n; ++i) {
    long long int d;
    cin >> d;
    b.push_back(d);
  }
  long long int i = 0, j = 2000000000;
  long long int prev = -1;
  while (i < j) {
    long long int mid = (i + j + 1) / 2;
    if (mid == prev) break;
    prev = mid;
    if (check(mid)) {
      i = mid;
    } else {
      j = mid - 1;
    }
  }
  cout << i << '\n';
}
