#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool setmin(T &a, T b) {
  if (a > b) return a = b, 1;
  return 0;
}
template <class T>
inline bool setmax(T &a, T b) {
  if (a < b) return a = b, 1;
  return 0;
}
template <class T>
inline T fast(T a, T b, T mod) {
  long long res = 1;
  while (b) {
    if (b & 1) res = (res * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return res;
}
template <class T>
inline T russian(T a, T b, T mod) {
  long long res = 0;
  while (b) {
    if (b & 1) res = (res + a) % mod;
    a = (a + a) % mod;
    b >>= 1;
  }
  return res;
}
template <class T>
inline T sub(T a, T b, T mod) {
  return ((a - b) + mod) % mod;
}
template <class T>
istream &operator>>(istream &os, vector<T> &container) {
  for (auto &u : container) os >> u;
  return os;
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &container) {
  for (auto &u : container) os << u << " ";
  return os;
}
template <typename T>
inline T gcd(T a, T b) {
  while (b) swap(a %= b, b);
  return a;
}
long double e = 2.7182818284590452353602874713526624;
long double PI = acos(-1);
long double eps = 1e-11;
const long long T = 1 << 19;
const long long INF = 1e9 + 7;
const long long BIG_INF = 1e18 + 5;
const long long N = 1e6 + 7;
long long n, m, k;
string a;
struct komp {
  char lit;
  int ile;
  komp(char x, int y) : lit(x), ile(y) {}
};
vector<komp> tab;
set<string> zbior;
int backtrack(int poz, int ile_moge_wywalic, string teraz) {
  if (poz == (int)(tab).size()) {
    if (ile_moge_wywalic == 0) {
      if (!zbior.count(teraz)) {
        zbior.insert(teraz);
        return 1;
      }
    }
    return 0;
  }
  int ile = 0;
  for (int i = 0; i <= min(ile_moge_wywalic, tab[poz].ile); i++) {
    for (int j = 0; j < tab[poz].ile - i; j++) teraz.push_back(tab[poz].lit);
    ile += backtrack(poz + 1, ile_moge_wywalic - i, teraz);
    for (int j = 0; j < tab[poz].ile - i; j++) teraz.pop_back();
  }
  return ile;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n >> m;
  cin >> a;
  for (int i = 0; i < (int)(a).size(); i++) {
    int ile = 1;
    while (i < (int)(a).size() - 1 && a[i] == a[i + 1]) {
      ile++;
      i++;
    }
    tab.push_back({a[i], ile});
  }
  long long wcz = 0;
  long long ans = 0;
  int kon = 0;
  for (int i = (int)(a).size(); i >= 0; i--) {
    int ile_r = backtrack(0, (int)(a).size() - i, "");
    int koszt = (int)(a).size() - i;
    if (wcz + ile_r < m) {
      ans += ile_r * koszt;
      wcz += ile_r;
    } else {
      ans += (m - wcz) * koszt;
      kon = 1;
      break;
    }
  }
  if (!kon) {
    cout << -1;
    exit(0);
  }
  cout << ans;
}
