#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<stdio.h>
#include<stdlib.h>
#include<cmath>
#define ll long long int
using namespace std;

ll n, k;
vector<ll>a;
vector<ll>b;

ll can(ll k, vector<ll> A, vector<ll>B) {
  ll n = A.size();
  ll cur = 9876599999999;
  ll val = 0;
  ll tms = 0;
  for(int i=0;i<n;i++){
    tms = B[i]/A[i];
    cur = min(cur,tms);
  }
  ll minn = cur;
  bool ok =true;
  ll left = minn;
  ll right = left + k;
  ll middle = (left+ right)/2;
  while(true){
    val = 0;
    middle = (left + right )/2;
    for(int i=0;i<n;i++){
      ll rest = middle*A[i];;
      if(rest > B[i]){
        val =val + rest - B[i];
      }
    }
    //cout<<middle<<endl;
    if(left >right ){
        return middle;
   }
    if(val<=k ){
      left = middle + 1;
      //cout<<"left increases ."<<left<<endl;
    }
    else {
     right = middle - 1;
     //cout<<"right decreases "<<right<<endl;
   }
  }
  return 0;
}
ll x;
int main () {
  scanf("%lld %lld",&n,&k);
  for(int i=0;i<n;i++){
    scanf("%lld",&x);
    a.push_back(x);
  }
  for(int i=0;i<n;i++){
    scanf("%lld",&x);
    b.push_back(x);
  }

  cout<<can(k,a,b)<<endl;
  return 0;
}


#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<stdio.h>
#include<stdlib.h>
#include<cmath>
#define ll long long int
using namespace std;

ll n, k;
vector<ll>a;
vector<ll>b;

ll can(ll k, vector<ll> A, vector<ll>B) {
  ll n = A.size();
  ll cur = 987659999999999;
  ll val = 0;
  ll tms = 0;
  for(int i=0;i<n;i++){
    tms = B[i]/A[i];
    cur = min(cur,tms);
  }
  ll minn = cur;
  bool ok =true;
  ll left = minn;
  ll right = left + k;
  ll middle = (left+ right)/2;
  while(true){
    val = 0;
    middle = (left + right )/2;
    for(int i=0;i<n;i++){
      ll rest = middle*A[i] - B[i];
      if(rest > 0){
        val =val + rest;
      }
    }
    //cout<<middle<<endl;
    if(left >right ){
        return middle;
   }
    if(val<=k ){
      left = middle + 1;
      //cout<<"left increases ."<<left<<endl;
    }
    else {
     right = middle - 1;
     //cout<<"right decreases "<<right<<endl;
   }
  }
  return 0;
}
ll x;
int main () {
  scanf("%lld %lld",&n,&k);
  for(int i=0;i<n;i++){
    scanf("%lld",&x);
    a.push_back(x);
  }
  for(int i=0;i<n;i++){
    scanf("%lld",&x);
    b.push_back(x);
  }

  cout<<can(k,a,b)<<endl;
  return 0;
}


#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<stdio.h>
#include<stdlib.h>
#include<cmath>
#define ll long long int
using namespace std;

ll n, k;
vector<ll>a;
vector<ll>b;

ll can(ll k, vector<ll> A, vector<ll>B) {
  ll n = A.size();
  ll cur = 9876599999999;
  ll val = 0;
  ll tms = 0;
  for(int i=0;i<n;i++){
    tms = B[i]/A[i];
    cur = min(cur,tms);
  }
  for(int i=0;i<n;i++){
    B[i]-=cur*A[i];
  }
  ll minn = cur;
  bool ok =true;
  ll left = 0;
  ll right = left + k;
  ll middle = (left+ right)/2;
  while(true){
    val = 0;
    middle = (left + right )/2;
    for(int i=0;i<n;i++){
      ll rest = middle*A[i];;
      if(rest > B[i]){
        val =val + rest - B[i];
      }
    }
    //cout<<middle<<endl;
    if(left >right ){
        return middle+minn;
   }
    if(val<=k ){
      left = middle + 1;
      //cout<<"left increases ."<<left<<endl;
    }
    else {
     right = middle - 1;
     //cout<<"right decreases "<<right<<endl;
   }
  }
  return 0;
}
ll x;
int main () {
  scanf("%lld %lld",&n,&k);
  for(int i=0;i<n;i++){
    scanf("%lld",&x);
    a.push_back(x);
  }
  for(int i=0;i<n;i++){
    scanf("%lld",&x);
    b.push_back(x);
  }

  cout<<can(k,a,b)<<endl;
  return 0;
}


#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<stdio.h>
#include<stdlib.h>
#define ll long long int
using namespace std;

ll n, k;
vector<ll>a;
vector<ll>b;

ll can(ll k, vector<ll> A, vector<ll>B) {
  ll n = A.size();
  ll cur = 999990;
  ll val = 0;
  ll tms = 0;
  for(int i=0;i<n;i++){
    tms = B[i]/A[i];
    cur = min(cur,tms);
  }
  ll minn = cur;
  bool ok =true;
  for(int j=0;j<=minn+k;j++){
    val = 0;
    for(int i=0;i<n;i++){
      ll left = cur*A[i] - B[i];
      if(left > 0){
        val =val + left;
      }
    }
    //cout<<cur-1<<endl;
    ll sign = val - k;
    if(val<k && ok)
      cur = cur*2;
    else {
      ok =false;
      if(val <= k){
        //cout<<cur<<endl;
        return cur;
      }
     cur = cur-1;
   }
  }
  return 0;
}
ll x;
int main () {
  scanf("%lld %lld",&n,&k);
  for(int i=0;i<n;i++){
    scanf("%lld",&x);
    a.push_back(x);
  }
  for(int i=0;i<n;i++){
    scanf("%lld",&x);
    b.push_back(x);
  }

  cout<<can(k,a,b)<<endl;
  return 0;
}


#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<stdio.h>
#include<stdlib.h>
#define ll long long int
using namespace std;

ll n, k;
vector<ll>a;
vector<ll>b;

ll can(ll k, vector<ll> A, vector<ll>B) {
  ll n = A.size();
  ll cur = 999990;
  ll val = 0;
  ll tms = 0;
  for(int i=0;i<n;i++){
    tms = B[i]/A[i];
    cur = min(cur,tms);
  }
  ll minn = cur;
  bool ok =true;
  for(int j=0;j<minn+k;j++){
    val = 0;
    for(int i=0;i<n;i++){
      ll left = cur*A[i] - B[i];
      if(left > 0){
        val =val + left;
      }
    }
    //cout<<cur-1<<endl;
    ll sign = val - k;
    if(val<k && ok)
      cur = cur*2;
    else {
      ok =false;
      if(val <= k){
        //cout<<cur<<endl;
        return cur;
      }
     cur = cur-1;
   }
  }
  return 0;
}
ll x;
int main () {
  scanf("%lld %lld",&n,&k);
  for(int i=0;i<n;i++){
    scanf("%lld",&x);
    a.push_back(x);
  }
  for(int i=0;i<n;i++){
    scanf("%lld",&x);
    b.push_back(x);
  }

  cout<<can(k,a,b)<<endl;
  return 0;
}


#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<stdio.h>
#include<stdlib.h>
#include<cmath>
#define ll long long int
using namespace std;

ll n, k;
vector<ll>a;
vector<ll>b;
ll x;
int main () {
  scanf("%lld %lld",&n,&k);
  for(int i=0;i<n;i++){
    scanf("%lld",&x);
    a.push_back(x);
  }
  for(int i=0;i<n;i++){
    scanf("%lld",&x);
    b.push_back(x);
  }
  ll right = (ll)3*1000000000;
  ll left  = 0;
  ll middle = 0;
  ll rest = 0;
  ll value = 0;
  bool ok = true;
  while(right  - 1  > left ) {
    value = 0;
    middle = (right + left )>>1;
    ok = true;
    for(int i=0;i<n;i++){
      rest = middle*a[i] - b[i];
      if(rest > k ){
        ok = false;
        break;
      }
      if(rest > 0) {
        value+=rest;
      }
    }
    if(value > (ll)k  || !ok ){
      right = middle;
    }
    else
      left = middle;
  }
  cout<<left<<endl;
  return 0;
}


#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<stdio.h>
#include<stdlib.h>
#include<cmath>
#define ll long long int
using namespace std;

ll n, k;
vector<ll>a;
vector<ll>b;

ll can(ll k, vector<ll> A, vector<ll>B) {
  ll n = A.size();
  ll cur = 987659999999999;
  ll val = 0;
  ll tms = 0;
  for(int i=0;i<n;i++){
    tms = B[i]/A[i];
    cur = min(cur,tms);
  }
  ll minn = cur;
  bool ok =true;
  ll left = minn;
  ll right = left + k;
  ll middle = (left+ right)/2;
  while(true){
    val = 0;
    ll middle = (left + right )/2;
    for(int i=0;i<n;i++){
      ll rest = middle*A[i] - B[i];
      if(left > 0){
        val =val + rest;
      }
    }
    //cout<<middle<<endl;
    if(left >right ){
        return middle;
   }
    if(val<=k ){
      left = middle + 1;
      //cout<<"left increases ."<<left<<endl;
    }
    else {
     right = middle - 1;
     //cout<<"right decreases "<<right<<endl;
   }
  }
  return 0;
}
ll x;
int main () {
  scanf("%lld %lld",&n,&k);
  for(int i=0;i<n;i++){
    scanf("%lld",&x);
    a.push_back(x);
  }
  for(int i=0;i<n;i++){
    scanf("%lld",&x);
    b.push_back(x);
  }

  cout<<can(k,a,b)<<endl;
  return 0;
}


#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<stdio.h>
#include<stdlib.h>

using namespace std;

long long int n, k;
long long int a[2000000],b[2000000];
long long int ans[2000000];
int main () {
  scanf("%lld %lld",&n,&k);
  for(int i=0;i<n;i++){
    scanf("%lld",&a[i]);
  }
  for(int i=0;i<n;i++)
    scanf("%lld",&b[i]);
  long long int minn = 999999999999;
  long long int cnt = 0;
  for(int i=0;i<n;i++){
    cnt = b[i]/a[i];
    minn = min(minn , cnt);
  }
  for(int i=0;i<n;i++){
    ans[i] = b[i] - a[i]*minn;
    //cout<<ans[i]<<" ";
  }
  while(k!=0){
    for(int i=0;i<n;i++){
      long long int diff = ans[i] - a[i];
      ans[i]-=a[i];
      if(diff<0){
        k-=abs(diff);
        ans[i] = 0;
      }
      if(k<0){
        cout<<minn<<endl;
        break;
      }
    }
    minn++;
  }
  cout<<minn<<endl;
  return 0;
}


#include <bits/stdc++.h>
#define ff(i,a,b) for(int i = a;i <= b;i++)
#define ll long long

using namespace std;
const int N = 1E6;
int a[N],b[N],n,k;

void enter()
{
    ll tmp = 0;
    cin >> n >> k;
    ff(i,1,n) cin >> a[i];
    ff(i,1,n) cin >> b[i];
}

ll check(ll x)
{
    ll hi = 0;
    ff(i,1,n)
    {
        hi += x * (ll) a[i] - b[i];
        if (hi > k) return hi;
    }
    return hi;
}

void xl()
{
    ll res = 0;
    ll low = 0,high = 1e10;
    while (low <= high)
    {
        ll mid = (low + high) / 2;
        if (check(mid) <= k)
        {
            res = mid;
            low = mid + 1;
        }
        else high = mid - 1;
    }
    cout << res;
}

int main()
{
    enter();
    xl();
}


#include <bits/stdc++.h>
#define ff(i,a,b) for(int i = a;i <= b;i++)
#define ll long long

using namespace std;
const int N = 1E6;
int a[N],b[N],n,k;

void enter()
{
    ll tmp = 0;
    cin >> n >> k;
    ff(i,1,n) cin >> a[i];
    ff(i,1,n) cin >> b[i];
}

ll check(ll x)
{
    ll hi = 0;
    ff(i,1,n) hi += x * a[i] - b[i];
    return hi;
}

void xl()
{
    ll res;
    ll low = 0,high = 1e10;
    while (low <= high)
    {
        int mid = (low + high) / 2;
        if (check(mid) <= k)
        {
            res = mid;
            low = mid + 1;
        }
        else high = mid - 1;
    }
    cout << res;
}

int main()
{
    enter();
    xl();
}


#include <bits/stdc++.h>
#define ff(i,a,b) for(int i = a;i <= b;i++)
#define ll long long

using namespace std;
const int N = 1E6;
int a[N],b[N],n,k;

void enter()
{
    ll tmp = 0;
    cin >> n >> k;
    ff(i,1,n) cin >> a[i];
    ff(i,1,n) cin >> b[i];
}

ll check(ll x)
{
    ll hi = 0;
    ff(i,1,n) hi += x * a[i] - b[i];
    return hi;
}

void xl()
{
    ll res;
    ll low = 0,high = 1e10;
    while (low <= high)
    {
        ll mid = (low + high) / 2;
        if (check(mid) <= k)
        {
            res = mid;
            low = mid + 1;
        }
        else high = mid - 1;
    }
    cout << res;
}

int main()
{
    enter();
    xl();
}


#include <bits/stdc++.h>
#define ff(i,a,b) for(int i = a;i <= b;i++)
#define ll long long

using namespace std;
const int N = 1E6;
int a[N],b[N],n,k;

void enter()
{
    ll tmp = 0;
    cin >> n >> k;
    ff(i,1,n) cin >> a[i];
    ff(i,1,n) cin >> b[i];
}

ll check(ll x)
{
    ll hi = 0;
    ff(i,1,n)
    {
        ll dcm = x *  a[i] - b[i];
        if (dcm < 0) dcm = 0;
        hi += dcm;
        if (hi > k) return hi;
    }
    return hi;
}

void xl()
{
    ll res = 0;
    ll low = 0,high = 1e10;
    while (low <= high)
    {
        ll mid = (low + high) / 2;
        if (check(mid) <= k)
        {
            res = mid;
            low = mid + 1;
        }
        else high = mid - 1;
    }
    cout << res;
}

int main()
{
    enter();
    xl();
}


#include <bits/stdc++.h>
#define ff(i,a,b) for(int i = a;i <= b;i++)
#define ll long long

using namespace std;
const int N = 1E6;
int a[N],b[N],n,k;

void enter()
{
    ll tmp = 0;
    cin >> n >> k;
    ff(i,1,n) cin >> a[i];
    ff(i,1,n) cin >> b[i];
}

ll check(ll x)
{
    ll hi = 0;
    ff(i,1,n)
    {
        hi += x * (ll) a[i] - b[i];
        if (hi >= k) return hi;
    }
    return hi;
}

void xl()
{
    ll res = 0;
    ll low = 0,high = 1e10;
    while (low <= high)
    {
        ll mid = (low + high) / 2;
        if (check(mid) <= k)
        {
            res = mid;
            low = mid + 1;
        }
        else high = mid - 1;
    }
    cout << res;
}

