#include <bits/stdc++.h>
using namespace std;
int n, i;
long long int x, y, z;
long long int m1[100001];
long long int m2[100001];
long long int a, b, c, k;
bool check(long long c) {
  x = 0;
  for (int i = 1; i <= n; i++)
    if (m1[i] * c > m2[i]) {
      x = x + (m1[i] * c - m2[i]);
      if (x > k) return false;
    }
  return true;
}
int main() {
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> m1[i];
  for (int i = 1; i <= n; i++) cin >> m2[i];
  a = 0;
  b = 2000000000;
  while (a < b) {
    c = (a + b + 1) / 2;
    if (check(c))
      a = c;
    else
      b = c - 1;
  }
  cout << a << endl;
}
