#include <bits/stdc++.h>
const int INF = 0x7fffffff;
const long long int LNF = 0x7fffffffffffffff;
using namespace std;
int main() {
  string mm;
  int q, n, m, z = 0, k = 0;
  set<string> ax;
  queue<string> aq;
  scanf("%d%d", &n, &m);
  getchar();
  cin >> mm;
  q = mm.size();
  ax.insert(mm);
  aq.push(mm);
  while (!aq.empty() && m != 0) {
    string mm = (aq.front());
    aq.pop();
    z += q - mm.size();
    k = 0;
    while (k < mm.size()) {
      string nn = mm;
      nn.erase(k, 1);
      if (ax.find(nn) == ax.end()) {
        aq.push(nn);
        ax.insert(nn);
      }
      k++;
    }
    m--;
  }
  if (m != 0) {
    printf("-1\n");
  } else {
    printf("%d\n", z);
  }
  return 0;
}
