#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
string line;
int k;
cin >> line >> k;
vector<char> chars(line.begin(), line.end());
sort(chars.begin(), chars.end());
char c = k >= chars.size() ? chars[chars.size() - 1] : chars[k - 1];
cout << line.find(c) << endl;
return 0;
}