#include #include using namespace std; using ll = long long; using ull = unsigned long long; using mint = atcoder::modint998244353; using maxt = atcoder::modint1000000007; //ここからグラフ探索系 using Graph = vector>; struct edge { int to; ll cost; }; edge make_edge(int a, ll b) { edge ans; ans.to = a, ans.cost = b; return ans; } using Cost_Graph = vector>; using D_heap = priority_queue, vector>, greater>>; vector bfs_01(Cost_Graph G, int s) {//01_BFS vector ans(G.size() + 1, -1); deque> que; que.push_back(make_pair(0, s)); while(!que.empty()) { auto v = que.front(); que.pop_front(); if(ans[v.second] != -1) { continue; } ans[v.second] = v.first; for(edge next_v : G[v.second]) { if(ans[next_v.to] != -1) { continue; } if(next_v.cost) { que.push_back(make_pair(v.first + 1, next_v.to)); } else { que.push_front(make_pair(v.first, next_v.to)); } } } return ans; } vector dijkstra(Cost_Graph G, int s) {//ダイクストラ法 vector ans(G.size() + 1, -1); D_heap que; que.push(make_pair(0, s)); while(!que.empty()) { auto v = que.top(); que.pop(); if(ans[v.second] != -1) { continue; } ans[v.second] = v.first; for(edge next_v : G[v.second]) { if(ans[next_v.to] != -1) { continue; } que.push(make_pair(v.first + next_v.cost, next_v.to)); } } return ans; } //グラフ探索系終わり vector Era(int N) { vector ans(0, 0); vector isprime(N + 1, true); isprime[1] = false; for(int i = 1; i <= N; i++) { if(isprime[i]) { ans.push_back(i); for(int j = 2 * i; j <= N; j += i) { isprime[j] = false; } } } return ans; } ll POW(ll a, ll N) { if(N == 0) { return 1; } ll tmp = POW(a, N / 2), ans = tmp * tmp; if(N % 2 == 1) { ans *= a; } return ans; } ll GCD(ll a, ll b) { if(b == 0) { return a; } ll r = a % b; return GCD(b, r); } ll LCM(ll a, ll b) { return (a * b) / GCD(a, b); } vector zaatu(vector a) { vector b(0, 0); b = a; sort(b.begin(), b.end()); b.erase(unique(b.begin(), b.end()), b.end()); int s = b.size(); for(ll &o : a) { int l = 0, r = s, c = 0; while(r - l > 1) { c = (l + r) / 2; if(b.at(c) <= o) { l = c; } else { r = c; } } o = r; } return a; } struct FenwickTree { int N; vector a; FenwickTree(int n) { N = n; a.assign(N + 1, 0); } void add(int i, ll x) { for(int j = i; j <= N; j += (j & -j)) { a[j] += x; } } ll sum(int i, int j) { return sum_sub(j) - sum_sub(i - 1); } ll sum_sub(int i) { if(i == 0) { return 0; } ll s = 0; for(int j = i; j > 0; j -= (j & -j)) { s += a[j]; } return s; } }; ll tento(vector a) { int s = a.size(); FenwickTree tmp(s); ll ans = 0; for(int i = 0; i < s; i++) { ans += i - tmp.sum_sub(a.at(i)); tmp.add(a.at(i), 1); } return ans; } ll solve_qe(ll a, ll b, ll c) { ll l = 0, r = (ll)1e9 + 1, mid = 0; while(r - l > 1) { mid = (l + r) / 2; if(a * POW(mid, 2) + b * mid + c <= 0) { l = mid; } else { r = mid; } } if(a * POW(l, 2) + b * l + c == 0) { return l; } return -1; } vector Manacher(string S) { int i = 0, j = 0, s = S.size(); vector ans(s, 0); while(i < s) { while(i >= j && i + j < s && S[i - j] == S[i + j]) { j++; } ans[i] = j; int k = 1; while(i >= k && k + ans[i - k] < j) { ans[i + k] = ans[i - k], k++; } i += k, j -= k; } return ans; } //メモ //__builtin_popcount //next_permutation //srand((unsigned)time(NULL)) //cout << fixed << setprecision(Digit); //A~Z=65~90,a~z=97~122,0~9=48~57 //メモ終わり //library end int main() { int N; cin >> N; vector W; vector cnt(3, 0); for(int i = 0; i < POW(3, N); i++) { string tmp; for(int j = 0; j < N; j++) { tmp += (char)(i / POW(3, j) % 3 + 65); } cnt.assign(3, 0); for(int j = 0; j < N; j++) { cnt[tmp[j] - 'A']++; } int f = 1; for(int o : cnt) { f = (o ? f : 0); } if(f) { W.push_back(tmp); } } sort(W.begin(), W.end()); int S; cin >> S; cout << (S > (int)W.size() ? "-1" : W[S - 1]) << endl; }