#include<bits/stdc++.h>
#define ull unsigned long long
using namespace std;
string s;
ull l,cnt[114514],maxx;
int ans;
signed main(){
ios::sync_with_stdio(false);
cin>>s>>l;
ull lll=s.size();
if(lll>=l){
cout<<ans;
return 0;
}
for(ull i=0;i<lll;i++){
cnt[s[i]]++;
maxx=max(maxx,cnt[s[i]]);
}
while(lll<l){
lll+=maxx;
maxx*=2;
++ans;
}
cout<<ans;
return 0;
}