#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, k;
  cin >> n >> k;
  struct Ingred {
    int num;
    int a, b;
  };
  vector<Ingred> ingreds(n);
  for (int i = 0; i < n; ++i) {
    cin >> ingreds[i].a;
  }
  for (int i = 0; i < n; ++i) {
    cin >> ingreds[i].b;
    ingreds[i].num = ingreds[i].b / ingreds[i].a;
  }
  sort(ingreds.begin(), ingreds.end(),
       [](const Ingred& x, const Ingred& y) { return x.num < y.num; });
  long long cookies = ingreds[0].num;
  long long for_next_one = ingreds[0].a - ingreds[0].b % ingreds[0].a;
  long long for_next_any = ingreds[0].a;
  for (int i = 1; i < n; ++i) {
    if (ingreds[i].num == ingreds[i - 1].num) {
      for_next_one += ingreds[i].a - ingreds[i].b % ingreds[i].a;
      for_next_any += ingreds[i].a;
      continue;
    }
    if (k < for_next_one) {
      break;
    }
    k -= for_next_one;
    for_next_one = for_next_any;
    ++cookies;
    if (ingreds[i].num == cookies) {
      for_next_one += ingreds[i].a - ingreds[i].b % ingreds[i].a;
      for_next_any += ingreds[i].a;
      continue;
    }
    int to_cook = ingreds[i].num - cookies;
    int can_cook = k / for_next_any;
    k -= min(to_cook, can_cook) * for_next_any;
    cookies += min(to_cook, can_cook);
    if (ingreds[i].num == cookies) {
      for_next_one += ingreds[i].a - ingreds[i].b % ingreds[i].a;
      for_next_any += ingreds[i].a;
      continue;
    }
    if (k < for_next_any) {
      break;
    }
  }
  if (k >= for_next_one) {
    k -= for_next_one;
    ++cookies;
  }
  int can_cook = k / for_next_any;
  cookies += can_cook;
  cout << cookies;
  return 0;
}