int main()
{
    enter();
    xl();
}


#include <cstdio>

#define INF (1ll << 60)
#define MAXN 100100

long long a[MAXN], b[MAXN];

int main(){
    int n, k;
    while(scanf("%d%d", &n, &k) > 0){
        long long aux = 0;

        for(int i=0; i<n; i++){
            scanf("%lld", &a[i]);
        }

        for(int i=0; i<n; i++){
            scanf("%lld", &b[i]);
        }

        long long lo = 0, up = (long long)1e10, cookies;

        while(lo <= up){
            long long mid = (lo + up) >> 1;

            long long powder = k;
            for(int i=0; i<n and powder>=0; i++){
                if(mid*a[i] > b[i]){
                    powder -= mid*a[i] - b[i];
                }
            }

            if(powder >= 0){
                cookies = mid;
                lo = mid+1;
            } else {
                up = mid-1;
            }
        }

        printf("%lld\n", cookies);
    }
}


#include <cstdio>

#define INF (1ll << 60)
#define MAXN 100100

int a[MAXN], b[MAXN];

int main(){
    int n, k;
    while(scanf("%d%d", &n, &k) > 0){
        long long aux = 0;

        for(int i=0; i<n; i++){
            scanf("%d", &a[i]);
            aux += a[i];
        }

        long long cookies = k/aux;
        k %= aux;

        long long cnt = INF;
        for(int i=0; i<n; i++){
            scanf("%d", &b[i]);

            if(b[i]/a[i] < cnt){
                cnt = b[i]/a[i];
            }
        }

        cookies += cnt;

        int flag = 1;
        for(int i=0; i<n; i++){
            b[i] -= cnt*a[i];

            if(b[i] < a[i]){
                if(k >= a[i]-b[i]){
                    k -= a[i]-b[i];
                } else {
                    flag = 0;
                    break;
                }
            }
        }

        cookies += flag;
        printf("%lld\n", cookies);
    }
}


#include <cstdio>

#define INF (1ll << 60)
#define MAXN 100100

int a[MAXN], b[MAXN];

int main(){
    int n, k;
    while(scanf("%d%d", &n, &k) > 0){
        long long aux = 0;

        for(int i=0; i<n; i++){
            scanf("%d", &a[i]);
            aux += a[i];
        }

        long long cookies = k/aux;
        k %= aux;

        while(k >= 0){
            long long cnt = INF;

            for(int i=0; i<n; i++){
                scanf("%d", &b[i]);

                if(b[i]/a[i] < cnt){
                    cnt = b[i]/a[i];
                }
            }

            cookies += cnt;

            for(int i=0; i<n; i++){
                b[i] -= cnt*a[i];

                if(b[i] < a[i]){
                    k -= a[i]-b[i];
                    b[i] = a[i];
                }
            }
        }

        printf("%lld\n", cookies);
    }
}


#include <cstdio>

#define INF (1ll << 60)
#define MAXN 100100

long long a[MAXN], b[MAXN];

int main(){
    int n, k;
    while(scanf("%d%d", &n, &k) > 0){
        long long aux = 0;

        for(int i=0; i<n; i++){
            scanf("%lld", &a[i]);
            aux += a[i];
        }

        long long cookies = k/aux;
        k %= aux;

        long long cnt = INF;

        for(int i=0; i<n; i++){
            scanf("%lld", &b[i]);

            if(b[i]/a[i] < cnt){
                cnt = b[i]/a[i];
            }
        }

        while(k >= 0){
            cookies += cnt;

            for(int i=0; i<n; i++){
                b[i] -= cnt*a[i];

                if(b[i] < a[i]){
                    k -= a[i]-b[i];
                    b[i] = a[i];
                }
            }

            cnt = 1;
        }

        printf("%lld\n", cookies);
    }
}


#include <cstdio>

#define INF (1ll << 60)
#define MAXN 100100

int a[MAXN], b[MAXN];

int main(){
    int n, k;
    while(scanf("%d%d", &n, &k) > 0){
        long long aux = 0;

        for(int i=0; i<n; i++){
            scanf("%d", &a[i]);
            aux += a[i];
        }

        long long cookies = k/aux;
        k %= aux;

        long long cnt = INF;

        for(int i=0; i<n; i++){
            scanf("%d", &b[i]);

            if(b[i]/a[i] < cnt){
                cnt = b[i]/a[i];
            }
        }

        while(k >= 0){
            cookies += cnt;

            for(int i=0; i<n; i++){
                b[i] -= cnt*a[i];

                if(b[i] < a[i]){
                    k -= a[i]-b[i];
                    b[i] = a[i];
                }
            }

            cnt = 1;
        }

        printf("%lld\n", cookies);
    }
}


