#include <bits/stdc++.h>
using namespace std;
const long long int N = 100010;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int n, k;
  cin >> n >> k;
  string t;
  cin >> t;
  set<string> s;
  s.insert(t);
  long long int ans = 0;
  vector<string> ar;
  ar.push_back(t);
  int f = 1;
  while (s.size() < k) {
    if (ar.size() == 0) {
      f = 0;
      break;
    }
    vector<string> br;
    for (long long int i = 0; i < ar.size(); ++i) {
      string ch = ar[i];
      t = "";
      for (long long int j = 0; j < ch.length(); ++j) {
        string lol = t;
        for (long long int k = j + 1; k < ch.length(); ++k) {
          lol += ch[k];
        }
        t += ch[j];
        if (s.find(lol) == s.end()) {
          s.insert(lol);
          br.push_back(lol);
          ans += n - lol.length();
          if (s.size() == k) {
            f = 2;
            break;
          }
        }
        if (s.size() == k) {
          f = 2;
          break;
        }
      }
      if (f == 2) {
        break;
      }
    }
    if (f == 2) {
      break;
    }
    ar = br;
  }
  if (f != 2) {
    ans = -1;
  }
  if (k == 1) {
    ans = 0;
  }
  cout << ans;
  return (0);
}
