#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, m;
  string s, a;
  cin >> n >> k;
  cin >> s;
  map<string, bool> ms;
  priority_queue<pair<int, string>> p;
  p.push({n, s});
  int sum = 0;
  m = 1;
  while (!p.empty() && m < k) {
    s = p.top().second;
    p.pop();
    a = s;
    for (int i = 0; i < s.size() && m < k; i++) {
      a.erase(i, 1);
      if (!ms[a]) {
        sum += n - a.size();
        ms[a] = 1;
        m++;
        p.push({a.size(), a});
      }
      a = s;
    }
  }
  if (m < k)
    cout << -1 << endl;
  else
    cout << sum << endl;
  return 0;
}
