#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  string str;
  cin >> str;
  set<string> visited;
  queue<string> s;
  s.push(str);
  visited.insert(str);
  int count = 0, x = 0;
  while (!s.empty() && count != k) {
    string temp = s.front();
    x = x + temp.length();
    count++;
    s.pop();
    for (int i = 0; i < temp.length(); i++) {
      string temp2 = "";
      for (int j = 0; j < temp.length(); j++) {
        if (j != i) temp2 += temp[j];
      }
      if (visited.find(temp2) == visited.end()) {
        s.push(temp2);
        visited.insert(temp2);
      }
    }
  }
  if (s.empty() && count < k)
    cout << "-1";
  else
    cout << n * k - x;
  return 0;
}
