/*
* Generate all strings for a given n that use the first n letters of
* the alphabet with a used once, b used twice, etc., and that don't
* have consecutive identical letters.
*/
#include <iostream>
#include <cstdlib>
#include <map>
using namespace std ;
const int MAXN = 30 ;
const int MAXSUM = MAXN * (MAXN + 1) / 2 ;
int n ;
int sum ;
long long ii ;
char str[MAXSUM+1] ;
int used[MAXN] ;
long long cnt ;
unsigned long long mpow[MAXN] ;
typedef pair<int, unsigned long long> keytype ;
map<keytype, long long> increment ;
long long target ;
char seen = 0 ;
void recur(int at, int prev, int powsum, int distinct, unsigned long long cnts) {
if (cnt > target)
return ;
if (at == sum) {
if (powsum + n + 2 == (2 << n) && distinct == n) {
cnt++ ;
if (cnt == target) {
cout << str << endl ;
seen = 1 ;
}
}
return ;
}
keytype key = make_pair(at*100+used[prev], cnts) ;
if (increment.find(key) != increment.end()) {
long long inc = increment[key] ;
if (inc + cnt < target) {
cnt += increment[key] ;
return ;
}
}
long long ocnt = cnt ;
for (int i=0; i<26; i++)
if (i != prev) {
int u = used[i] ;
if (powsum + (1 << u) + n + 2 <= (2 << n) && (u || distinct < n)) {
str[at] = 'a' + i ;
used[i]++ ;
recur(at+1, i, powsum + (1 << u), distinct + (u == 0),
cnts + mpow[u]) ;
used[i]-- ;
}
}
increment[key] = cnt - ocnt ;
}
int main(int argc, char *argv[]) {
cin >> n >> target ;
sum = n * (n + 1) / 2 ;
mpow[0] = 1 ;
for (int i=0; i<n; i++)
mpow[i+1] = ((unsigned long long)(n+1)) * mpow[i] ;
recur(0, 27, 0, 0, 0) ;
if (!seen)
cout << -1 << endl ;
}
LyoKICogICBHZW5lcmF0ZSBhbGwgc3RyaW5ncyBmb3IgYSBnaXZlbiBuIHRoYXQgdXNlIHRoZSBmaXJzdCBuIGxldHRlcnMgb2YKICogICB0aGUgYWxwaGFiZXQgd2l0aCBhIHVzZWQgb25jZSwgYiB1c2VkIHR3aWNlLCBldGMuLCBhbmQgdGhhdCBkb24ndAogKiAgIGhhdmUgY29uc2VjdXRpdmUga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W1lbnQuZW5kKCkpIHsKICAgICAgbG9uZyBsb25nIGluYyA9IGluY3JlbWVudFtrZXldIDsKICAgICAgaWYgKGluYyArIGNudCA8IHRhcmdldCkgewogICAgICAgICBjbnQgKz0gaW5jcmVtZW50W2tleV0gOwogICAgICAgICByZXR1cm4gOwogICAgICB9CiAgIH0KICAgbG9uZyBsb25nIG9jbnQgPSBjbnQgOwogICBmb3IgKGludCBpPTA7IGk8MjY7IGkrKykKICAgICAgaWYgKGkgIT0gcHJldikgewogICAgICAgICBpbnQgdSA9IHVzZWRbaV0gOwogICAgICAgICBpZiAocG93c3VtICsgKDEgPDwgdSkgKyBuICsgMiA8PSAoMiA8PCBuKSAmJiAodSB8fCBkaXN0aW5jdCA8IG4pKSB7CiAgICAgICAgICAgIHN0clthdF0gPSAnYScgKyBpIDsKICAgICAgICAgICAgdXNlZFtpXSsrIDsKICAgICAgICAgICAgcmVjdXIoYXQrMSwgaSwgcG93c3VtICsgKDEgPDwgdSksIGRpc3RpbmN0ICsgKHUgPT0gMCksCiAgICAgICAgICAgICAgICAgIGNudHMgKyBtcG93W3VdKSA7CiAgICAgICAgICAgIHVzZWRbaV0tLSA7CiAgICAgICAgIH0KICAgICAgfQogICBpbmNyZW1lbnRba2V5XSA9IGNudCAtIG9jbnQgOwp9CmludCBtYWluKGludCBhcmdjLCBjaGFyICphcmd2W10pIHsKICAgY2luID4+IG4gPj4gdGFyZ2V0IDsKICAgc3VtID0gbiAqIChuICsgMSkgLyAyIDsKICAgbXBvd1swXSA9IDEgOwogICBmb3IgKGludCBpPTA7IGk8bjsgaSsrKQogICAgICBtcG93W2krMV0gPSAoKHVuc2lnbmVkIGxvbmcgbG9uZykobisxKSkgKiBtcG93W2ldIDsKICAgcmVjdXIoMCwgMjcsIDAsIDAsIDApIDsKICAgaWYgKCFzZWVuKQogICAgICBjb3V0IDw8IC0xIDw8IGVuZGwgOwp9Cg==