#include <bits/stdc++.h>
using namespace std;
queue<string> Q;
set<string> S;
int numOfStrings = 1;
int n, k;
vector<int> V;
void f(string s) {
  if (s.length() == 0) {
    return;
  }
  int l = s.size();
  for (int i = 0; i < l; i++) {
    string t = s.substr(0, i) + s.substr(i + 1);
    if (S.find(t) == S.end()) {
      S.insert(t);
      Q.push(t);
      numOfStrings++;
      V.at(t.size())++;
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> n >> k >> s;
  V = vector<int>(n + 1);
  Q.push(s);
  int len = s.size();
  while (numOfStrings < k && len >= 0) {
    int l = Q.size();
    for (int i = 0; i < l; i++) {
      string top = Q.front();
      Q.pop();
      f(top);
    }
    len--;
  }
  if (numOfStrings < k) {
    cout << -1;
    return 0;
  }
  int cost = 0;
  int strings = 1;
  int curr = n;
  while (true) {
    int remaining = k - strings;
    curr--;
    if (V.at(curr) < remaining) {
      cost += (n - curr) * V.at(curr);
      strings += V.at(curr);
    } else {
      cost += (n - curr) * remaining;
      break;
    }
  }
  cout << cost;
  return 0;
}
