#include <bits/stdc++.h>
using namespace std;
long long const MAX = 2147483647, REALMAX = 9223372036854775806;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  map<string, bool> M;
  queue<string> q;
  int a, b, k = 0, sum = 0;
  string s;
  cin >> a >> b >> s;
  q.push(s);
  while (!q.empty()) {
    string s1 = q.front();
    q.pop();
    if (M[s1] || k == b) {
      continue;
    }
    M[s1] = true;
    M[s] = true;
    k++;
    sum += a - s1.size();
    for (long long i = (0); i < (s1.size()); i++) {
      string s2 = s1;
      s2.erase(s2.begin() + i);
      q.push(s2);
    }
  }
  cout << (k == b ? sum : -1);
}
