#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
unsigned long long lon[123];
unsigned long long max()
{
int j;
unsigned long long m=0;
for(j=0;j<123;j++)
if(lon[j]>m)
m=lon[j];
return m;
}
int main()
{
char S[1000001];
unsigned long long L,i=0;
int caozuo=0;
memset(lon,0,sizeof(lon));
scanf("%s",&S);
scanf("%lld",&L);
while(S[i]!='\0')
{
lon[S[i]]++;
i++;
}
unsigned long long m=max();
while(i<L)
{
i = i+pow(2,caozuo)*m;
caozuo++;
}
printf("%d",caozuo);
}