#include<string>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<vector>
#include<tuple>
#include<algorithm>
using namespace std;
#define ran 6200
int n,m;string s;
vector<int> A, B;
tuple<int, int, bool> a[ran];
pair<string, int> c[ran];
vector<string> dp[ran];
bool g[ran];
void upd(vector<string>&A,const vector<string>&B) {
	string a = "", b = "";
	for (auto c : A)a += c;
	for (auto c : B)b += c;
	if (a < b)A = B;
}
int main() {
	cin >> n >> s;
	m = s.length();
	for (int i = 0; i < m; i++) {
		if (s[i] == 'a')A.push_back(i);else
			B.push_back(i);
		c[i].second = -1;
	}
	for (int i = 0; i < n; i++) {
		if (A[i] < B[i])
			a[i] = make_tuple(A[i], B[i], false);
		else
			a[i] = make_tuple(B[i], A[i], true);
	}
	sort(a, a + n);
	for (int i = 0; i < n; i++) {
		if (!get<2>(a[i])) {
			c[get<0>(a[i])] = make_pair("ab", get<1>(a[i]) + 1);
		}
		else {
			memset(g, 0, sizeof(g));
			int L = get<0>(a[i]), R = get<1>(a[i]);
			for (int j = 0; j < n; j++){
				int x = get<0>(a[j]), y = get<1>(a[j]);
				if (x >= L && x <= R && get<2>(a[j])) {
					R = max(R, y);
					g[x] = g[y] = true;
				}
			}
			string cur = "";L = R = -1;
			for (int j = 0; j < m; j++)if (g[j]) {
				if (L == -1)L = j;
				R = j;
				cur += s[j];
			}
			c[L] = make_pair(cur, R + 1);
		}
	}
	dp[0].clear();
	for (int i = 0; i < m; i++){
		auto vs = dp[i];
		upd(dp[i + 1], dp[i]);
		if (c[i].second != -1) {
			while (vs.size() > 0 && vs.back() < c[i].first)
				vs.pop_back();
			vs.push_back(c[i].first);
			upd(dp[c[i].second], vs);
		}
	}
	string out = "";
	for (auto it : dp[m])
		out += it;
	puts(out.c_str());
	return 0;
}