#include<bits/stdc++.h>
using namespace std;
long long n, k;
long a[1001],b[1001],c[1001];
int f(long long x,long m)
{
    for(int i= 1; i <= n; i++)
    {
        if(b[i] < a[i]*x)
        m = m-(a[i]*x-b[i]);
    }
    if(m <= 0) return 1;
    else return 0;
}
int main()
{
    scanf("%lldd%lldd",&n,&k);
    long long term = 0;
    for(int i = 1; i <= n; i++)
    {
        scanf("%lld",&a[i]);
        term += a[i];

    }
    for(int i = 1; i <= n; i++)
    {
        scanf("%lld",&b[i]);
    }
    for(int i = 1; i <= n; i++)
    {
        c[i] = b[i]/a[i];
    }
    int min = c[1];
    int max = c[1];
    for(int i = 2; i <= n; i++)
    {
        if(c[i] < min)
        {
            min = c[i];
        }
        if(c[i] > max)
        {
            max = c[i];
        }
    }
    max += k/term;
    long long l = min, r = max;
    long sum = r;
    while(l <= r)
    {
        long long mid = (l+r)>>1;
        if(f(mid,k))
        {
            sum = mid;
            r = mid - 1;
        }
        else
        {
            l = mid+1;
        }
    }
    cout<<sum<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n, k;
    scanf("%d%d",&n,&k);
    int a[1001],b[1001],c[1001];
    for(int i = 1; i <= n; i++)
    {
        scanf("%d",&a[i]);
    }
    for(int i = 1; i <= n; i++)
    {
        scanf("%d",&b[i]);
    }
    for(int i = 1; i <= n; i++)
    {
        c[i] = b[i]/a[i];
    }
    int min = c[1];
    int minloc = 1;
    for(int i = 2; i <= n; i++)
    {
        if(c[i] < min)
        {
            min = c[i];
            minloc = i;
        }
    }
    int sum = min;
    for(int i =1; i <= n; i++)
    {
        b[i] = b[i] - min*a[i];
    }
    while(true)
    {
        int flag = 0;
        for(int i = 1; i <= n; i++)
        {

            if(b[i] < a[i])
            {
                if(k >= a[i]-b[i])
                {

                    k = k-(a[i]-b[i]);
                     b[i] = 0;
                    flag++;
                }
                else break;
            }
            else
            {
                b[i] = b[i] - a[i];
                flag++;
            }

        }
        if(flag==n) sum++;
        else break;
    }
    cout<<sum<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n, k;
int a[100001],b[100001],c[100001];
int f(long long x,int m)
{
    for(int i= 1; i <= n; i++)
    {
        if(b[i] < a[i]*x)
        m = m-(a[i]*x-b[i]);
    }
    if(m < 0) return 1;
    else if(m==0) return 2;
    else return 0;
}
int main()
{
    scanf("%d%d",&n,&k);
    long long term = 0;
    for(int i = 1; i <= n; i++)
    {
        scanf("%d",&a[i]);
        term += a[i];

    }
    for(int i = 1; i <= n; i++)
    {
        scanf("%d",&b[i]);
    }
    for(int i = 1; i <= n; i++)
    {
        c[i] = b[i]/a[i];
    }
    int min = c[1];
    int max = c[1];
    for(int i = 2; i <= n; i++)
    {
        if(c[i] < min)
        {
            min = c[i];
        }
        if(c[i] > max)
        {
            max = c[i];
        }
    }
    max += k/term;
    long long l = min, r = max;
    long long sum = r;
    while(l <= r)
    {
        long long mid = (l+r)>>1;
        if(f(mid,k)==1)
        {
            r = mid - 1;
        }
        else if(f(mid,k)==0)
        {
            sum = mid;
            l = mid+1;
        }
        else
        {
            sum = mid;
            break;
        }

    }
    cout<<sum<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n, k;
int a[1001],b[1001],c[1001];
int f(long long x,int m)
{
    for(int i= 1; i <= n; i++)
    {
        if(b[i] < a[i]*x)
        m = m-(a[i]*x-b[i]);
        if(m < 0) break;
    }
    if(m <= 0) return 1;
    else return 0;
}
int main()
{
    scanf("%d%d",&n,&k);
    long long term = 0;
    for(int i = 1; i <= n; i++)
    {
        scanf("%d",&a[i]);
        term += a[i];

    }
    for(int i = 1; i <= n; i++)
    {
        scanf("%d",&b[i]);
    }
    for(int i = 1; i <= n; i++)
    {
        c[i] = b[i]/a[i];
    }
    int min = c[1];
    int max = c[1];
    for(int i = 2; i <= n; i++)
    {
        if(c[i] < min)
        {
            min = c[i];
        }
        if(c[i] > max)
        {
            max = c[i];
        }
    }
    max += k/term;
    long long l = min, r = max;
    long sum = r;
    while(l <= r)
    {
        long long mid = (l+r)>>1;
        if(f(mid,k))
        {
            sum = mid;
            r = mid - 1;
        }
        else
        {
            sum = mid;
            l = mid + 1;
        }
    }
    cout<<sum<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n, k;
int a[1001],b[1001],c[1001];
int f(long long x,int m)
{
    for(int i= 1; i <= n; i++)
    {
        if(b[i] < a[i]*x)
        m = m-(a[i]*x-b[i]);
    }
    if(m <= 0) return 1;
    else return 0;
}
int main()
{
    scanf("%d%d",&n,&k);
    long long term = 0;
    for(int i = 1; i <= n; i++)
    {
        scanf("%d",&a[i]);
        term += a[i];

    }
    for(int i = 1; i <= n; i++)
    {
        scanf("%d",&b[i]);
    }
    for(int i = 1; i <= n; i++)
    {
        c[i] = b[i]/a[i];
    }
    int min = c[1];
    int max = c[1];
    for(int i = 2; i <= n; i++)
    {
        if(c[i] < min)
        {
            min = c[i];
        }
        if(c[i] > max)
        {
            max = c[i];
        }
    }
    max += k/term;
    long long l = min, r = max;
    long long sum = r;
    while(l < r)
    {
        long long mid = (l+r)>>1;
        if(f(mid,k))
        {
            sum = mid;
            r = mid - 1;
        }
        else
        {
            sum = mid;
            l = mid+1;
        }

    }
    cout<<sum<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n, k;
int a[1001],b[1001],c[1001];
int f(long long x,int m)
{
    for(int i= 1; i <= n; i++)
    {
        if(b[i] < a[i]*x)
        m = m-(a[i]*x-b[i]);
    }
    if(m < 0) return 1;
    else if(m==0) return 2;
    else return 0;
}
int main()
{
    scanf("%d%d",&n,&k);
    long long term = 0;
    for(int i = 1; i <= n; i++)
    {
        scanf("%d",&a[i]);
        term += a[i];

    }
    for(int i = 1; i <= n; i++)
    {
        scanf("%d",&b[i]);
    }
    for(int i = 1; i <= n; i++)
    {
        c[i] = b[i]/a[i];
    }
    int min = c[1];
    int max = c[1];
    for(int i = 2; i <= n; i++)
    {
        if(c[i] < min)
        {
            min = c[i];
        }
        if(c[i] > max)
        {
            max = c[i];
        }
    }
    max += k/term;
    long long l = min, r = max;
    long long sum = r;
    while(l <= r)
    {
        long long mid = (l+r)>>1;
        if(f(mid,k)==1)
        {
            r = mid - 1;
        }
        else if(f(mid,k)==0)
        {
            sum = mid;
            l = mid+1;
        }
        else
        {
            sum = mid;
            break;
        }

    }
    cout<<sum<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n, k;
int a[1001],b[1001],c[1001];
int f(long long x,int m)
{
    for(int i= 1; i <= n; i++)
    {
        if(b[i] < a[i]*x)
        m = m-(a[i]*x-b[i]);
        if(m < 0) break;
    }
    if(m <= 0) return 1;
    else return 0;
}
int main()
{
    scanf("%d%d",&n,&k);
    long long term = 0;
    for(int i = 1; i <= n; i++)
    {
        scanf("%d",&a[i]);
        term += a[i];

    }
    for(int i = 1; i <= n; i++)
    {
        scanf("%d",&b[i]);
    }
    for(int i = 1; i <= n; i++)
    {
        c[i] = b[i]/a[i];
    }
    int min = c[1];
    int max = c[1];
    for(int i = 2; i <= n; i++)
    {
        if(c[i] < min)
        {
            min = c[i];
        }
        if(c[i] > max)
        {
            max = c[i];
        }
    }
    max += k/term;
    long long l = min, r = max;
    long sum = r;
    while(l <= r)
    {
        long long mid = (l+r)>>1;
        if(f(mid,k))
        {
            sum = mid;
            r = mid - 1;
        }
        else
        {
            l = mid + 1;
        }
    }
    cout<<sum<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n, k;
int a[1001],b[1001],c[1001];
int f(long long x,int m)
{
    for(int i= 1; i <= n; i++)
    {
        if(b[i] < a[i]*x)
        m = m-(a[i]*x-b[i]);
    }
    if(m < 0) return 1;
    else return 0;
}
int main()
{
    scanf("%d%d",&n,&k);
    long long term = 0;
    for(int i = 1; i <= n; i++)
    {
        scanf("%d",&a[i]);
        term += a[i];

    }
    for(int i = 1; i <= n; i++)
    {
        scanf("%d",&b[i]);
    }
    for(int i = 1; i <= n; i++)
    {
        c[i] = b[i]/a[i];
    }
    int min = c[1];
    int max = c[1];
    for(int i = 2; i <= n; i++)
    {
        if(c[i] < min)
        {
            min = c[i];
        }
        if(c[i] > max)
        {
            max = c[i];
        }
    }
    max += k/term;
    long long l = min, r = max;
    long long sum = r;
    while(l <= r)
    {
        long long mid = (l+r)>>1;
        if(f(mid,k))
        {
            if(l==r)
            {
                sum = l -1;
                break;
            }
            else
            {
                sum = mid;
                r = mid - 1;
            }
        }
        else
        {
            l = mid+1;
        }

    }
    cout<<sum<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n;
long long k;
int a[100001],b[100001],c[100001];
int f(long long x,long long m)
{
    for(int i= 1; i <= n; i++)
    {
        if(b[i] < a[i]*x)
        m = m-(a[i]*x-b[i]);
    }
    if(m < 0) return 1;
    else if(m==0) return 2;
    else return 0;
}
int main()
{
    scanf("%d%I64d",&n,&k);
    long long term = 0;
    for(int i = 1; i <= n; i++)
    {
        scanf("%d",&a[i]);
        term += a[i];

    }
    for(int i = 1; i <= n; i++)
    {
        scanf("%d",&b[i]);
    }
    for(int i = 1; i <= n; i++)
    {
        c[i] = b[i]/a[i];
    }
    int min = c[1];
    int max = c[1];
    for(int i = 2; i <= n; i++)
    {
        if(c[i] < min)
        {
            min = c[i];
        }
        if(c[i] > max)
        {
            max = c[i];
        }
    }
    max += k/term;
    long long l = min, r = max;
    long long sum = r;
    while(l <= r)
    {
        long long mid = (l+r)>>1;
        if(f(mid,k)==1)
        {
            r = mid - 1;
        }
        else if(f(mid,k)==0)
        {
            sum = mid;
            l = mid+1;
        }
        else
        {
            sum = mid;
            break;
        }

    }
    cout<<sum<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n, k;
int a[1001],b[1001],c[1001];
int f(long long x,int m)
{
    for(int i= 1; i <= n; i++)
    {
        if(b[i] < a[i]*x)
        m = m-(a[i]*x-b[i]);
        if(m < 0) break;
    }
    if(m <= 0) return 1;
    else return 0;
}
int main()
{
    scanf("%d%d",&n,&k);
    long long term = 0;
    for(int i = 1; i <= n; i++)
    {
        scanf("%d",&a[i]);
        term += a[i];

    }
    for(int i = 1; i <= n; i++)
    {
        scanf("%d",&b[i]);
    }
    for(int i = 1; i <= n; i++)
    {
        c[i] = b[i]/a[i];
    }
    int min = c[1];
    int max = c[1];
    for(int i = 2; i <= n; i++)
    {
        if(c[i] < min)
        {
            min = c[i];
        }
        if(c[i] > max)
        {
            max = c[i];
        }
    }
    max += k/term;
    long long l = min, r = max+1;
    long sum = r;
    while(l <= r)
    {
        long long mid = (l+r)>>1;
        if(f(mid,k))
        {
            sum = mid;
            r = mid - 1;
        }
        else
        {
            l = mid + 1;
        }
    }
    cout<<sum<<endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

long int arr[100001],had[100001],sum[100001];
vector < pair<int,int> > index;
int main()
{
    ios_base::sync_with_stdio(false);
    long int n,k;
    scanf("%ld %ld",&n,&k);

    for(int i=0; i<n; i++)
        scanf("%ld",&arr[i]);

    for(int i=0; i<n; i++)
        scanf("%ld",&had[i]);

    long int ans=INT_MAX;
    for(int i=0; i<n; i++){
        sum[i]=had[i]/arr[i];
        ans=min(ans,sum[i]);
        /// first is sum , 2nd is place(index).
        index.push_back(make_pair(sum[i],i));
    }
     sort(index.begin(),index.end());
     long int add=0,newadd=0;
     for(int i=0; i<index.size(); i++)
     {
        long int Wanttoadd=arr[index[i].second]-(had[index[i].second]%arr[index[i].second]);
        //cout<<"Wanttoadd -> "<<Wanttoadd<<" "<<k<<endl;
        if(k>=Wanttoadd)
        {
            k=k-Wanttoadd;
            newadd+=arr[index[i].second];
        }
        else break;

        if((index[i].first!=index[i+1].first&&i+1!=index.size())||i==index.size()-1)
        {
            long int m=1;
            if(i<index.size()-1)
                m=index[i+1].first-index[i].first;
           if(k>=add){
            k=k-add;
            add+=newadd; newadd=0;
            ans++; m--;

            m=min((k/add),m);
            ans+=m; k=k-(add*m);
           }
           else break;
        }

     }

    if(add!=0)ans+=(k/add);

    if(ans!=INT_MAX)printf("%ld\n",ans);
    else printf("0\n");
   return 0;
}


#include <bits/stdc++.h>

using namespace std;

long int arr[100001],had[100001],sum[100001];
vector < pair<int,int> > index;
int main()
{
    long int n,k;
    scanf("%ld %ld",&n,&k);

    for(int i=0; i<n; i++)
        scanf("%ld",&arr[i]);

    for(int i=0; i<n; i++)
        scanf("%ld",&had[i]);

    long int ans=INT_MAX;
    for(int i=0; i<n; i++){
        sum[i]=had[i]/arr[i];
        ans=min(ans,sum[i]);
        /// first is sum , 2nd is place(index).
        index.push_back(make_pair(sum[i],i));
    }
     sort(index.begin(),index.end());
     long int add=0,newadd=0;
     for(int i=0; i<index.size(); i++)
     {
        long int Wanttoadd=arr[index[i].second]-(had[index[i].second]%arr[index[i].second]);
       // cout<<"Wanttoadd -> "<<Wanttoadd<<" "<<k<<endl;
        if(k>=Wanttoadd)
        {
            k=k-Wanttoadd;
            newadd+=arr[index[i].second];
        }
        else break;

        if(index[i].first!=index[i+1].first)
        {
           if(k>=add){
            k=k-add;
            add+=newadd; newadd=0;
            ans++;
           }
           else break;
        }

     }
    if(add!=0)ans+=(k/add);

    if(ans!=INT_MAX)printf("%ld\n",ans);
    else printf("0\n");
   return 0;
}


#include <bits/stdc++.h>

using namespace std;

long int arr[100001],had[100001],sum[100001];
vector < pair<int,int> > index;
int main()
{
    long int n,k;
    scanf("%ld %ld",&n,&k);

    for(int i=0; i<n; i++)
        scanf("%ld",&arr[i]);

    for(int i=0; i<n; i++)
        scanf("%ld",&had[i]);

    long int ans=INT_MAX;
    for(int i=0; i<n; i++){
        sum[i]=had[i]/arr[i];
        ans=min(ans,sum[i]);
        /// first is sum , 2nd is place(index).
        index.push_back(make_pair(sum[i],i));
    }
     sort(index.begin(),index.end());
     long int add=0,newadd=0;
     for(int i=0; i<index.size(); i++)
     {
        long int Wanttoadd=arr[index[i].second]-(had[index[i].second]%arr[index[i].second]);
        //cout<<"Wanttoadd -> "<<Wanttoadd<<" "<<k<<endl;
        if(k>=Wanttoadd)
        {
            k=k-Wanttoadd;
            newadd+=arr[index[i].second];
        }
        else break;

        if(index[i].first!=index[i+1].first||i==index.size()-1)
        {
           if(k>=add){
            k=k-add;
            add+=newadd; newadd=0;
            ans++;
           }
           else break;
        }

     }
    if(add!=0)ans+=(k/add);

    if(ans!=INT_MAX)printf("%ld\n",ans);
    else printf("0\n");
   return 0;
}


#include <bits/stdc++.h>

using namespace std;

long int arr[100001],had[100001],sum[100001];
vector < pair<int,int> > index;
int main()
{
    long int n,k;
    scanf("%ld %ld",&n,&k);

    for(int i=0; i<n; i++)
        scanf("%ld",&arr[i]);

    for(int i=0; i<n; i++)
        scanf("%ld",&had[i]);

    long int ans=INT_MAX;
    for(int i=0; i<n; i++){
        sum[i]=had[i]/arr[i];
        ans=min(ans,sum[i]);
        /// first is sum , 2nd is place(index).
        index.push_back(make_pair(sum[i],i));
    }
     sort(index.begin(),index.end());
     long int add=0,newadd=0;
     for(int i=0; i<index.size(); i++)
     {
        long int Wanttoadd=arr[index[i].second]-(had[index[i].second]%arr[index[i].second]);
        //cout<<"Wanttoadd -> "<<Wanttoadd<<" "<<k<<endl;
        if(k>=Wanttoadd)
        {
            k=k-Wanttoadd;
            newadd+=arr[index[i].second];
        }
        else break;

        if((index[i].first!=index[i+1].first&&i+1!=index.size())||i==index.size()-1)
        {
            long int m=1;
            if(i<index.size()-1)
                m=index[i+1].first-index[i].first;
           if(k>=add){
            k=k-add;
            add+=newadd; newadd=0;
            ans++; m--;

            m=min((k/add),m);
            ans+=m; k=k-(add*m);
           }
           else break;
        }

     }

    if(add!=0)ans+=(k/add);

    if(ans!=INT_MAX)printf("%ld\n",ans);
    else printf("0\n");
   return 0;
}


#include <bits/stdc++.h>

using namespace std;

long int arr[100001],had[100001],sum[100001];
vector < pair<int,int> > index;
int main()
{
    long int n,k;
    scanf("%ld %ld",&n,&k);

    for(int i=0; i<n; i++)
        scanf("%ld",&arr[i]);

    for(int i=0; i<n; i++)
        scanf("%ld",&had[i]);

    long int ans=INT_MAX;
    for(int i=0; i<n; i++){
        sum[i]=had[i]/arr[i];
        ans=min(ans,sum[i]);
   //     cout<<sum[i]<<" ";
        /// first is sum , 2nd is place(index).
        index.push_back(make_pair(sum[i],i));
    }
   // printf("\n\n");
     sort(index.begin(),index.end());
     long int add=0,newadd=0;
     for(int i=0; i<index.size(); i++)
     {
        long int Wanttoadd=arr[index[i].second]-(had[index[i].second]%arr[index[i].second]);
       // cout<<"Wanttoadd -> "<<Wanttoadd<<" "<<k<<endl;
        if(k>Wanttoadd)
        {
            k=k-Wanttoadd;
            newadd+=arr[index[i].second];
        }
        else break;

        if(index[i].first!=index[i+1].first)
        {
           if(k>=add){
            k=k-add;
            add+=newadd; newadd=0;
            ans++;
           }
           else break;
        }

     }
    if(add!=0)ans+=(k/add);

    if(ans!=INT_MAX)printf("%ld\n",ans);
    else printf("0\n");
   return 0;
}


#include <algorithm>
#include <cstdio>
#include <queue>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 10;
int a[maxn], b[maxn];
struct Point{
    int id, v, res;
    Point(int id = 0, int v = 0, int res = 0) : id(id), v(v), res(res) {}
    bool operator < (const Point &rhs) const{
        return v > rhs.v;
    }
};
priority_queue<Point> q;
Point str[maxn];
int n, k, ans;
int main(){
    //freopen("in.txt", "r", stdin);
    while(~scanf("%d%d", &n, &k)){
        for(int i = 0; i < n; i++) scanf("%d", &a[i]);
        for(int i = 0; i < n; i++) scanf("%d", &b[i]);
        while(!q.empty()) q.pop();
        for(int i = 0; i < n; i++) q.push(Point(i, b[i] / a[i], b[i] % a[i]));
        for(;;){
            int cnt = 0;
            Point tem = q.top();
            while(!q.empty()){
                Point tt = q.top();
                if(tt.v != tem.v) break;
                q.pop();
                str[cnt++] = tt;
            }
            ll all = 0;
            for(int i = 0; i < cnt; i++) all += a[str[i].id] - str[i].res;
            if(all > k) { ans = str[0].v; break;}
            k -= all;
            all = 0;
            for(int i = 0; i < cnt; i++) all += a[str[i].id];
            if(q.empty()){ ans = str[0].v + 1 + (k / all); break; }
            Point rt = q.top();
            int uuu = k / all;
            if(str[0].v + uuu + 1 < rt.v) { ans = str[0].v + uuu + 1; break; }
            k -= all * (rt.v - str[0].v - 1);
            for(int i = 0; i < cnt; i++) str[i].v = rt.v, str[i].res = 0;
            for(int i = 0; i < cnt; i++) q.push(str[i]);
        }
        printf("%d\n", ans);
    }
    return 0;
}


#include <algorithm>
#include <cstdio>
#include <queue>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 10;
int a[maxn], b[maxn];
struct Point{
    int id, v, res;
    Point(int id = 0, int v = 0, int res = 0) : id(id), v(v), res(res) {}
    bool operator < (const Point &rhs) const{
        return v > rhs.v;
    }
};
priority_queue<Point> q;
Point str[maxn];
int n, k, ans;
int main(){
    //freopen("in.txt", "r", stdin);
    while(~scanf("%d%d", &n, &k)){
        for(int i = 0; i < n; i++) scanf("%d", &a[i]);
        for(int i = 0; i < n; i++) scanf("%d", &b[i]);
        while(!q.empty()) q.pop();
        for(int i = 0; i < n; i++) q.push(Point(i, b[i] / a[i], b[i] % a[i]));
        for(;;){
            int cnt = 0;
            Point tem = q.top();
            while(!q.empty()){
                Point tt = q.top();
                if(tt.v != tem.v) break;
                q.pop();
                str[cnt++] = tt;
            }
            ll all = 0;
            for(int i = 0; i < cnt; i++) all += a[str[i].id] - str[i].res;
            if(all > k) { ans = str[0].v; break;}
            k -= all;
            all = 0;
            for(int i = 0; i < cnt; i++) all += a[i];
            if(q.empty()){ ans = str[0].v + 1 + (k / all); break; }
            Point rt = q.top();
            int uuu = k / all;
            if(str[0].v + uuu + 1 < rt.v) { ans = str[0].v + uuu + 1; break; }
            k -= all * (rt.v - str[0].v - 1);
            for(int i = 0; i < cnt; i++) str[i].v = rt.v, str[i].res = 0;
            for(int i = 0; i < cnt; i++) q.push(str[i]);
        }
        printf("%d\n", ans);
    }
    return 0;
}


#include <algorithm>
#include <cstdio>
#include <queue>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 10;
int a[maxn], b[maxn];
struct Point{
    int id, v, res;
    Point(int id = 0, int v = 0, int res = 0) : id(id), v(v), res(res) {}
    bool operator < (const Point &rhs) const{
        return v > rhs.v;
    }
};
priority_queue<Point> q;
Point str[maxn];
int n, k, ans;
int main(){
    //freopen("in.txt", "r", stdin);
    while(~scanf("%d%d", &n, &k)){
        for(int i = 0; i < n; i++) scanf("%d", &a[i]);
        for(int i = 0; i < n; i++) scanf("%d", &b[i]);
        while(!q.empty()) q.pop();
        for(int i = 0; i < n; i++) q.push(Point(i, b[i] / a[i], b[i] % a[i]));
        for(;;){
            int cnt = 0;
            Point tem = q.top();
            while(!q.empty()){
                Point tt = q.top();
                if(tt.v != tem.v) break;
                q.pop();
                str[cnt++] = tt;
            }
            if(q.empty()){
                ll all = 0;
                for(int i = 0; i < cnt; i++) all += a[str[i].id] - str[i].res;
                if(all > k) { ans = str[0].v; break;}
                k -= all;
                all = 0;
                for(int i = 0; i < cnt; i++) all += a[i];
                ans = str[0].v + 1 + (k / all);
                break;
            }
            Point rt = q.top();
            ll all = 0;
            for(int i = 0; i < cnt; i++){
                int temp = a[str[i].id];
                int rhs = str[i].res;
                all += temp - rhs;
            }
            if(all > k) { ans = str[0].v; break; }
            k -= all;
            all = 0;
            for(int i = 0; i < cnt; i++){
                int fuck = str[i].id;
                all += a[fuck];
            }
            int uuu = k / all;
            if(str[0].v + uuu + 1 < rt.v) { ans = str[0].v + uuu + 1; break; }
            k -= all * (rt.v - str[0].v - 1);
            for(int i = 0; i < cnt; i++) str[i].v = rt.v, str[i].res = 0;
            for(int i = 0; i < cnt; i++) q.push(str[i]);
        }
        printf("%d\n", ans);
    }
    return 0;
}


#include <algorithm>
#include <cstdio>
#include <queue>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 10;
int a[maxn], b[maxn];
struct Point{
    int id, v, res;
    Point(int id = 0, int v = 0, int res = 0) : id(id), v(v), res(res) {}
    bool operator < (const Point &rhs) const{
        return v < rhs.v;
    }
}t[maxn];
int n, k, ans;
int main(){
    //freopen("in.txt", "r", stdin);
    while(~scanf("%d%d", &n, &k)){
        for(int i = 0; i < n; i++) scanf("%d", &a[i]);
        for(int i = 0; i < n; i++) scanf("%d", &b[i]);
        for(int i = 0; i < n; i++) t[i] = Point(i, b[i] / a[i], b[i] % a[i]);
        sort(t, t + n);
        int i = 0;
        ll tot = 0, level, tem;
        while(i < n){
            int j = i;
            level = tem = 0;
            while(i < n && t[j].v == t[i].v){
                tem += a[t[i].id];
                level += a[t[i].id] - t[i].res;
                ++i;
            }
            ans = t[j].v;
            if(k < level + tot) break;
            ans++;
            k -= level + tot;
            tot += tem;
            int times = k / tot;
            if(i >= n || t[i].v > times + 1 + t[j].v){
                ans = times + 1 + t[j].v;
                break;
            }
            times = t[i].v - t[j].v - 1;
            k -= times * tot;
            ans = t[i].v;
        }
        printf("%d\n", ans);
    }
    return 0;
}


#include <algorithm>
#include <cstdio>
#include <queue>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 10;
int a[maxn], b[maxn];
struct Point{
    int id, v, res;
    Point(int id = 0, int v = 0, int res = 0) : id(id), v(v), res(res) {}
    bool operator < (const Point &rhs) const{
        return v > rhs.v;
    }
};
priority_queue<Point> q;
priority_queue<Point> qq;
Point str[maxn];
int n, k, ans;
int main(){
    //freopen("in.txt", "r", stdin);
    while(~scanf("%d%d", &n, &k)){
        for(int i = 0; i < n; i++) scanf("%d", &a[i]);
        for(int i = 0; i < n; i++) scanf("%d", &b[i]);
        while(!q.empty()) q.pop();
        for(int i = 0; i < n; i++) q.push(Point(i, b[i] / a[i], b[i] % a[i]));
        for(;;){
            int cnt = 0;
            Point tem = q.top();
            while(!q.empty()){
                Point tt = q.top();
                if(tt.v != tem.v) break;
                q.pop();
                str[cnt++] = tt;
            }
            if(q.empty()){
                ll all = 0;
                for(int i = 0; i < cnt; i++) all += a[str[i].id] - str[i].res;
                if(all > k) { ans = str[0].v; break;}
                k -= all;
                all = 0;
                for(int i = 0; i < cnt; i++) all += a[i];
                ans = str[0].v + 1 + (k / all);
                break;
            }
            Point rt = q.top();
            ll all = 0;
            for(int i = 0; i < cnt; i++){
                int temp = a[str[i].id];
                int rhs = str[i].res;
                all += temp - rhs;
            }
            if(all > k) { ans = str[0].v; break; }
            k -= all;
            all = 0;
            for(int i = 0; i < cnt; i++){
                int fuck = str[i].id;
                all += a[fuck];
            }
            int uuu = k / all;
            if(str[0].v + uuu + 1 < rt.v) { ans = str[0].v + uuu + 1; break; }
            k -= all * uuu;
            for(int i = 0; i < cnt; i++) str[i].v = rt.v, str[i].res = 0;
            for(int i = 0; i < cnt; i++) q.push(str[i]);
        }
        printf("%d\n", ans);
    }
    return 0;
}


//By Ralif Rakhmatullin
#include<iostream>
#include<fstream>
#include<string>
#include<cstring>
#include<math.h>
#include<cassert>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<stack>
#include<set>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<bitset>
#include<valarray>
#include<iterator>
#include<list>
#define ll long long
#define ull unsigned long long
#define mp make_pair
#define S second
#define F first
#define y1 LOL
#define pb push_back
#define len length
#define sz size
#define beg begin
const ll inf=(ll)1e10;
const int mod=1e9+7;
using namespace std;
ll n, k;
ll a[100011], b[100011];
ll ans = 0;
bool check(ll v){
	ll sum = 0;
	for(int i = 1; i <= n; i ++){
		sum += max(0ll, a[i] * v - b[i]);
	}
	if(sum <= k){
		ans = max(ans, v);
		return 1;
	}
	return 0;
}
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	//cout.tie(0);
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	cin >> n >> k;
	for(int i = 1; i <= n; i ++){
		cin >> a[i];
	}
	for(int i = 1; i <= n; i ++){
		cin >> b[i];
	}
	ll l = 1, r = inf;
	while(l <= r){
		ll mid = (r + l) / 2;
		if(check(mid)){
			l = mid + 1;
		}else
			r = mid - 1;
	}
	cout << ans;
	return 0;
}


//By Ralif Rakhmatullin
#include<iostream>
#include<fstream>
#include<string>
#include<cstring>
#include<math.h>
#include<cassert>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<stack>
#include<set>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<bitset>
#include<valarray>
#include<iterator>
#include<list>
#define ll long long
#define ull unsigned long long
#define mp make_pair
#define S second
#define F first
#define y1 LOL
#define pb push_back
#define len length
#define sz size
#define beg begin
const ll inf=(ll)1e9 * 2;
const int mod=1e9+7;
using namespace std;
ll n, k;
ll a[100011], b[100011];
ll ans = 0;
bool check(ll v){
	ll sum = 0;
	for(int i = 1; i <= n; i ++){
		sum += max(0ll, a[i] * v - b[i]);
	}
	if(sum <= k){
		ans = max(ans, v);
		return 1;
	}
	return 0;
}
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	//cout.tie(0);
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	cin >> n >> k;
	for(int i = 1; i <= n; i ++){
		cin >> a[i];
	}
	for(int i = 1; i <= n; i ++){
		cin >> b[i];
	}
	ll l = 0, r = inf;
	while(l <= r){
		ll mid = (r + l) / 2;
		if(check(mid)){
			l = mid + 1;
		}else
			r = mid - 1;
	}
	cout << ans;
	return 0;
}


//By Ralif Rakhmatullin
#include<iostream>
#include<fstream>
#include<string>
#include<cstring>
#include<math.h>
#include<cassert>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<stack>
#include<set>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<bitset>
#include<valarray>
#include<iterator>
#include<list>
#define ll long long
#define ull unsigned long long
#define mp make_pair
#define S second
#define F first
#define y1 LOL
#define pb push_back
#define len length
#define sz size
#define beg begin
const ll inf=(ll)1e9 * 2;
const int mod=1e9+7;
using namespace std;
ll n, k;
ll a[100011], b[100011];
ll ans = 0;
bool check(ll v){
	ll sum = 0;
	for(int i = 1; i <= n; i ++){
		sum += max(0ll, a[i] * v - b[i]);
	}
	if(sum <= k){
		ans = max(ans, v);
		return 1;
	}
	return 0;
}
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	//cout.tie(0);
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	cin >> n >> k;
	for(int i = 1; i <= n; i ++){
		cin >> a[i];
	}
	for(int i = 1; i <= n; i ++){
		cin >> b[i];
	}
	ll l = 1, r = inf;
	while(l <= r){
		ll mid = (r + l) / 2;
		if(check(mid)){
			l = mid + 1;
		}else
			r = mid - 1;
	}
	cout << ans;
	return 0;
}


//By Ralif Rakhmatullin
#include<iostream>
#include<fstream>
#include<string>
#include<cstring>
#include<math.h>
#include<cassert>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<stack>
#include<set>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<bitset>
#include<valarray>
#include<iterator>
#include<list>
#define ll long long
#define ull unsigned long long
#define mp make_pair
#define S second
#define F first
#define y1 LOL
#define pb push_back
#define len length
#define sz size
#define beg begin
const ll inf=(ll)2e9;
const int mod=1e9+7;
using namespace std;
ll n, k;
ll a[200011], b[200011];
ll ans = 0;
bool check(ll v){
	ll sum = 0;
	for(int i = 1; i <= n; i ++){
		sum += max(0ll, a[i] * v - b[i]);
	}
	if(sum <= k){
		ans = max(ans, v);
		return 1;
	}
	return 0;
}
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	//cout.tie(0);
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	cin >> n >> k;
	for(int i = 1; i <= n; i ++){
		cin >> a[i];
	}
	for(int i = 1; i <= n; i ++){
		cin >> b[i];
	}
	ll l = 0, r = inf;
	while(l <= r){
		ll mid = (r + l) / 2;
		if(check(mid)){
			l = mid + 1;
		}else
			r = mid - 1;
	}
	cout << check(ans);
	return 0;
}


//By Ralif Rakhmatullin
#include<iostream>
#include<fstream>
#include<string>
#include<cstring>
#include<math.h>
#include<cassert>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<stack>
#include<set>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<bitset>
#include<valarray>
#include<iterator>
#include<list>
#define ll long long
#define ull unsigned long long
#define mp make_pair
#define S second
#define F first
#define y1 LOL
#define pb push_back
#define len length
#define sz size
#define beg begin
const int inf=(int)1e9;
const int mod=1e9+7;
using namespace std;
int n, k;
ll a[100011], b[100011];
ll ans = 0;
bool check(ll v){
	ll sum = 0;
	for(int i = 1; i <= n; i ++){
		sum += max(0ll, a[i] * v - b[i]);
	}
	if(sum <= k){
		ans = max(ans, v);
		return 1;
	}
	return 0;
}
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	//cout.tie(0);
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	cin >> n >> k;
	for(int i = 1; i <= n; i ++){
		cin >> a[i];
	}
	for(int i = 1; i <= n; i ++){
		cin >> b[i];
	}
	ll l = 1, r = inf;
	while(l <= r){
		ll mid = (r + l) / 2;
		if(check(mid)){
			l = mid + 1;
		}else
			r = mid - 1;
	}
	cout << ans;
	return 0;
}


//By Ralif Rakhmatullin
#include<iostream>
#include<fstream>
#include<string>
#include<cstring>
#include<math.h>
#include<cassert>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<stack>
#include<set>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<bitset>
#include<valarray>
#include<iterator>
#include<list>
#define ll long long
#define ull unsigned long long
#define mp make_pair
#define S second
#define F first
#define y1 LOL
#define pb push_back
#define len length
#define sz size
#define beg begin
const ll inf=(ll)2e9;
const int mod=1e9+7;
using namespace std;
ll n, k;
ll a[200011], b[200011];
ll ans = 0;
bool check(ll v){
	ll sum = 0;
	for(int i = 1; i <= n; i ++){
		sum += max(0ll, a[i] * v - b[i]);
	}
	if(sum <= k){
		ans = max(ans, v);
		return 1;
	}
	return 0;
}
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	//cout.tie(0);
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	cin >> n >> k;
	for(int i = 1; i <= n; i ++){
		cin >> a[i];
	}
	for(int i = 1; i <= n; i ++){
		cin >> b[i];
	}
	ll l = 0, r = inf;
	while(l <= r){
		ll mid = (r + l) / 2;
		if(check(mid)){
			l = mid + 1;
		}else
			r = mid - 1;
	}
	cout << ans;
	return 0;
}


//By Ralif Rakhmatullin
#include<iostream>
#include<fstream>
#include<string>
#include<cstring>
#include<math.h>
#include<cassert>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<stack>
#include<set>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<bitset>
#include<valarray>
#include<iterator>
#include<list>
#define ll long long
#define ull unsigned long long
#define mp make_pair
#define S second
#define F first
#define y1 LOL
#define pb push_back
#define len length
#define sz size
#define beg begin
const ll inf=(ll)1e18;
const int mod=1e9+7;
using namespace std;
int n, k;
ll a[100011], b[100011];
ll ans = 0;
bool check(ll v){
	ll sum = 0;
	for(int i = 1; i <= n; i ++){
		sum += max(0ll, a[i] * v - b[i]);
	}
	if(sum <= k){
		ans = max(ans, v);
		return 1;
	}
	return 0;
}
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	//cout.tie(0);
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	cin >> n >> k;
	for(int i = 1; i <= n; i ++){
		cin >> a[i];
	}
	for(int i = 1; i <= n; i ++){
		cin >> b[i];
	}
	ll l = 1, r = inf;
	while(l <= r){
		ll mid = (r + l) / 2;
		if(check(mid)){
			l = mid + 1;
		}else
			r = mid - 1;
	}
	cout << ans;
	return 0;
}


//By Ralif Rakhmatullin
#include<iostream>
#include<fstream>
#include<string>
#include<cstring>
#include<math.h>
#include<cassert>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<stack>
#include<set>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<bitset>
#include<valarray>
#include<iterator>
#include<list>
#define ll long long
#define ull unsigned long long
#define mp make_pair
#define S second
#define F first
#define y1 LOL
#define pb push_back
#define len length
#define sz size
#define beg begin
const int inf=(int)1e10;
const int mod=1e9+7;
using namespace std;
int n, k;
ll a[100011], b[100011];
ll ans = 0;
bool check(ll v){
	ll sum = 0;
	for(int i = 1; i <= n; i ++){
		sum += max(0ll, a[i] * v - b[i]);
		if(sum > k){
			return 0;
		}
	}
	if(sum <= k){
		ans = max(ans, v);
		return 1;
	}
	return 0;
}
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	//cout.tie(0);
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	cin >> n >> k;
	for(int i = 1; i <= n; i ++){
		cin >> a[i];
	}
	for(int i = 1; i <= n; i ++){
		cin >> b[i];
	}
	ll l = 1, r = inf;
	while(l <= r){
		ll mid = (r + l) / 2;
		if(check(mid)){
			l = mid + 1;
		}else
			r = mid - 1;
	}
	cout << ans;
	return 0;
}


//By Ralif Rakhmatullin
#include<iostream>
#include<fstream>
#include<string>
#include<cstring>
#include<math.h>
#include<cassert>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<stack>
#include<set>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<bitset>
#include<valarray>
#include<iterator>
#include<list>
#define ll long long
#define ull unsigned long long
#define mp make_pair
#define S second
#define F first
#define y1 LOL
#define pb push_back
#define len length
#define sz size
#define beg begin
const ll inf=(ll)2e9;
const int mod=1e9+7;
using namespace std;
ll n, k;
ll a[200011], b[200011];
ll ans = 0;
bool check(ll v){
	ll sum = 0;
	for(int i = 1; i <= n; i ++){
		sum += max(0ll, a[i] * v - b[i]);
	}
	if(sum <= k){
		ans = max(ans, v);
		return 1;
	}
	return 0;
}
ll sum, cnt;
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	//cout.tie(0);
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	cin >> n >> k;
	for(int i = 1; i <= n; i ++){
		cin >> a[i];
	}
	for(int i = 1; i <= n; i ++){
		cin >> b[i];
		sum += a[i];
		ans = max(ans, b[i] / a[i]);
	}
	ll l = 0, r = ans + k / sum;
	while(l <= r){
		ll mid = (r + l) / 2;
		if(check(mid)){
			l = mid + 1;
		}else
			r = mid - 1;
	}
	cout << ans;
	return 0;
}


