#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1000000007;
long long int bfs_solve(long long int n, long long int k, string second) {
  deque<string> dq;
  set<string> vis;
  dq.push_back(second);
  long long int ans = 0;
  string cur;
  while (!dq.empty() and (long long int) vis.size() < k) {
    cur = dq.front();
    dq.pop_front();
    if (vis.find(cur) != vis.end()) continue;
    vis.insert(cur);
    ans += n - (long long int)cur.size();
    if (cur == "") break;
    for (long long int i = 0; i < (long long int)cur.size(); i++)
      if (vis.find(cur.substr(0, i) + cur.substr(i + 1)) == vis.end())
        dq.push_back(cur.substr(0, i) + cur.substr(i + 1));
  }
  return (long long int)vis.size() == k ? ans : -1;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int n, k;
  string second;
  cin >> n >> k >> second;
  cout << bfs_solve(n, k, second) << endl;
  return 0;
}
