#include<cstdio>
#include<algorithm>
#include<cstring>
#include <iostream>
#define M 400010
using namespace std ;
int wa[M], wb[M], WS[M], wv[M];
int rk[M], sa[M], height[M];
int RMQ[21][M], mp[M], vis[M];
char r[M], s[M];
int a[M];
long long sum[M];

int min(int x, int y)
{
    return x < y? x: y;
}

bool cmp(int *r, int i, int j, int len)
{
    return r[i] == r[j] && r[i+len] == r[j+len];
}

void suffix(int *r, int n, int m)
{
    int *x = wa, *y = wb, *t;
    int i, j, p;
    for(i = 0; i < m; i++) WS[i] = 0;
    for(i = 0; i < n; i++) WS[x[i] = r[i]]++;
    for(i = 1; i < m; i++) WS[i] += WS[i-1];
    for(i = n - 1; i >= 0; i--) sa[--WS[x[i]]] = i;

    for(j = 1, p = 0; p < n; j <<= 1, m = p){
        p = 0;
        for(i = n-j; i < n; i++) y[p++] = i;
        for(i = 0; i < n; i++) if(sa[i] >= j) y[p++] = sa[i] - j;
        for(i = 0; i < m; i++) WS[i] = 0;
        for(i = 0; i < n; i++) WS[wv[i] = x[y[i]]]++;
        for(i = 1; i < m; i++) WS[i] += WS[i-1];
        for(i = n-1; i >= 0; i--) sa[--WS[wv[i]]] = y[i];

        t = x; x = y; y = t; x[sa[0]] = 0;
        for(i = 1, p = 1; i < n; i++)
            x[sa[i]] = cmp(y, sa[i], sa[i-1], j) ? p - 1: p++;
    }
}

void setHeight(int *r, int n)
{
    int i, j, k;
    for(i = 0; i <= n; i++)
        rk[sa[i]] = i;
    for(i=0, k=0; i < n; height[rk[i++]] = k)
        for(k = k?k-1: 0, j = sa[rk[i]-1]; r[i+k] == r[j+k]; k++);
}

void setRMQ(int n)
{
    mp[0] = -1;
    int i, j, a, b;
    for(i = 1; i <= n; i++)
        if((i&(i-1)) == 0) mp[i] = mp[i-1] + 1;
        else mp[i] = mp[i-1];
    for(i = 0; i <= n; i++) RMQ[0][i] = height[i];
    for(j = 1; j <= mp[n]; j++)
        for(i = 0; i+(1<<j)-1<=n; i++){
            a = RMQ[j-1][i];
            b = RMQ[j-1][i+(1<<(j-1))];
            RMQ[j][i] = min(a, b);
        }
}

int find(int a, int b)
{
	if( a == b ) return M;
    if(b < a){int t = a; a = b; b = t;}
    a++;
    int j = mp[b-a+1];
    int x = RMQ[j][a];
     b -= (1<<j) - 1;
    int y = RMQ[j][b];
    return min(x, y);
}
char maxn[M] ;
int nxt[M];
void getNext( char *a )
{
	for( int i = 0 ;a[i] ;i ++ ) maxn[i] = min( a[i+1] ,a[0] ) ;
	int i = 0, j = -1;
	nxt[i] = j;
	while( a[i] ){
		if( j == -1 || a[i] == a[j] ){
			++i, ++j;
			if( a[i] == a[j] ){
				nxt[i] = nxt[j];
				if( j != -1 ) maxn[i] = min( maxn[j] ,a[i+1] ) ;
				else maxn[i] = min( a[i+1] ,a[0] ) ;
				maxn[i] = min( a[0] ,maxn[i] ) ;
			}
			else nxt[i] = j;
		}
		else j = nxt[j];
	}
}
char str[M];

int judge( char *s, char *str ){ //s大
	getNext( str );
	int i = 0, j = 0, cnt = 0;
	int hehe = 0 ;
	int len = strlen( str );
	if( s[0] > str[0] ) return 0x3f3f3f3f ;
	while( s[i] ){
		if( j == -1 || s[i] == str[j] ){
	//		putchar(s[i]) ;
			if( j != -1 ){
				if( s[i+1] > maxn[j] ){ 
	//				putchar(' ') ;
					if( s[i+1] > str[0] ) return 0x3f3f3f3f ;
					hehe++ ;j = -1 ;
				}
			}
			i++; j++;
		}
		else j = nxt[j];
		if( j == len ) cnt++, j = nxt[j];
	}
	return hehe  + 1 ;
}
bool check( long long mid, int n, int k )
{
	int i = std::lower_bound( sum, sum + n + 1, mid ) - sum;
	int l = sa[i];
	int len = mid - sum[i-1] + height[i];
	for( int j = 0; j < len; ++j ) str[j] = s[l+j];
	str[len] = '\0';
	int ans = judge( s, str );
	return ans <= k;
}
void solve( int n, int k )
{
	sum[0] = 0;
	for( int i = 1; i <= n; ++i ) sum[i] = sum[i-1] + n - sa[i] - height[i];
	long long mid, l = 1, r = sum[n];
	while( r > l ){
		mid = ( l + r ) >> 1;
		if( check( mid, n, k ) ) r = mid;
		else l = mid + 1;
	}
	check( l, n, k );
	printf( "%s\n", str );
}
int main()
{
/*	char ax[30] ,bx[30] ;while( cin >> bx >> ax ){ 

		getNext(ax) ;
		for( int i = 0 ;ax[i] ;i ++ ) cout << maxn[i] << " " ;puts("") ;
		judge(bx,ax) ;
	}*/
	int k, n;
	while( scanf( "%d", &k ) == 1 && k ){
		scanf( "%s", s );
		n = strlen( s );
		for( int i = 0; i < n; ++i ) a[i] = s[i] - 'a' + 1;
		a[n] = 0;
		suffix( a, n + 1, 30 );
		setHeight( a, n );
		setRMQ( n );
		solve( n, k );
	}
}