#include<bits/stdc++.h>
using namespace std;
#define lli long long int
const lli mod=1e9+7;
const lli pINF=100000000000000000;
const lli nINF=-LLONG_MAX;
void fast() {std::ios::sync_with_stdio(false);cin.tie(NULL);}
lli power(lli a,lli b){lli ans=1;while(b!=0){ if(b%2==1){ans*=a;}b/=2;a*=a;} return ans;}
lli invmod(lli a) {return pow(a,mod-2);}
#define vi vector<int>
#define vlli vector<lli>
#define pb push_back
#define mp make_pair
#define F first
const int INF = 0x3f3f3f3f ;
#define PII pair<int,int>
#define S second
#define si(n) scanf("%d",&n)
#define sli(n) scanf("%lld",&n)
#define printi(n) printf("%d\n",n)
#define printli(n) printf("%lld\n",n)
#define all(v) v.begin(),v.end()
#define forn(i,n) for(int i=0;i<n;i++)
void print(int a[],int n){for(int i=0;i<n;i++) cout<<a[i]<<" ";}
#define MAX 5005
#define LL long long 
int Rank[20][MAX];
int arr[5005],cum[5005],lcp[5005];

struct Tuple
{
    int left,right,pos;
};

bool compare(const Tuple &a, const Tuple &b)
{
    return a.left == b.left ? a.right < b.right : a.left < b.left;
}

void counting_sort(Tuple t[] , int n)
{
    int count[MAX+9];
    Tuple temp[n + 9];
    memset(count , 0 , sizeof count);

    for(int i = 0 ;i < n ; i++)
        count[t[i].right + 1]++;

    for(int i = 1 ; i  < MAX ; i++)
        count[i] += count[i-1];

    for(int i = 0 ; i<n ; i++)
    {
        temp[count[t[i].right +1] - 1] = t[i];
        count[t[i].right + 1]--;
    }   

    memset(count , 0 , sizeof count);

    for(int i = 0 ; i < n ; i ++)
        count[t[i].left + 1] ++;

    for(int i = 1 ; i<MAX ; i++)
        count[i] += count[i-1];

    for(int i = n- 1; i>=0 ; i--)
    {
        t[count[temp[i].left + 1] - 1] = temp[i];
        count[temp[i].left + 1]--;
    }
}

void suffix_array(char s[],int n)
{

    for(int i=0;i<n;i++)
        Rank[0][i] = s[i] - 97;

    Tuple t[n+9];


    for(int stp = 1 , cnt = 1 ; (cnt>>1) < n ; cnt<<=1 , stp++)
    {
        for(int i=0;i<n;i++)
        {
            t[i].left = Rank[stp-1][i];
            t[i].right = i+cnt < n ? Rank[stp-1][i + cnt] : -1;
            t[i].pos = i;
        }
        //sort(t,t+n,compare);
        counting_sort(t , n);
        for(int i=0;i<n;i++)
            Rank[stp][t[i].pos] = i > 0 && t[i-1].left == t[i].left && t[i-1].right == t[i].right ? Rank[stp][t[i-1].pos] : i;
    }
    int pos = ceil(log(n)/log(2));
    for(int i = 0;i<n;i++)
        arr[Rank[pos][i]] = i;
}

void lcpArray(char s[],int n)
{
        int k=0,sum = 0;
        vector<int> rank(n,0);
        for(int i=0; i<n; i++) rank[arr[i]]=i;
                lcp[0] = 0;
        for(int i=0; i<n; i++, k?k--:0)
        {
                if(rank[i]==n-1) {k=0; continue;}
                int j=arr[rank[i]+1];
                while(i+k<n && j+k<n && s[i+k]==s[j+k]) k++ ;
                lcp[rank[i] + 1] = k;
        }
}

int main()
{
    char s[5005];
    scanf("%s",s);
    int  n = strlen(s);
    suffix_array(s,n);
    lcpArray(s , n);
    cum[0] = n - arr[0];
    for(int i = 1;i < n;i++){
        cum[i] = cum[i-1] + (n - arr[i] - lcp[i]);
    }
    int q=1;
    while(q--)
    {
        int a;
        scanf("%d",&a);
        int pos ;
        pos = lower_bound(cum , cum + n , a) - cum;
        int i , j;
        for(int j = 0 , i = arr[pos] ; j< a - cum[pos-1] + lcp[pos] ; j++,i++)
            printf("%c",s[i]);
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 768