#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
const int INF = 0x3f3f3f3f;
const long long inf = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + 7;
const int maxn = 2e5 + 5;
map<string, int> mp;
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  string s;
  cin >> s;
  int cnt = 0;
  long long ans = 0;
  queue<string> q;
  q.push(s);
  while (!q.empty() && cnt <= k) {
    string now = q.front();
    q.pop();
    int len = now.length();
    mp[now] = 1;
    cnt += 1;
    ans += (n - len);
    if (cnt == k) break;
    for (int i = 0; i < len; i++) {
      string cur = now;
      cur.erase(i, 1);
      if (!mp[cur]) q.push(cur), mp[cur] = 1;
    }
  }
  if (cnt != k)
    puts("-1");
  else
    cout << ans << '\n';
}
