#include <bits/stdc++.h>
using namespace std;
int main() {
  long double n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  set<string, greater<string> > st;
  queue<string> stk;
  stk.push(s);
  while (k && !stk.empty()) {
    string temp = stk.front();
    stk.pop();
    if (st.find(temp) == st.end()) {
      st.insert(temp);
      k--;
      for (long double i = 0; i < temp.length(); i++) {
        string s1 = temp;
        s1.erase(s1.begin() + i);
        if (s1.size()) stk.push(s1);
      }
    }
  }
  long double ans = 0;
  if (k == 0 || (k == 1 && stk.empty())) {
    for (auto i = st.begin(); i != st.end(); i++) {
      ans += (n - (*i).length());
    }
    if (stk.empty()) ans += n;
    cout << ans << endl;
  } else {
    cout << -1 << endl;
  }
}
