#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007LL
//#define MOD 998244353LL
#define doublecout(a) cout<<setprecision(16)<<a<<endl;
using vi = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける
using vvvi = vector<vvi>; // intの2次元の型に vvi という別名をつける
const ll llMAX=9223372036854775807LL; 
const ll llMIN=-9223372036854775808LL;

void myprint1D(vi &data)
{
  REP(i,data.size())
    cout<<data[i]<<" ";
  cout<<endl;
}

//配列を[y][x]で表示
void myprint2D_T(vvi &data)
{
  REP(i,data.size())
    myprint1D(data[i]);
}

//配列を[x][y]で表示
void myprint2D(vvi &data)
{
  ll l1=data.size();
  ll l2=data[0].size();
  REP(j,l2){
    REP(i,l1)
      cout<<data[i][j]<<" ";
    cout<<endl;
  }
}

//print(a,b...)って使い方
void print1(ll a){cout<<a<<endl;}
void print2(ll a,ll b){cout<<a<<" "<<b<<endl;}
void print3(ll a,ll b,ll c){cout<<a<<" "<<b<<" "<<c<<endl;}
void print4(ll a,ll b,ll c,ll d){cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl;}
void print5(ll a,ll b,ll c,ll d,ll e){cout<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<e<<endl;}


ll m;
string x;

bool solve(ll c){
  double dc=0.0;
  dc=c;
  double dgk=0.0;
  double dw=1.0;
  ll xs=x.size();
  bool flag=true;
  for(ll i=0;i<x.size();i++){
    if (dw>5223372036854775808.0){
      flag=false;
      break;
    }
    dgk+=dw*(x[xs-1-i]-48);
    if (dgk>5223372036854775808.0){
      flag=false;
      break;
    }
    dw*=dc;
  }

  if (flag==true){
    ll w=1;
    ll gk=0;
    for(ll i=0;i<x.size();i++){
      gk+=(x[xs-1-i]-48)*w;
      if (gk>m){
        flag=false;
        break;
      }
      w*=c;
    }
  }

  return flag;
}



int main(){
  ll ans=0;
  cin>>x;
  cin >> m;
  ll mm=m;

  if (x.size()==1){
    if (x[0]-48<=m){
      cout<<1<<endl;
    }else{
      cout<<0<<endl;
    }
    return 0;
  }

  ll mx=0;
  for(ll i=0;i<x.size();i++){
    mx=max(x[i]-48LL,mx);
  }

  if (x.size()==2){
    m-=(x[1]-48);
    ll s=(x[0]-48);
    ans=m/s;
    ans-=mx;
    cout<<ans<<endl;
    return 0;
  }
  


  if (x.size()>=3){
    ans=-9910000;
    int fflag=0;
    for(__int128_t i=2;i<1000002;i++){
      __int128_t gk=0;
      int flag=0;
      for(ll j=0;j<x.size();j++){
        gk*=i;
        gk+=(x[j]-48);
        if (gk>m)flag=1;
      }
      if (flag==1){
        ans=i-1-mx;
        fflag=1;
        break;
      }
    }
    if (fflag==1){
      if (ans<0)ans=0;
      cout<<ans<<endl;
      return 0;
    }
  }

  
  if (x.size()==3){
    x[0]-=48;
    x[1]-=48;
    x[2]-=48;
    
    double s4ac=(double)x[1]*(double)x[1]-4.0*(double)x[0]*(double)((double)x[2]-(double)m);
    if (s4ac<0){
      cout<<0<<endl;
      return 0;
    }
    s4ac=sqrt(s4ac);
    double niji=(double)(-(double)x[1]+s4ac)/(2.0*(double)x[0]);
    //cout<<niji<<endl;
    ll erm=1.0*niji;
    
    ll pm=1;
    ans=mx;
    if (x[0]*erm*erm+x[1]*erm+x[2]>m)pm=-1;

    for(ll i=0;i<2000000;i++){
      if (x[0]*erm*erm+x[1]*erm+x[2]<=m){
        ans=erm;
        if (pm==-1)break;
      }else{
        if (pm!=-1)break;
      }
      erm+=pm;
    }
    ans=ans-mx;
    if (ans<0)ans=0;

    
    x[0]+=48;
    x[1]+=48;
    x[2]+=48;

  cout<<ans<<endl;
  return 0;
  }

  /*
455
1234567890123456
  */

/*

  m=mm;
  //2分岐探索
  ll ok=mx;//解が存在する値
  ll ng=10000000000;//解が存在しない値
  while(abs(ok-ng)>1)
  {
    ll mid=(ok+ng)/2;
    //cout<<mid<<endl;
    if (solve(mid))//これを満たす最小のmidがokになる
    {
      ok=mid;
    }
    else
    {
      ng=mid;
    }
  }
  //okの値を使う
  ll ans2=ok-mx;

  if (ans!=ans2){
    print2(ans,ans2);
  }
*/



  cout<<ans<<endl;
  return 0;
}
/*
100000000000000000000000000000000000000000000000000000000000
10

*/
#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<set>
#include<queue>
#include<stack>
#include<math.h>
#include<time.h>
#include<deque>
#include<cstring>
#define ll  long long
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define pb push_back
#define F first
#define S second
#define mp make_pair
#define pf push_front
#define MOD (ll)(1e9+7)
#define INF (ll)(1e18)
#define M 5000005
#define endl "\n"
#define AC ios::sync_with_stdio(0);cin.tie(0);
using namespace std;
ll dp[105][105][105]={0};
int n,a[105];
ll modd(ll x,ll y){
    if(y==1) return 0;
    ll r=x%y;
    if(r<0) return r+y;
    return r;
}
signed main(){
    AC;
    ll ans=(1e18);
    ll x;
    cin>>n>>x;
    
    FOR(i,0,n){
        cin>>a[i];
    }
    
    FOR(i,0,105)FOR(j,0,105)FOR(k,0,105) dp[i][j][k]=-INF;
    FOR(i,0,105) dp[i][0][0]=0;
    
    FOR(c,1,n+1){
        FOR(i,0,n){
            for(int j=c;j>0;j--){
                FOR(k,0,c){
                    dp[c][j][k]=max(dp[c][j][k],a[i]+dp[c][j-1][modd(k-a[i],c)]);
                }
            }
        }
    }
    
    FOR(c,1,n+1){
        ll m=x%c;
        ll now=(x-dp[c][c][m])/c;
        if(dp[c][c][m]>0) ans=min(ans,now);
    }
    cout<<ans<<endl;
}