//By Ralif Rakhmatullin
#include<iostream>
#include<fstream>
#include<string>
#include<cstring>
#include<math.h>
#include<cassert>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<stack>
#include<set>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<bitset>
#include<valarray>
#include<iterator>
#include<list>
#define ll long long
#define ull unsigned long long
#define mp make_pair
#define S second
#define F first
#define y1 LOL
#define pb push_back
#define len length
#define sz size
#define beg begin
const ll inf=(ll)1e15;
const int mod=1e9+7;
using namespace std;
ll n, k;
ll a[100011], b[100011];
ll ans = 0;
bool check(ll v){
	ll sum = 0;
	for(int i = 1; i <= n; i ++){
		sum += max(0ll, a[i] * v - b[i]);
	}
	if(sum <= k){
		ans = max(ans, v);
		return 1;
	}
	return 0;
}
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	//cout.tie(0);
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	cin >> n >> k;
	for(int i = 1; i <= n; i ++){
		cin >> a[i];
	}
	for(int i = 1; i <= n; i ++){
		cin >> b[i];
	}
	ll l = 0, r = inf;
	while(l <= r){
		ll mid = (r + l) / 2;
		if(check(mid)){
			l = mid + 1;
		}else
			r = mid - 1;
	}
	cout << ans;
	return 0;
}


#include<stdio.h>
#include<string.h>
#include<queue>
#include<algorithm>
#include<iostream>
using namespace std;
long long a[100001];
long long b[100001];
int main()
{
	long long n,m,k,i;
	while(scanf("%I64d%I64d",&n,&k)!=EOF)
	{
		for(i=0;i<n;i++)
		{
			scanf("%d",&a[i]);
		}
		for(i=0;i<n;i++)
		{
			scanf("%d",&b[i]);
		}
		long long l=0,r=b[0]+k,mid,cnt;
		while(l<=r)
		{
			cnt=0;
			mid=(l+r)/2;
			for(i=0;i<n;i++)
			{
				cnt+=mid-b[i]/a[i];
			}
			if(cnt<=k) l=mid+1;
			else r=mid-1;

		}
		cout<<r<<endl;
	}
}


#include<stdio.h>
#include<string.h>
#include<queue>
#include<algorithm>
#include<iostream>
using namespace std;
__int64 a[100001];
__int64 b[100001];
int main()
{
	__int64 n,m,k,i,c;
	while(scanf("%I64d%I64d",&n,&k)!=EOF)
	{
		for(i=0;i<n;i++)
		{
			scanf("%I64d",&a[i]);
		}
		for(i=0;i<n;i++)
		{
			scanf("%I64d",&b[i]);
		}
		__int64 l=0,r=b[0]+k,mid,cnt;
		while(l<=r)
		{
			cnt=0;
			mid=(l+r)/2;
			for(i=0;i<n;i++)
			{
				if(b[i]/a[i]<mid) c=b[i]/a[i];
				else c=mid;
				if(b[i]/a[i]<mid) cnt+=(mid-c)*a[i]-b[i]%a[i];
				if(cnt>k) break;

			}
			if(cnt<k) l=mid+1;
			else if(cnt==k) break;
			else r=mid-1;
			mid=(l+r)/2;
			//cout<<cnt<<" "<<mid<<endl;
			//cout<<cnt<<" "<<mid<<endl;
		}
		cout<<mid<<endl;
	}
}


#include<stdio.h>
#include<string.h>
#include<queue>
#include<algorithm>
#include<iostream>
using namespace std;
long long a[100001];
long long b[100001];
int main()
{
	__int64 n,m,k,i,c;
	while(scanf("%I64d%I64d",&n,&k)!=EOF)
	{
		for(i=0;i<n;i++)
		{
			scanf("%I64d",&a[i]);
		}
		for(i=0;i<n;i++)
		{
			scanf("%I64d",&b[i]);
		}
		__int64 l=0,r=b[0]+k,mid,cnt;
		while(l<=r)
		{
			cnt=0;
			mid=(l+r)/2;
			for(i=0;i<n;i++)
			{
				if(b[i]/a[i]<mid) c=b[i]/a[i];
				else c=mid;
				if(b[i]/a[i]<mid) cnt+=(mid-c)*a[i]-b[i]%a[i];

			}
			if(cnt<k) l=mid+1;
			else if(cnt==k) break;
			else r=mid-1;
			mid=(l+r)/2;
			//cout<<cnt<<" "<<mid<<endl;
			//cout<<cnt<<" "<<mid<<endl;
		}
		cout<<mid<<endl;
	}
}


#include<stdio.h>
#include<string.h>
#include<queue>
#include<algorithm>
#include<iostream>
using namespace std;
__int64 a[100001];
__int64 b[100001];
int main()
{
	__int64 n,m,k,i,c;
	while(scanf("%I64d%I64d",&n,&k)!=EOF)
	{
		for(i=0;i<n;i++)
		{
			scanf("%I64d",&a[i]);
		}
		for(i=0;i<n;i++)
		{
			scanf("%I64d",&b[i]);
		}
		__int64 l=0,r=b[0]+k,mid,cnt;
		while(l<=r)
		{
			cnt=0;
			mid=(l+r)/2;
			for(i=0;i<n;i++)
			{
				if(b[i]/a[i]<mid) c=b[i]/a[i];
				else c=mid;
				if(b[i]/a[i]<mid) cnt+=(mid-c)*a[i]-b[i]%a[i];

			}
			if(cnt<k) l=mid+1;
			else if(cnt==k) break;
			else r=mid-1;
			mid=(l+r)/2;
			//cout<<cnt<<" "<<mid<<endl;
			//cout<<cnt<<" "<<mid<<endl;
		}
		cout<<mid<<endl;
	}
}


#include<stdio.h>
#include<string.h>
#include<queue>
#include<algorithm>
#include<iostream>
using namespace std;
long long a[100001];
long long b[100001];
int main()
{
	long long n,m,k,i,c;
	while(scanf("%I64d%I64d",&n,&k)!=EOF)
	{
		for(i=0;i<n;i++)
		{
			scanf("%I64d",&a[i]);
		}
		for(i=0;i<n;i++)
		{
			scanf("%I64d",&b[i]);
		}
		long long l=0,r=b[0]+k,mid,cnt;
		while(l<=r)
		{
			cnt=0;
			mid=(l+r)/2;
			for(i=0;i<n;i++)
			{
				if(b[i]/a[i]<mid) c=b[i]/a[i];
				else c=mid;
				cnt+=(mid-c)*a[i];

			}
			if(cnt<=k) l=mid+1;
			else r=mid-1;
			//cout<<cnt<<" "<<mid<<endl;
		}
		cout<<mid<<endl;
	}
}


#include<stdio.h>
#include<string.h>
#include<queue>
#include<algorithm>
#include<iostream>
using namespace std;
long long a[100001];
long long b[100001];
int main()
{
	long long n,m,k,i,c;
	while(scanf("%I64d%I64d",&n,&k)!=EOF)
	{
		for(i=0;i<n;i++)
		{
			scanf("%I64d",&a[i]);
		}
		for(i=0;i<n;i++)
		{
			scanf("%I64d",&b[i]);
		}
		long long l=0,r=b[0]+k,mid,cnt;
		while(l<=r)
		{
			cnt=0;
			mid=(l+r)/2;
			for(i=0;i<n;i++)
			{
				if(b[i]/a[i]<mid) c=b[i]/a[i];
				else c=mid;
				if(b[i]/a[i]<mid) cnt+=(mid-c)*a[i]-b[i]%a[i];

			}
			if(cnt<k) l=mid+1;
			else if(cnt==k) break;
			else r=mid-1;
			mid=(l+r)/2;
			//cout<<cnt<<" "<<mid<<endl;
			//cout<<cnt<<" "<<mid<<endl;
		}
		cout<<mid<<endl;
	}
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
#define maxn 100005
#define INF 2000000000
long long n,k;
long long a[maxn],b[maxn];
int main()
{
    while(scanf("%I64d %I64d",&n,&k)!=EOF){
        for(int i=0;i<n;i++)
            scanf("%I64d",&a[i]);
        for(int i=0;i<n;i++)
            scanf("%I64d",&b[i]);
        long long mid,left=0,right=INF,ans=0;
        while(left<=right){
            long long k1=k;
            mid=(left+right)/2;
            bool flag1=true;
            for(int i=0;i<n;i++){
                if((a[i]*mid>b[i])){
                    if(k1-(a[i]*mid-b[i])>=0)
                        k1=k1-a[i]*mid+b[i];
                    else{
                        flag1=false;
                        break;
                    }
                }
            }
            if(flag1){
                ans=max(ans,mid);
                left=mid+1;
            }
            else right=mid-1;
        }
        printf("%I64d\n",ans);
    }
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
#define maxn 100005
int n,k;
int a[maxn],b[maxn];
bool solve(long long x)
{
    int ans=0;
    for(int i=0;i<n;i++){
        int c=x*a[i]-b[i];
        if(c>0) ans+=c;
        if(ans>k) return false;
    }
    //cout<<ans<<endl;
    if(ans>k) return false;
    else return true;
}
int main()
{
    while(scanf("%d %d",&n,&k)!=EOF){
        for(int i=0;i<n;i++)
            scanf("%d",&a[i]);
        for(int i=0;i<n;i++)
            scanf("%d",&b[i]);
        int m=0,pos;
        for(int i=0;i<n;i++){
                int x=b[i]+k;
                m=max(m,x/a[i]);
        }
        long long left=0,right=m+1;
        while(right-left>1){
            long long mid=(left+right)/2;
            if(solve(mid))
                left=mid;
            else
                right=mid;
        }
        cout<<left<<endl;
    }
    return 0;
}


#include <stdio.h>
#include <string.h>
#include <cmath>
#include <algorithm>

using namespace std;
const int maxn=100010;

struct node
{
  __int64 a,b,c;
};
bool cmp(node a,node b)
{
    return a.c>b.c;
}
node t[maxn];
int main()
{
    __int64 k;
    int n,i,j;
    while(scanf("%d%I64d",&n,&k)==2)
    {
        for(i=0;i<n;i++)
            scanf("%I64d",&t[i].a);
        for(i=0;i<n;i++)
            scanf("%I64d",&t[i].b);
        for(i=0;i<n;i++)
            t[i].c=t[i].b/t[i].a;
        sort(t,t+n,cmp);
        int v,d;
        __int64 R,r;
        v=d=0;
        R=r=0;
        for(i=0;i<n;i++)
        {
            __int64 s=k;
            for(j=i+1;j<n;j++)
            {
                if(t[j].c==t[i].c)
                    continue;
                s-=((t[i].c-t[j].c)*t[j].a-t[j].b%t[j].a);
                if(s<0)
                    break;
            }
            if(j==n)
            {
                k=s;
                v=t[i].c;
                R=+t[i].a;
                r+=t[i].b%t[i].a;
                for(int l=i+1;l<n;l++)
                {
                    if(t[l].c==t[i].c)
                        r+=t[l].b%t[l].a;
                    R+=t[l].a;
                }
                if(k>=R-r)
                    v++,k-=(R-r);
                break;
            }
        }
        printf("%I64d\n",v+k/R);
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long LL;
struct node
{
	LL a, b;
}x[100005];
int main()
{
	LL n, k;
	int i, j;
	while (cin >> n >> k)
	{
		for (i = 1; i <= n; ++i)
		{
			scanf("%lld", &x[i].a);
		}
		LL m = 0;
		for (i = 1; i <= n; ++i)
		{
			scanf("%lld", &x[i].b);
			m = max((x[i].b + k) / x[i].a, m);
		}
		LL L = 0, R = m;
		LL mmax = 0;
		while (L <= R)
		{
			LL mid = (L + R) / 2;
			LL p = k;
			LL ans = 0;

			for (i = 1; i <= n; ++i)
			{
				if (x[i].b / x[i].a >= mid)
					continue;
				else
				{
					p -= mid * x[i].a - x[i].b;
				}
				if (p < 0)
				{
					ans = 1;
					break;
				}
			}
			if (ans)
			{
				R = mid - 1;
			}
			else
			{
				mmax = max(mmax, mid);
				L = mid + 1;
			}
		}
		printf("%lld\n", mmax);

	}
}


#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <cstdio>
#include <cstdio>
#include <algorithm>
#include <queue>
using namespace std;
struct node
{
    int need,have,cm;
}el[100010];
int main()
{
    int n,k;
    while(~scanf("%d%d",&n,&k))
    {
        for(int i=0;i<n;i++)
            scanf("%d",&el[i].need);
        for(int j=0;j<n;j++)
        {
            scanf("%d",&el[j].have);
            el[j].cm = el[j].have/el[j].need;
            el[j].have = el[j].have-el[j].cm*el[j].need;
        }
        int Min=1000000005;
        while(k>=0)
        {
            int ii;
            for(int i=0;i<n;i++)
            {
                if(Min>el[i].cm)
                {
                    Min = el[i].cm;
                    ii = i;
                }
            }
            int needk=el[ii].need-el[ii].have%el[ii].need;
            if(k>=needk)
            {
                k = k-needk;
                el[ii].have=el[ii].have+needk;
                el[ii].cm++;
                Min = el[ii].cm;
            }else
                break;
        }
        printf("%d\n",Min);
    }
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
using namespace std;

typedef pair<int, int> P;
typedef  __int64 ULL;
const int INF = 0x3fff3fff;
const int PI = acos(-1);

typedef struct {
    ULL a, b;
} Node;
ULL n, k;
Node nodes[100010];

bool cmp(Node n1, Node n2) {
    return (double)n1.b / (double)n1.a > (double)n2.b / (double)n2.a;
}

bool valid(ULL mid) {
    ULL res = 0, temp = k;
    for(int i = 0; i < n; i++) {
        if(nodes[i].b / nodes[i].a >= mid)res++;
        else if(temp > 0) {
            ULL dest = nodes[i].a * mid;
            temp -= (dest - nodes[i].b);
            if(temp >= 0)res++;
        }
    }
    return res >= n;
}

void solve() {
    sort(nodes, nodes + n, cmp);
    ULL low = 0, high = ((k + nodes[0].b) / nodes[0].a) + 2, mid;
    while(low < high - 1) {
        mid = (high - low) / 2 + low;
        if(valid(mid))low = mid;
        else high = mid;
    }
    printf("%I64u\n", low);
}

int main() {
    //freopen("D:\\ACM\\contest\\cid88\\Ctds.txt", "r", stdin);
    while(~scanf("%I64u%I64u", &n, &k)) {
        for(int i = 0; i < n; i++)scanf("%I64u", &nodes[i].a);
        for(int i = 0; i < n; i++)scanf("%I64u", &nodes[i].b);
        solve();
    }
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
#define maxn 100005
int n,k;
int a[maxn],b[maxn];
bool solve(long long x)
{
    int ans=0;
    for(int i=0;i<n;i++){
        int c=x*a[i]-b[i];
        if(c>0) ans+=c;
        if(ans>k) return false;
    }
    //cout<<ans<<endl;
    if(ans>k) return false;
    else return true;
}
int main()
{
    while(scanf("%d %d",&n,&k)!=EOF){
        for(int i=0;i<n;i++)
            scanf("%d",&a[i]);
        for(int i=0;i<n;i++)
            scanf("%d",&b[i]);
        int m=0,pos;
        for(int i=0;i<n;i++){
            if(b[i]/a[i]>m){
                m=max(m,b[i]/a[i]);
                pos=i;
            }
        }
        m=(b[pos]+k)/a[pos];
        long long left=0,right=m+1;
        while(right-left>1){
            long long mid=(left+right)/2;
            if(solve(mid))
                left=mid;
            else
                right=mid;
        }
        cout<<left<<endl;
    }
    return 0;
}


/*#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<queue>
using namespace std;

int main(){
    __int64 n,m,k,u;
    Node no,ne;
    while(~scanf("%I64d %I64d %I64d",&n,&m,&k)){
        u=min(n,m);

    }
}
*/
#include<stdio.h>
#define ll long long
#define MAX 1e10
ll a[100010],b[100010],n,k;

ll cpp(ll l,ll r){
	ll mid,sum;
	while(l<=r){
		mid=(l+r)/2,sum=0;
		for(int i=0; i<n; i++){
            if(a[i]*mid-b[i]>0){
                sum+=a[i]*mid-b[i];
            }
			else sum+=0;
		}
		if(sum==k) return mid;
		else if(sum<k) l=mid+1;
		else r=mid-1;
	}
	return r;
}

int main(){

	while(~scanf("%lld %lld",&n,&k)){
		for(int i=0; i<n; i++) scanf("%lld",&a[i]);
		for(int i=0; i<n; i++) scanf("%lld",&b[i]);
		ll ans=cpp(0,MAX);
		printf("%lld\n",ans);
	}

}


#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <queue>
#include <vector>
#define inputt int t;cin>>t;
#define pi acos(-1.0)
#define lson o*2,l,m
#define rson o*2+1,m+1,r
#define INF 0x7f7f7f7f
#define lowbit(X) ((X)&(-X))
#define clr(X,Y) memset(X,Y,sizeof(X))
typedef long long ll;
using namespace std;
ll a[100005];
ll b[100005];
int main(){
	ll n,k;
	ll Max=0,Min=1000000000;
	scanf("%I64d%I64d",&n,&k);
	for(int i=0;i<n;i++)scanf("%I64d",&a[i]);
	for(int i=0;i<n;i++){
	scanf("%I64d",&b[i]);
	Max=max(Max,(b[i]+k)/a[i]);
	Min=min(Min,b[i]/a[i]);
	}
	ll m;
	ll ans=0;
	while(Min<Max){
		m=(ll(Min)+Max+1)/2;
		ans=0;
		for(int i=0;i<n;i++){
			if(a[i]*m-b[i]>0)ans+=a[i]*m-b[i];
		}
		if(ans<=k)Min=m;
		else Max=m-1;
	}
	printf("%I64d\n",Min);
	return 0;
}


#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <queue>
#include <vector>
#define inputt int t;cin>>t;
#define pi acos(-1.0)
#define lson o*2,l,m
#define rson o*2+1,m+1,r
#define INF 0x7f7f7f7f
#define lowbit(X) ((X)&(-X))
#define clr(X,Y) memset(X,Y,sizeof(X))
typedef long long ll;
using namespace std;
ll a[100005];
ll b[100005];
int main(){
	int n,k;
	ll Max=0,Min=1000000000;
	scanf("%d%d",&n,&k);
	for(int i=0;i<n;i++)scanf("%I64d",&a[i]);
	for(int i=0;i<n;i++){
	scanf("%I64d",&b[i]);
	Max=max(Max,(b[i]+k)/a[i]);
	Min=min(Min,b[i]/a[i]);
	}
	ll m;
	ll ans=0;
	while(Min<Max){
		m=(ll(Min)+Max+1)/2;
		ans=0;
		for(int i=0;i<n;i++){
			if(a[i]*m-b[i]>0)ans+=a[i]*m-b[i];
		}
		if(ans<=k)Min=m;
		else Max=m-1;
	}
	printf("%I64d\n",Min);
	return 0;
}


#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <queue>
#include <vector>
#define inputt int t;cin>>t;
#define pi acos(-1.0)
#define lson o*2,l,m
#define rson o*2+1,m+1,r
#define INF 0x7f7f7f7f
#define lowbit(X) ((X)&(-X))
#define clr(X,Y) memset(X,Y,sizeof(X))
typedef long long ll;
using namespace std;
ll a[100005];
ll b[100005];
int main(){
	ll n,k;
	ll Max=0,Min=1000000010;
	scanf("%I64d%I64d",&n,&k);
	for(int i=0;i<n;i++)scanf("%I64d",&a[i]);
	for(int i=0;i<n;i++){
	scanf("%I64d",&b[i]);
	Max=max(Max,(b[i]+k)/a[i]);
	Min=min(Min,b[i]/a[i]);
	}
	ll m;
	ll ans=0;
	while(Min<Max){
		m=(Min+Max+1)/2;
		ans=0;
		bool f=0;
		for(int i=0;i<n;i++){
			if(a[i]*m-b[i]>0)ans+=a[i]*m-b[i];
			if(ans>k){
				f=1;
				break;
			}
		}
		if(ans<=k)Min=m;
		else Max=m-1;
	}
	printf("%I64d\n",Min);
	return 0;
}


#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <queue>
#include <vector>
#define inputt int t;cin>>t;
#define pi acos(-1.0)
#define lson o*2,l,m
#define rson o*2+1,m+1,r
#define INF 0x7f7f7f7f
#define lowbit(X) ((X)&(-X))
#define clr(X,Y) memset(X,Y,sizeof(X))
typedef long long ll;
using namespace std;
int a[100005];
int b[100005];
int main(){
	int n,k;
	int Max=0,Min=1000000000;
	scanf("%d%d",&n,&k);
	for(int i=0;i<n;i++)scanf("%d",&a[i]);
	for(int i=0;i<n;i++){
	scanf("%d",&b[i]);
	Max=max(Max,(b[i]+k)/a[i]);
	Min=min(Min,b[i]/a[i]);
	}
	int m;
	int ans=0;
	while(Min<Max){
		m=(ll(Min)+Max+1)/2;
		ans=0;
		for(int i=0;i<n;i++){
			if(a[i]*m-b[i]>0)ans+=a[i]*m-b[i];
		}
		if(ans<=k)Min=m;
		else Max=m-1;
	}
	printf("%d\n",Min);
	return 0;
}


#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <queue>
#include <vector>
#define inputt int t;cin>>t;
#define pi acos(-1.0)
#define lson o*2,l,m
#define rson o*2+1,m+1,r
#define INF 0x7f7f7f7f
#define lowbit(X) ((X)&(-X))
#define clr(X,Y) memset(X,Y,sizeof(X))
typedef long long ll;
using namespace std;
int a[100005];
int b[100005];
int main(){
	int n,k;
	int Max=0,Min=1000000000;
	scanf("%d%d",&n,&k);
	for(int i=0;i<n;i++)scanf("%d",&a[i]);
	for(int i=0;i<n;i++){
	scanf("%d",&b[i]);
	Max=max(Max,(b[i]+k)/a[i]);
	Min=min(Min,b[i]/a[i]);
	}
	int m;
	int ans=0;
	while(Min<Max){
		m=(Min+Max+1)>>1;
		ans=0;
		for(int i=0;i<n;i++){
			if(a[i]*m-b[i]>0)ans+=a[i]*m-b[i];
		}
		if(ans<=k)Min=m;
		else Max=m-1;
	}
	printf("%d\n",Min);
	return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;

#define ll long long

const int MAXN = 1000 * 100 + 10;
ll a[MAXN], b[MAXN];

ll n, k;

ll BS(ll s, ll e)
{
	if(e - s <= 1)
		return s;

	ll m = (s + e) / 2;

	ll nd = 0;
	for(int i = 0; i < n; i ++)
		nd += max((ll)0, -b[i] + (a[i] * m));

	if(nd <= k)
		return BS(m, e);
	else
		return BS(s, m);
}

int main()
{
	cin>> n >> k;

	for(int i = 0; i < n; i ++)
		cin>> a[i];

	for(int i = 0; i < n; i ++)
		cin>> b[i];

	ll mn = LONG_MAX;
	ll mx = LONG_MIN;
	for(int i = 0; i < n; i ++)
	{
		ll c = b[i] / a[i];
		mn = min(mn, c);
		mx = max(mx, c);
	}

	ll x = BS(0, mx + k + 1);
	cout<< x << endl;

}


#include <iostream>
#include <algorithm>
using namespace std;

#define ll long long

const int MAXN = 1000 * 100 + 10;
ll a[MAXN], b[MAXN], c[MAXN];

ll n, k;

ll BS(ll s, ll e)
{
	if(e - s <= 1)
		return s;

	ll m = (s + e) / 2;

	ll nd = 0;
	for(int i = 0; i < n; i ++)
	{
		if(m <= c[i])
			continue;
		nd += (m - c[i]) * a[i] - b[i];
		if(nd > k)
			return BS(s, m);
	}

	if(nd <= k)
		return BS(m, e);
	else
		return BS(s, m);
}

int main()
{
	cin>> n >> k;

	for(int i = 0; i < n; i ++)
		cin>> a[i];

	for(int i = 0; i < n; i ++)
		cin>> b[i];

	ll mn = LONG_MAX;
	ll mx = LONG_MIN;
	for(int i = 0; i < n; i ++)
	{
		c[i] = b[i] / a[i];
		b[i] = b[i] % a[i];
		mn = min(mn, c[i]);
		mx = max(mx, c[i]);
	}

	ll x = BS(0, mx + k + 1);
	cout<< x << endl;

}


#include <iostream>
#include <algorithm>
using namespace std;

#define ll long long

const int MAXN = 1000 * 100 + 10;
ll a[MAXN], b[MAXN];

ll n, k;

ll BS(ll s, ll e)
{
	if(e - s <= 1)
		return s;

	ll m = (s + e) / 2;

	ll nd = 0;
	for(int i = 0; i < n; i ++)
		nd += max((ll)0, (a[i] * m) - b[i]);

	if(nd <= k)
		return BS(m, e);
	else
		return BS(s, m);
}

int main()
{
	cin>> n >> k;

	for(int i = 0; i < n; i ++)
		cin>> a[i];

	for(int i = 0; i < n; i ++)
		cin>> b[i];

	int mn = INT_MAX;
	int mx = INT_MIN;
	for(int i = 0; i < n; i ++)
	{
		int c = b[i] / a[i];
		mn = min(mn, c);
		mx = max(mx, c);
	}

	ll x = BS(0, mx + k + 1);
	cout<< x << endl;

}


#include <iostream>
#include <algorithm>
using namespace std;

#define ll long long

const int MAXN = 1000 * 100 + 10;
int a[MAXN], b[MAXN];

ll n, k;

ll BS(ll s, ll e)
{
	if(e - s <= 1)
		return s;

	ll m = (s + e) / 2;

	ll nd = 0;
	for(int i = 0; i < n; i ++)
		nd += max(0, (a[i] * m) - b[i]);

	if(nd <= k)
		return BS(m, e);
	else
		return BS(s, m);
}

int main()
{
	cin>> n >> k;

	for(int i = 0; i < n; i ++)
		cin>> a[i];

	for(int i = 0; i < n; i ++)
		cin>> b[i];

	int mn = INT_MAX;
	int mx = INT_MIN;
	for(int i = 0; i < n; i ++)
	{
		int c = b[i] / a[i];
		mn = min(mn, c);
		mx = max(mx, c);
	}

	ll x = BS(0, mx + k + 1);
	cout<< x << endl;

}


#include <iostream>
#include <algorithm>
using namespace std;

#define ll long long

const int MAXN = 1000 * 100 + 10;
ll a[MAXN], b[MAXN];

ll n, k;

ll BS(ll s, ll e)
{
	if(e - s <= 1)
		return s;

	ll m = (s + e) / 2;

	ll nd = 0;
	for(int i = 0; i < n; i ++)
		nd += max((ll)0, -b[i] + (a[i] * m));

	if(nd <= k)
		return BS(m, e);
	else
		return BS(s, m);
}

int main()
{
	cin>> n >> k;

	for(int i = 0; i < n; i ++)
		cin>> a[i];

	for(int i = 0; i < n; i ++)
		cin>> b[i];

	ll x = BS(0, 1000 * 1000 * 1000 * 5);
	cout<< x << endl;

}


#include <iostream>
#include <algorithm>
using namespace std;

#define ll long long

const int MAXN = 1000 * 100 + 10;
ll a[MAXN], b[MAXN];

ll n, k;

ll BS(ll s, ll e)
{
	if(e - s <= 1)
		return s;

	ll m = (s + e) / 2;

	ll nd = 0;
	for(int i = 0; i < n; i ++)
		nd += max((ll)0, -b[i] + (a[i] * m));

	if(nd <= k)
		return BS(m, e);
	else
		return BS(s, m);
}

int main()
{
	cin>> n >> k;

	for(int i = 0; i < n; i ++)
		cin>> a[i];

	for(int i = 0; i < n; i ++)
		cin>> b[i];

	ll x = BS(0, INT_MAX );
	cout<< x << endl;

}


#include <iostream>
#include <algorithm>
using namespace std;

#define ll long long

const int MAXN = 1000 * 100 + 10;
ll a[MAXN], b[MAXN], c[MAXN];

ll n, k;

ll BS(ll s, ll e)
{
	if(e - s <= 1)
		return s;

	ll m = (s + e) / 2;

	ll nd = 0;
	for(int i = 0; i < n; i ++)
	{
		if(m <= c[i])
			continue;
		nd += (m - c[i]) * a[i] - b[i];
	}

	if(nd <= k)
		return BS(m, e);
	else
		return BS(s, m);
}

int main()
{
	cin>> n >> k;

	for(int i = 0; i < n; i ++)
		cin>> a[i];

	for(int i = 0; i < n; i ++)
		cin>> b[i];

	ll mn = LONG_MAX;
	ll mx = LONG_MIN;
	for(int i = 0; i < n; i ++)
	{
		c[i] = b[i] / a[i];
		b[i] = b[i] % a[i];
		mn = min(mn, c[i]);
		mx = max(mx, c[i]);
	}

	ll x = BS(0, mx + k + 1);
	cout<< x << endl;

}


#include <iostream>
#include <algorithm>
using namespace std;

#define ll long long

const int MAXN = 1000 * 100 + 10;
ll a[MAXN], b[MAXN];

ll n, k;

ll BS(ll s, ll e)
{
	if(e - s <= 1)
		return s;

	ll m = (s + e) / 2;

	ll nd = 0;
	for(int i = 0; i < n; i ++)
		nd += max((ll)0, (a[i] * m) - b[i]);

	if(nd <= k)
		return BS(m, e);
	else
		return BS(s, m);
}

int main()
{
	cin>> n >> k;

	for(int i = 0; i < n; i ++)
		cin>> a[i];

	for(int i = 0; i < n; i ++)
		cin>> b[i];

	ll mx = 10000000001;

	ll x = BS(0, mx);
	cout<< x << endl;

}


#include <iostream>
#include <algorithm>
using namespace std;

#define ll long long

const int MAXN = 1000 * 100 + 10;
ll a[MAXN], b[MAXN];

ll n, k;

ll BS(ll s, ll e)
{
	if(e - s <= 1)
		return s;

	ll m = (s + e) / 2;

	ll nd = 0;
	for(int i = 0; i < n; i ++)
		nd += max((ll)0, (a[i] * m) - b[i]);

	if(nd <= k)
		return BS(m, e);
	else
		return BS(s, m);
}

int main()
{
	cin>> n >> k;

	for(int i = 0; i < n; i ++)
		cin>> a[i];

	for(int i = 0; i < n; i ++)
		cin>> b[i];

	ll mn = LONG_MAX;
	ll mx = LONG_MIN;
	for(int i = 0; i < n; i ++)
	{
		ll c = b[i] / a[i];
		mn = min(mn, c);
		mx = max(mx, c);
	}

	ll x = BS(0, mx + k + 1);
	cout<< x << endl;

}


#include <cstdio>

typedef long long ll;
const int maxn=100000;
const int maxk=2000000000;
int n,k,ans,a[maxn],b[maxn];

int main()
{
	scanf("%d%d",&n,&k);
	for(int i=0;i<n;i++)scanf("%d",&a[i]);
	for(int i=0;i<n;i++)scanf("%d",&b[i]);

	unsigned l=0,r=maxk;
	while(l<=r)
	{
		int m=(l+r)/2;ll s=0;
		for(int i=0;i<n;i++)if((ll)a[i]*m>b[i])s+=(ll)a[i]*m-b[i];
		if(s<=k)ans=l,l=m+1;else r=m-1;
	}
	printf("%d\n",ans);

	return 0;
}


#include <cstdio>

typedef long long ll;
const int maxn=100000;
const int maxk=2000000000;
int n,k,ans,a[maxn],b[maxn];

int main()
{
	scanf("%d%d",&n,&k);
	for(int i=0;i<n;i++)scanf("%d",&a[i]);
	for(int i=0;i<n;i++)scanf("%d",&b[i]);

	unsigned l=0,r=maxk;
	while(l<=r)
	{
		int m=(l+r)/2,s=k;
		for(int i=0;i<n;i++)if(s<(ll)a[i]*m-b[i])s=-1;else if((ll)a[i]*m-b[i]>0)s-=a[i]*m-b[i];
		if(s!=-1)ans=m,l=m+1;else r=m-1;
	}
	printf("%d\n",ans);

	return 0;
}


#include <cstdio>

typedef long long ll;
const int maxn=100000;
const int maxk=2000000000;
int n,k,ans,a[maxn],b[maxn];

int main()
{
	for(int i=0;i<n;i++)scanf("%d",&a[i]);
	for(int i=0;i<n;i++)scanf("%d",&b[i]);

	unsigned l=0,r=maxk;
	while(l<=r)
	{
		int m=(l+r)/2;ll s=0;
		for(int i=0;i<n;i++)if((ll)a[i]*m>b[i])s+=(ll)a[i]*m-b[i];
		if(s<=k)ans=l,l=m+1;else r=m-1;
	}
	printf("%d\n",ans);

	return 0;
}


#include <cstdio>

typedef long long ll;
const int maxn=100000;
const int maxk=2000000000;
int n,k,ans,a[maxn],b[maxn];

int main()
{
	scanf("%d%d",&n,&k);
	for(int i=0;i<n;i++)scanf("%d",&a[i]);
	for(int i=0;i<n;i++)scanf("%d",&b[i]);

	unsigned l=0,r=maxk;
	while(l<=r)
	{
		int m=(l+r)/2,s=k;
		for(int i=0;i<n;i++)if(s<(ll)a[i]*m-b[i])s=-1;else s-=a[i]*m-b[i];
		if(s!=-1)ans=l,l=m+1;else r=m-1;
	}
	printf("%d\n",ans);

	return 0;
}


#include <cstdio>

typedef long long ll;
const int maxn=100000;
const int maxk=2000000000;
int n,k,ans,a[maxn],b[maxn];

int main()
{
	scanf("%d%d",&n,&k);
	for(int i=0;i<n;i++)scanf("%d",&a[i]);
	for(int i=0;i<n;i++)scanf("%d",&b[i]);

	unsigned l=0,r=maxk;
	while(l<=r)
	{
		int m=(l+r)/2,s=k;
		for(int i=0;i<n;i++)if(s<(ll)a[i]*m-b[i])s=-1;else s-=a[i]*m-b[i];
		if(s!=-1)ans=m,l=m+1;else r=m-1;
	}
	printf("%d\n",ans);

	return 0;
}


// powered by xpd1  /i love shimokawa_mikuni and i haven't touch my devc for 3 months.
// All of these left only broken history after 12.4.22. sacrifice for my dPXq love.
// on 2012-10-
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <iostream>
#include <cmath>
#include <ctime>
#include <cstring>
#include <ctype.h>
#include <memory>
#include <fstream>
#include <string>
#include <utility>
#include <iomanip>

#include <map>
#include <queue>
#include <vector>
#include <list>
#include <set>
//#include <conio.h>
#define oo 2000000000
#define ol 200000000000000000ll //=2E17
#define ooo 1E14
#define EPS 1E-10
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define eps EPS
#define mem(x,y) (memset((x),y,sizeof((x))))
#define debug(x) cout << #x<<" = "<<x<<endl;
#ifdef __int64
 #define fmt64 "%I64d"
#else
 #define fmt64 "%lld"
#endif
using namespace std;
using namespace rel_ops;
const double PI=acos((double)-1);
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
int ts,ts2,ts3,ts4;
int n,m;
LL gcd(LL x,LL y){LL t;for(;y!=0;){t=x%y;x=y;y=t;}return x;}
double sqr(double x){return x*x;}
int d2=1,d[200005],next[200007],head[200007];
void adde(int x,int y)
{
  d2++,d[d2]=y,next[d2]=head[x],head[x]=d2;
}
int dfn[10005],low[10005],fa[10005],sta[10005],sta2;
int gus[10005],gus2;
void tarjan(int k,int dep)
{
  int i,j,t1,t2;
  sta[++sta2]  = k;
  dfn[k]=low[k]=dep;
  for(j=head[k];j;j=next[j])
  {
   i=d[j];if (fa[k] ==i)continue;
   if (!dfn[i]) {fa[i]=k;tarjan(i,dep+1);low[k]=min(low[k],low[i]);}
   else
    low[k]=min(low[k],dfn[i]);
  }
  if (low[k]==dfn[k])
  {
   gus2++;
   for(;;)
   {
    t1 =sta[sta2];
     gus[t1]=gus2;
    if (sta[sta2]==k)break;
    sta2--;
   }
   sta2--;
  }
}
int chokkei;
set <int>b[10005];
int ans,ha[10005];
int work(int k)
{
  int i,j,l,t1,t2,t3,t4,t5,t6,t7,t8,t9,t,nw,mx1=0,mx2=0;
  ha[k]=1;
  if (b[k].size() ==1 )ans++;
  for(j=head[k];j;j=next[j])
  {
   i=d[j];
   if (ha[i]) continue;
   t1 =work(i);
   if (t1 > mx1) mx2=mx1,mx1=t1;
   else if (t1 > mx2) mx2= t1;
  }
  chokkei=max(chokkei,mx1+mx2+1);
  int max;
  return mx1+1;

}

int main()
{
  int i,j,k,l,t1,t2,t3,t4,t5,t6,t7,t8,t9,t,nw;
  int tt1,tt2,tt3,tt4;
  double u1,u2,u3,u4,u5,u6,u7,u8,u9;
  char c1,c2,c3;
  srand((unsigned)time(0));//srand(72888306);
  #ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
  #endif
  cin >>n>>m;
  for(i=1;i<=m;i++)
  {
   cin >>t1>>t2;
   adde(t1,t2);adde(t2,t1);
  }
  for(i=1;i<=n;i++) if (!dfn[i]) {tarjan(i,1); }  //
  for(i=1;i<=n;i++)
   for(j=head[i];j;j=next[j])
   {
    t1= gus[i]; t2 = gus[d[j]];
    if (t1 !=t2 &&b[t1].find(t2) ==b[t1].end()) b[t1].insert(t2);
   }
  ans =gus2;
  ans=0;
  for(i=1;i<=gus2;i++)
  {
   if (ha[i]) continue;
   chokkei=0;
   work(1);
   ans+=chokkei-2;
   if (chokkei ==1) ans++;
  }

  ans = n-ans;
  printf("%d\n",ans);
  return 0;
}


// powered by xpd1  /i love shimokawa_mikuni and i haven't touch my devc for 3 months.
// All of these left only broken history after 12.4.22. sacrifice for my dPXq love.
// on 2012-10-
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <iostream>
#include <cmath>
#include <ctime>
#include <cstring>
#include <ctype.h>
#include <memory>
#include <fstream>
#include <string>
#include <utility>
#include <iomanip>

#include <map>
#include <queue>
#include <vector>
#include <list>
#include <set>
//#include <conio.h>
#define oo 2000000000
#define ol 200000000000000000ll //=2E17
#define ooo 1E14
#define EPS 1E-10
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define eps EPS
#define mem(x,y) (memset((x),y,sizeof((x))))
#define debug(x) cout << #x<<" = "<<x<<endl;
#ifdef __int64
 #define fmt64 "%I64d"
#else
 #define fmt64 "%lld"
#endif
using namespace std;
using namespace rel_ops;
const double PI=acos((double)-1);
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
int ts,ts2,ts3,ts4;
int n,m;
LL gcd(LL x,LL y){LL t;for(;y!=0;){t=x%y;x=y;y=t;}return x;}
double sqr(double x){return x*x;}
int d2=1,d[200005],next[200007],head[200007];
void adde(int x,int y)
{
  d2++,d[d2]=y,next[d2]=head[x],head[x]=d2;
}
int dfn[10005],low[10005],fa[10005],sta[10005],sta2;
int gus[10005],gus2;
void tarjan(int k,int dep)
{
  int i,j,t1,t2;
  sta[++sta2]  = k;
  dfn[k]=low[k]=dep;
  for(j=head[k];j;j=next[j])
  {
   i=d[j];if (fa[k] ==i)continue;
   if (!dfn[i]) {fa[i]=k;tarjan(i,dep+1);low[k]=min(low[k],low[i]);}
   else
    low[k]=min(low[k],dfn[i]);
  }
  if (low[k]==dfn[k])
  {
   gus2++;
   for(;;)
   {
    t1 =sta[sta2];
     gus[t1]=gus2;
    if (sta[sta2]==k)break;
    sta2--;
   }
   sta2--;
  }
}
int chokkei;
set <int>b[10005];
int ans,ha[10005];
int work(int k)
{
  int i,j,l,t1,t2,t3,t4,t5,t6,t7,t8,t9,t,nw,mx1=0,mx2=0;
  ha[k]=1;
  if (b[k].size() ==1 )ans++;
  for(typeof b[k].begin() it =b[k].begin();it!=b[k].end();it++)
  {
   i=*it;
   if (ha[i]) continue;
   t1 =work(i);
   if (t1 > mx1) mx2=mx1,mx1=t1;
   else if (t1 > mx2) mx2= t1;
  }
  chokkei=max(chokkei,mx1+mx2+1);
  int max;
  return mx1+1;

}

int main()
{
  int i,j,k,l,t1,t2,t3,t4,t5,t6,t7,t8,t9,t,nw;
  int tt1,tt2,tt3,tt4;
  double u1,u2,u3,u4,u5,u6,u7,u8,u9;
  char c1,c2,c3;
  srand((unsigned)time(0));//srand(72888306);
  #ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
  #endif
  cin >>n>>m;
  for(i=1;i<=m;i++)
  {
   cin >>t1>>t2;
   adde(t1,t2);adde(t2,t1);
  }
  for(i=1;i<=n;i++) if (!dfn[i]) {tarjan(i,1); }  //
  for(i=1;i<=n;i++)
   for(j=head[i];j;j=next[j])
   {
    t1= gus[i]; t2 = gus[d[j]];
    if (t1 !=t2 &&b[t1].find(t2) ==b[t1].end()) b[t1].insert(t2);
   }
  ans =gus2;
  ans=0;
  for(i=1;i<=gus2;i++)
  {
   if (ha[i]) continue;
   chokkei=0;
   work(1);
   ans+=chokkei-2;
   if (chokkei ==1) ans++;
  }
  ans = n-ans;
  printf("%d\n",ans);
  return 0;
}


// powered by xpd1  /i love shimokawa_mikuni and i haven't touch my devc for 3 months.
// All of these left only broken history after 12.4.22. sacrifice for my dPXq love.
// on 2012-10-
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <iostream>
#include <cmath>
#include <ctime>
#include <cstring>
#include <ctype.h>
#include <memory>
#include <fstream>
#include <string>
#include <utility>
#include <iomanip>

#include <map>
#include <queue>
#include <vector>
#include <list>
#include <set>
//#include <conio.h>
#define oo 2000000000
#define ol 200000000000000000ll //=2E17
#define ooo 1E14
#define EPS 1E-10
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define eps EPS
#define mem(x,y) (memset((x),y,sizeof((x))))
#define debug(x) cout << #x<<" = "<<x<<endl;
#ifdef __int64
 #define fmt64 "%I64d"
#else
 #define fmt64 "%lld"
#endif
using namespace std;
using namespace rel_ops;
const double PI=acos((double)-1);
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
int ts,ts2,ts3,ts4;
int n,m;
LL gcd(LL x,LL y){LL t;for(;y!=0;){t=x%y;x=y;y=t;}return x;}
double sqr(double x){return x*x;}
int d2=1,d[200005],next[200007],head[200007];
void adde(int x,int y)
{
  d2++,d[d2]=y,next[d2]=head[x],head[x]=d2;
}
int dfn[10005],low[10005],fa[10005],sta[10005],sta2;
int gus[10005],gus2;
void tarjan(int k,int dep)
{
  int i,j,t1,t2;
  sta[++sta2]  = k;
  dfn[k]=low[k]=dep;
  for(j=head[k];j;j=next[j])
  {
   i=d[j];if (fa[k] ==i)continue;
   if (!dfn[i]) {fa[i]=k;tarjan(i,dep+1);low[k]=min(low[k],low[i]);}
   else
    low[k]=min(low[k],dfn[i]);
  }
  if (low[k]==dfn[k])
  {
   gus2++;
   for(;;)
   {
    t1 =sta[sta2];
     gus[t1]=gus2;
    if (sta[sta2]==k)break;
    sta2--;
   }
   sta2--;
  }
}
int chokkei;
set <int>b[10005];
int ans,ha[10005];
int work(int k)
{
  int i,j,l,t1,t2,t3,t4,t5,t6,t7,t8,t9,t,nw,mx1=0,mx2=0;
  ha[k]=1;
  if (b[k].size() ==1 )ans++;
  for(typeof b[k].begin() it =b[k].begin();it!=b[k].end();it++)
  {
   i=*it;
   if (ha[i]) continue;
   t1 =work(i);
   if (t1 > mx1) mx2=mx1,mx1=t1;
   else if (t1 > mx2) mx2= t1;
  }
  chokkei=max(chokkei,mx1+mx2+1);
  int max;
  return mx1+1;

}

int main()
{
  int i,j,k,l,t1,t2,t3,t4,t5,t6,t7,t8,t9,t,nw;
  int tt1,tt2,tt3,tt4;
  double u1,u2,u3,u4,u5,u6,u7,u8,u9;
  char c1,c2,c3;
  srand((unsigned)time(0));//srand(72888306);
  #ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
  #endif
  cin >>n>>m;
  for(i=1;i<=m;i++)
  {
   cin >>t1>>t2;
   adde(t1,t2);adde(t2,t1);
  }
  for(i=1;i<=n;i++) if (!dfn[i]) {tarjan(i,1); }  //
  for(i=1;i<=n;i++)
   for(j=head[i];j;j=next[j])
   {
    t1= gus[i]; t2 = gus[d[j]];
    if (t1 !=t2 &&b[t1].find(t2) ==b[t1].end()) b[t1].insert(t2);
   }
  ans =gus2;
  ans=0;
  int kuai=0;
  for(i=1;i<=gus2;i++)
  {
   if (ha[i]) continue;
   //kuai=0;
   kuai++;
   chokkei=0;
   work(1);
   ans+=chokkei-2;
   if (chokkei ==1) ans++;

  }
  ans = n-ans;
  ans += (kuai-1);
  printf("%d\n",ans);
  return 0;
}


// powered by xpd1  /i love shimokawa_mikuni and i haven't touch my devc for 3 months.
// All of these left only broken history after 12.4.22. sacrifice for my dPXq love.
// on 2012-10-
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <iostream>
#include <cmath>
#include <ctime>
#include <cstring>
#include <ctype.h>
#include <memory>
#include <fstream>
#include <string>
#include <utility>
#include <iomanip>

#include <map>
#include <queue>
#include <vector>
#include <list>
#include <set>
//#include <conio.h>
#define oo 2000000000
#define ol 200000000000000000ll //=2E17
#define ooo 1E14
#define EPS 1E-10
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define eps EPS
#define mem(x,y) (memset((x),y,sizeof((x))))
#define debug(x) cout << #x<<" = "<<x<<endl;
#ifdef __int64
 #define fmt64 "%I64d"
#else
 #define fmt64 "%lld"
#endif
using namespace std;
using namespace rel_ops;
const double PI=acos((double)-1);
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
int ts,ts2,ts3,ts4;
int n,m;
LL gcd(LL x,LL y){LL t;for(;y!=0;){t=x%y;x=y;y=t;}return x;}
double sqr(double x){return x*x;}
int d2=1,d[200005],next[200007],head[200007];
void adde(int x,int y)
{
  d2++,d[d2]=y,next[d2]=head[x],head[x]=d2;
}
int dfn[10005],low[10005],fa[10005],sta[10005],sta2;
int gus[10005],gus2;
void tarjan(int k,int dep)
{
  int i,j,t1,t2;
  sta[++sta2]  = k;
  dfn[k]=low[k]=dep;
  for(j=head[k];j;j=next[j])
  {
   i=d[j];if (fa[k] ==i)continue;
   if (!dfn[i]) {fa[i]=k;tarjan(i,dep+1);low[k]=min(low[k],low[i]);}
   else
    low[k]=min(low[k],dfn[i]);
  }
  if (low[k]==dfn[k])
  {
   gus2++;
   for(;;)
   {
    t1 =sta[sta2];
     gus[t1]=gus2;
    if (sta[sta2]==k)break;
    sta2--;
   }
   sta2--;
  }
}
int chokkei;
set <int>b[10005];
int ans,ha[10005];
int work(int k)
{
  int i,j,l,t1,t2,t3,t4,t5,t6,t7,t8,t9,t,nw,mx1=0,mx2=0;
  ha[k]=1;
  if (b[k].size() ==1 )ans++;
  for(j=head[k];j;j=next[j])
  {
   i=d[j];
   if (ha[i]) continue;
   t1 =work(i);
   if (t1 > mx1) mx2=mx1,mx1=t1;
   else if (t1 > mx2) mx2= t1;
  }
  chokkei>?=mx1+mx2+1;
  int max;
  return mx1+1;

}

int main()
{
  int i,j,k,l,t1,t2,t3,t4,t5,t6,t7,t8,t9,t,nw;
  int tt1,tt2,tt3,tt4;
  double u1,u2,u3,u4,u5,u6,u7,u8,u9;
  char c1,c2,c3;
  srand((unsigned)time(0));//srand(72888306);
  #ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
  #endif
  cin >>n>>m;
  for(i=1;i<=m;i++)
  {
   cin >>t1>>t2;
   adde(t1,t2);adde(t2,t1);
  }
  for(i=1;i<=n;i++) if (!dfn[i]) {tarjan(i,1); }  //
  for(i=1;i<=n;i++)
   for(j=head[i];j;j=next[j])
   {
    t1= gus[i]; t2 = gus[d[j]];
    if (t1 !=t2 &&b[t1].find(t2) ==b[t1].end()) b[t1].insert(t2);
   }
  ans =gus2;
  ans=0;
  for(i=1;i<=gus2;i++)
  {
   if (ha[i]) continue;
   chokkei=0;
   work(1);
   ans+=chokkei-2;
   if (chokkei ==1) ans++;
  }

  ans = n-ans;
  printf("%d\n",ans);
  return 0;
}


// powered by xpd1  /i love shimokawa_mikuni and i haven't touch my devc for 3 months.
// All of these left only broken history after 12.4.22. sacrifice for my dPXq love.
// on 2012-10-
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <iostream>
#include <cmath>
#include <ctime>
#include <cstring>
#include <ctype.h>
#include <memory>
#include <fstream>
#include <string>
#include <utility>
#include <iomanip>

#include <map>
#include <queue>
#include <vector>
#include <list>
#include <set>
//#include <conio.h>
#define oo 2000000000
#define ol 200000000000000000ll //=2E17
#define ooo 1E14
#define EPS 1E-10
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define eps EPS
#define mem(x,y) (memset((x),y,sizeof((x))))
#define debug(x) cout << #x<<" = "<<x<<endl;
#ifdef __int64
 #define fmt64 "%I64d"
#else
 #define fmt64 "%lld"
#endif
using namespace std;
using namespace rel_ops;
const double PI=acos((double)-1);
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
int ts,ts2,ts3,ts4;
int n,m;
LL gcd(LL x,LL y){LL t;for(;y!=0;){t=x%y;x=y;y=t;}return x;}
double sqr(double x){return x*x;}
int d2=1,d[200005],next[200007],head[200007];
void adde(int x,int y)
{
  d2++,d[d2]=y,next[d2]=head[x],head[x]=d2;
}
int dfn[10005],low[10005],fa[10005],sta[10005],sta2;
int gus[10005],gus2;
void tarjan(int k,int dep)
{
  int i,j,t1,t2;
  sta[++sta2]  = k;
  dfn[k]=low[k]=dep;
  for(j=head[k];j;j=next[j])
  {
   i=d[j];if (fa[k] ==i)continue;
   if (!dfn[i]) {fa[i]=k;tarjan(i,dep+1);low[k]=min(low[k],low[i]);}
   else
    low[k]=min(low[k],dfn[i]);
  }
  if (low[k]==dfn[k])
  {
   gus2++;
   for(;;)
   {
    t1 =sta[sta2];
     gus[t1]=gus2;
    if (sta[sta2]==k)break;
    sta2--;
   }
   sta2--;
  }
}
int chokkei;
set <int>b[10005];
int ans,ha[10005];
int work(int k)
{
  int i,j,l,t1,t2,t3,t4,t5,t6,t7,t8,t9,t,nw,mx1=0,mx2=0;
  ha[k]=1;
  if (b[k].size() ==1 )ans++;
  for(typeof b[k].begin() it =b[k].begin();it!=b[k].end();it++)
  {
   i=*it;
   if (ha[i]) continue;
   t1 =work(i);
   if (t1 > mx1) mx2=mx1,mx1=t1;
   else if (t1 > mx2) mx2= t1;
  }
  chokkei=max(chokkei,mx1+mx2+1);
  int max;
  return mx1+1;

}

int main()
{
  int i,j,k,l,t1,t2,t3,t4,t5,t6,t7,t8,t9,t,nw;
  int tt1,tt2,tt3,tt4;
  double u1,u2,u3,u4,u5,u6,u7,u8,u9;
  char c1,c2,c3;
  srand((unsigned)time(0));//srand(72888306);
  #ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
  #endif
  cin >>n>>m;
  for(i=1;i<=m;i++)
  {
   cin >>t1>>t2;
   adde(t1,t2);adde(t2,t1);
  }
  for(i=1;i<=n;i++) if (!dfn[i]) {tarjan(i,1); }  //
  for(i=1;i<=n;i++)
   for(j=head[i];j;j=next[j])
   {
    t1= gus[i]; t2 = gus[d[j]];
    if (t1 !=t2 &&b[t1].find(t2) ==b[t1].end()) b[t1].insert(t2);
   }
  ans =gus2;
  ans=0;
  int kuai=0;
  for(i=1;i<=gus2;i++)
  {
   if (ha[i]) continue;
   //kuai=0;
   kuai++;
   chokkei=0;
   work(i);
   ans+=chokkei-2;
   if (chokkei ==1) ans++;

  }
  ans = n-ans;
  ans += (kuai-1);
  printf("%d\n",ans);
  return 0;
}


#include <cstdio>
int main() {return 0;}


#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <ctime>
#include <set>
#include <map>

#define X first
#define Y second
#define pb push_back

using namespace std;

typedef long long lint;
typedef pair<int, int> pii;
typedef set<int> Si;
typedef vector<int> Vi;
typedef vector<int> :: iterator Vi_it;
typedef set<int> :: iterator Si_it;

const double eps = 1e-9;
const double PI = acos(-1.0);

inline int dcmp(const double & x)
{return x < -eps ? -1 : x > eps;}
const int Mn = 2000 + 10, Me = 100000 * 2 + 10;
int hd[Mn],nxt[Me],to[Me],cnt;
int hd1[Mn],nxt1[Me],to1[Me],cnt1;
int dfn[Mn],low[Mn],stack[Mn],scc[Mn],sc,top,tot;
int size_sc[Mn],size[Mn];
int vis[Mn],num;
int n,m;
inline void add(int x,int y)
{
	to[cnt] = y;
	nxt[cnt] = hd[x];
	hd[x] = cnt++;
}
inline void add1(int x,int y)
{
	to1[cnt1] = y;
	nxt1[cnt1] = hd1[x];
	hd1[x] = cnt1++;
}
inline void tarjan(int x,int p)
{
	stack[++top] = x;
	dfn[x] = low[x] = ++tot;
	for(int i = hd[x]; ~i; i = nxt[i])
		if(i != p)
		{
			if(!dfn[to[i]])
				tarjan(to[i],i^1);
			low[x] = min(low[x],low[to[i]]);
		}
	if(low[x] == dfn[x])
	{
		int now;
		sc++;
		//printf("%d : ",sc);
		do
		{
			now = stack[top--];
			//printf(" %d",now);
			scc[now] = sc;
			size_sc[sc]++;
		}while(now != x);
		//puts("");
	}
}
inline void dfs(int x,int p)
{
	size[x] = 1;
	vis[x] = num;
	for(int i = hd1[x]; ~i; i = nxt1[i])
		if(i != p)
		{
			dfs(to1[i],i^1);
			size[x] += size[to1[i]];
		}
}
inline void get_size(int x,int p)
{
	size[x] = 1;
	for(int i = hd1[x]; ~i; i = nxt1[i])
		if(i != p)
		{
			get_size(to1[i],i^1);
			size[x] += size[to1[i]];
		}
}
inline int dp(int x,int p)
{
	int res(0x7fffffff);
	int tot(0);
	for(int i = hd1[x]; ~i; i = nxt1[i])
		if(i != p)
			tot++;
	if(!tot)
		return 0;
	for(int i = hd1[x]; ~i; i = nxt1[i])
		if(i != p)
			res = min(res,dp(to1[i],i^1)+size[x]-size[to1[i]]-tot);
	return res;
}
inline int solve(int x)
{
	dfs(x,-1);
	int res(0x7fffffff);
	for(int i = 1; i <= sc; i++)
		if(vis[i] == num)
		{
			get_size(i,-1);
			res = min(res,dp(i,-1));
		}
	return res;
}
int main()
{
	memset(hd,-1,sizeof hd);
	memset(hd1,-1,sizeof hd1);
	scanf("%d%d",&n,&m);
	for(int i = 1; i <= m; i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		add(x,y),add(y,x);
	}
	for(int i = 1; i <= n; i++)
		if(!dfn[i])
			tarjan(i,-1);
	int ans(0);
	for(int i = 1; i <= sc; i++)
		ans += size_sc[i] - 1;
	for(int i = 1; i <= n; i++)
		for(int j = hd[i]; ~j; j = nxt[j])
			if(scc[i] < scc[to[j]])
			{
				//printf("%d - %d\n",scc[i],scc[to[j]]);
				add1(scc[i],scc[to[j]]);
				add1(scc[to[j]],scc[i]);
			}
	for(int i = 1; i <= sc; i++)
		if(!vis[i])
		{
			num++;
			ans += solve(i);
		}
	cout << ans + num - 1 << endl;
	return 0;
}