#include<bits/stdc++.h>
#define cs const
#define pb push_back
using namespace std;
cs int N = 500;
int n, m, l, c[N], pre[2], mn[N][2];
vector<int> G[N];
char str[N], S[N];
int trs(int a){ return a > n ? a - n : a + n; }
int vis[N], TIME;
bool dfs(int u){
	if(vis[trs(u)]==TIME) return false; vis[u]=TIME;
	for(int v : G[u]) if(vis[v]!=TIME){
	if(!dfs(v)) return false;
	} return true;
}
bool chk(int x){
	++TIME;
	for(int i=1; i<=x; i++)
		if(!dfs(i+c[S[i]-'a'+1]*n)) return false;
	for(int i=x+1; i<=n; i++){
		if(vis[i]==TIME) S[i]=pre[0]+'a'-1;
		else if(vis[i+n]==TIME) S[i]=pre[1]+'a'-1;
		else{
			int u=min(pre[0],pre[1]), v=max(pre[0],pre[1]);
			if(dfs(i+c[u]*n)) S[i]=u+'a'-1;
			else if(dfs(i+c[v]*n)) S[i]=v+'a'-1;
			else return false;
		}
	} return true;
}
int main(){
	#ifdef FSYolanda
	freopen("1.in","r",stdin);
	#endif
	scanf("%s",str+1); l=strlen(str+1);
	mn[l+1][0] = mn[l+1][1] = pre[0] = pre[1] = l+1;
	for(int i=l; i>=1; i--){
		c[i]=str[i]=='V'; pre[c[i]] = i;
		mn[i][0] = pre[0]; mn[i][1] = pre[1];
	}
	scanf("%d%d",&n,&m);
	for(int i=1,x,y,a,b; i<=m; i++){
		scanf("%d",&x); scanf("%s",str); a=str[0]=='V';
		scanf("%d",&y); scanf("%s",str); b=str[0]=='V';
		G[x+a*n].pb(y+b*n); G[trs(y+b*n)].pb(trs(x+a*n));
	}
	scanf("%s",S+1);
	if(chk(n)){ cout << S+1; return 0; }
	else if(pre[0]==l+1||pre[1]==l+1){ puts("-1"); return 0; }
	for(int i=n; i; i--){
		int x=S[i]-'a'+2, u=min(mn[x][0],mn[x][1]), v=max(mn[x][0],mn[x][1]);
		if(u!=l+1){ S[i]=u+'a'-1; if(chk(i)){ cout<<S+1; return 0; } }
		if(v!=l+1){ S[i]=v+'a'-1; if(chk(i)){ cout<<S+1; return 0; } }
	} puts("-1"); return 0;
}


#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
#define N 222
using namespace std;

int n, m, s[30], t[N], ret[N], ans[N], mi[2], anc[N];
char S[30], T[N];
vector<int> G[N];

int dfn[N], low[N], now, stk[N], top, ins[N], scc[N], num, col[N];

void Tarjan(int u, int id) {
    dfn[u] = low[u] = ++now;
    stk[++top] = u, ins[u] = 1;
    for (int v : G[u]) {
        if (!dfn[v]) Tarjan(v, id), low[u] = min(low[u], low[v]);
        else if (ins[v]) low[u] = min(low[u], dfn[v]);
    } if (low[u] != dfn[u]) return ;
    ++num, stk[top + 1] = 0;
    while (stk[top + 1] != u)
        scc[stk[top]] = num, ins[stk[top]] = 0, col[stk[top]] = id, --top;
}

void dfs(int u, int &ok) {
    ins[u] = 1;
    for (int v : G[u]) {
        if (ins[v]) continue;
        if (ans[v >> 1] == -1)
            ans[v >> 1] = (v & 1), dfs(v, ok);
        else if (ans[v >> 1] != (v & 1)) ok = 0;
        if (!ok) break;
    }
    ins[u] = 0;
}

void precheck() {
    memcpy(ans, ret, sizeof ret);
    for (int i = 1; i <= n; ++i)
        if (ans[i] == -1) ans[i] = s[t[i]];
        else if (ans[i] != s[t[i]]) return ;
    int ok = 1;
    for (int i = 1; i <= n && ok; ++i)
        if (~ans[i]) dfs(i << 1 | ans[i], ok);
    if (!ok) return ;
    for (int i = 1; i <= n; ++i)
        putchar(t[i] + 'a' - 1);
    puts("");
    exit(0);
}

bool check(int i, int c) {
    memcpy(ans, ret, sizeof ret);
    for (int j = 1; j < i; ++j)
        if (ans[j] == -1) ans[j] = s[t[j]];
        else if (ans[j] != s[t[j]]) return 0;
    ans[i] = s[c]; int ok = 1;
    for (int j = 1; j <= n && ok; ++j)
        if (~ans[j]) dfs(j << 1 | ans[j], ok);
    if (!ok) return 0;
    for (int j = 1; j < i; ++j)
        anc[j] = t[j];
    anc[i] = c;
    for (int j = i + 1; j <= n; ++j)
        if (~ans[j]) {
            if (!mi[ans[j]]) return 0;
            anc[j] = mi[ans[j]];
        } else anc[j] = 1;
    for (int j = 1; j <= n; ++j)
        putchar(anc[j] + 'a' - 1);
    puts("");
    return 1;
}

int main() {
    scanf("%s", S + 1);
    int len = strlen(S + 1);
    for (int i = 1; i <= len; ++i)
        s[i] = S[i] == 'C';
    for (int i = 1; i <= len; ++i)
        if (!mi[s[i]]) mi[s[i]] = i;
    cin >> n >> m;
    for (int i = 1; i <= m; ++i) {
        int pos1, pos2; char t1, t2;
        scanf("%d %c %d %c", &pos1, &t1, &pos2, &t2);
        pos1 = pos1 << 1 | (t1 == 'C');
        pos2 = pos2 << 1 | (t2 == 'C');
        G[pos1].push_back(pos2);
    }
    scanf("%s", T + 1);
    for (int i = 1; i <= n; ++i)
        t[i] = T[i] - 'a' + 1;

    int cnt = 0;
    for (int i = 2; i <= (n << 1 | 1); ++i)
        if (!dfn[i]) Tarjan(i, ++cnt);

    memset(ret, -1, sizeof ret);
    for (int i = 1, u, v; i <= n; ++i) {
        u = (i << 1), v = (i << 1 | 1);
        if (col[u] == col[v]) {
            if (dfn[u] == dfn[v]) return puts("-1"), 0;
            ret[i] = dfn[u] < dfn[v] ? 0 : 1;
        }
    }

    precheck();

    for (int i = n; i >= 1; --i) {
        bool chk = (t[i] != len);
        for (int j = 1; j < i && chk; ++j)
            if ((~ret[j]) && s[t[j]] != ret[j]) chk = 0;
        if (!chk) continue;
        int vis[2] = {0, 0};
        for (int j = t[i] + 1; j <= len; ++j) {
            if (vis[s[j]]) continue;
            vis[s[j]] = 1;
            if (check(i, j)) return 0;
        }
    }

    return puts("-1"), 0;
}


#include<bits/stdc++.h>
using namespace std;
namespace red{
#define ls(p) (p<<1)
#define rs(p) (p<<1|1)
#define mid ((l+r)>>1)
	inline int read()
	{
		int x=0;char ch,f=1;
		for(ch=getchar();(ch<'0'||ch>'9')&&ch!='-';ch=getchar());
		if(ch=='-') f=0,ch=getchar();
		while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}
		return f?x:-x;
	}
	const int N=5e5+10;
	int n,d,m,k;
	char s[N];
	int b[33][2],f[33],vis[500];
	int head[N],cnt;
	struct point
	{
		int nxt,to;
		point(){}
		point(const int &nxt,const int &to):nxt(nxt),to(to){}
	}a[N<<1];
	inline void link(int x,int y)
	{
		a[++cnt]=(point){head[x],y};head[x]=cnt;
	}
	inline int get(int x)
	{
		return x<=n?x+n:x-n;
	}
	inline bool dfs(int now)
	{
		if(vis[get(now)]) return 0;
		vis[now]=1;
		for(int i=head[now];i;i=a[i].nxt)
		{
			int t=a[i].to;
			if(!vis[t]&&!dfs(t)) return 0;
		}
		return 1;
	}
	inline bool check(int o)
	{
		for(int i=1;i<=(n<<1);++i) vis[i]=0;
		for(int i=1;i<=o;++i)
			if(!dfs(i+f[s[i]-'a'+1]*n)) return 0;
		for(int i=o+1;i<=n;++i)
		{
			if(vis[i]) s[i]=b[1][0]+'a'-1;
			else if(vis[i+n]) s[i]=b[1][1]+'a'-1;
			else
			{
				int x=min(b[1][0],b[1][1]),y=max(b[1][0],b[1][1]);
				if(dfs(i+f[x]*n)) s[i]=x+'a'-1;
				else if(dfs(i+f[y]*n)) s[i]=y+'a'-1;
				else return 0;
			}
		}
		return 1;
	}
	inline void main()
	{
		scanf("%s",s+1);k=strlen(s+1);
		map<char,int> p;
		p['V']=0,p['C']=1;
		b[k+1][0]=b[k+1][1]=k+1;
		for(int i=k,t[2]={k+1,k+1};i;--i)
			t[f[i]=p[s[i]]]=i,b[i][0]=t[0],b[i][1]=t[1];
		n=read(),m=read();
		for(int x,y,s1,t1,s2,t2,i=1;i<=m;++i)
		{
			x=read();scanf("%s",s+1);y=strlen(s+1);
			s1=x+p[s[y]]*n,s2=get(s1);
			x=read();scanf("%s",s+1);y=strlen(s+1);
			t1=x+p[s[y]]*n,t2=get(t1);
			link(s1,t1);
			link(t2,s2);
		}
		scanf("%s",s+1);n=strlen(s+1);
		if(check(n)) return(void)printf("%s",s+1);
		else if(b[1][0]==k+1||b[1][1]==k+1) return(void)puts("-1");
		for(int i=n;i;--i)
		{
			int c=s[i]-'a'+2,x=min(b[c][0],b[c][1]),y=max(b[c][0],b[c][1]);
			if(x!=k+1)
			{
				s[i]=x+'a'-1;
				if(check(i)) return(void)printf("%s",s+1);
			}
			if(y!=k+1)
			{
				s[i]=y+'a'-1;
				if(check(i)) return(void)printf("%s",s+1);
			}
		}
		puts("-1");
	}
}
signed main()
{
	red::main();
	return 0;
}


#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long LL;

LL n,e[405][405];
void floyd(){
	for(LL k = 1;k <= n + n;k ++){
		for(LL i = 1;i <= n + n;i ++){
			for(LL j = 1;j <= n + n;j ++){
				e[i][j] |= (e[i][k] && e[k][j]);
			}
		}
	}
}

LL acv[405],tcv[405];
LL mxp[2],vc[35],nxt[35];
string s;
LL chk(LL pos,LL now,LL x,LL id){
	LL tmp;
	if(acv[pos] != -1 && acv[pos] != vc[now]) return 0;
	for(LL i = 1;i <= n;i ++) if(e[x][i] && e[x][i + n]) return 0;
	for(LL i = 1;i <= n;i ++){
		tcv[i] = -1;
		if(e[x][i]) tcv[i] = 0;
		if(e[x][i + n]) tcv[i] = 1;
	}
	if(!id){
		for(LL i = 1;i <= n;i ++){
			if(pos + i > n) break;
			tmp = max(tcv[pos + i],acv[pos + i]);
			if(tmp == -1) break;
			if(mxp[tmp] < s[pos + i] - 'a' + 1) return 0;
			if(mxp[tmp] > s[pos + i] - 'a' + 1) break;
		}
	}
	for(LL i = 1;i <= n;i ++) acv[i] = max(acv[i],tcv[i]);
	return 1;
}

LL ans[405];
int main(){
	LL len,m,l1,l2,c1,c2,fla;
	char ch1,ch2;
	cin >> s; len = s.length(); s = ' ' + s;
	for(LL i = 1;i <= len;i ++) vc[i] = (s[i] == 'C' ? 0 : 1);
	mxp[0] = mxp[1] = -1; for(LL i = 1;i <= len;i ++) mxp[vc[i]] = i;
	cout << mxp[0] << ' ' << mxp[1] << endl;
	for(LL i = 1;i <= len;i ++){
		nxt[i] = 0;
		for(LL j = i + 1;j <= len;j ++){
			if(vc[i] != vc[j]){ nxt[i] = j; break; }
		}
	}

	memset(acv,-1,sizeof(acv));
	memset(tcv,-1,sizeof(tcv));
	cin >> n >> m;
	while(m --){
		cin >> l1 >> ch1 >> l2 >> ch2;
		c1 = (ch1 == 'C') ? 0 : 1;
		c2 = (ch2 == 'C') ? 0 : 1;
		e[l1 + c1 * n][l2 + c2 * n] = 1;
		e[l2 + (!c2) * n][l1 + (!c1) * n] = 1;
	} floyd();

	cin >> s; s = ' ' + s;
	fla = 0;
	for(LL i = 1;i <= n;i ++){
		LL mi = fla ? 1 : s[i] - 'a' + 1;
//		cout << mi << ' ' << vc[mi] << ' ' << acv[i] << endl;
		if(chk(i,mi,i + vc[mi] * n,fla)) ans[i] = mi;
		else if(vc[mi] == vc[mi + 1] && chk(i,mi + 1,i + vc[mi + 1] * n,1)) ans[i] = mi + 1,fla = 1;
		else if(nxt[mi] && chk(i,nxt[mi],i + vc[nxt[mi]] * n,1)) ans[i] = nxt[mi],fla = 1;
		else{ cout << -1 << '\n'; return 0; }
//		cout << ans[i] << endl;
	}
	for(LL i = 1;i <= n;i ++)
		if(ans[i] > len){
			cout << -1 << '\n';
			return 0;
		}
	for(LL i = 1;i <= n;i ++) cout << (char)(ans[i] + 'a' - 1); cout << '\n';
	return 0;
}


#include<bits/stdc++.h>
#define inf 0x7f7f7f7f
#define Min(a,b,c,d,e) (min(a,min(b,min(c,min(d,e)))))
#define Max(a,b,c,d,e) (max(a,max(b,max(c,max(d,e)))))
using namespace std;
int a[100010];
string b;
int main()
{
    int n;
    cin >> n;
    for(int i=1;i<=n;i++)
    	cin >> a[i];
    cin>>b;
    b="0"+b;
    int l=-1e9;
    int r=1e9;
    for(int i=5;i<=n;i++)
	{
        if(b[i]==b[i-1])
			continue;
        if(b[i-1]=='1' && b[i]=='0')
			r=min(r,Min(a[i],a[i-1],a[i-2],a[i-3],a[i-4])-1);
        else
			l=max(l,Max(a[i],a[i-1],a[i-2],a[i-3],a[i-4])+1);
    }

    cout<< l << " "<< r;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 1e5 + 10;

int n, k;
char s[N];
char t[N];
int cnt;
string ans;

int main()
{
	scanf("%d%d", &n, &k);
	scanf("%s", s + 1);
	strcpy(t + 1, s + 1);
	sort(t + 1, t + n + 1);
	cnt = unique(t + 1, t + n + 1) - (t + 1);
	bool flag = false;
	if(n < k)
	{
		cout << s + 1;
		for (int i = n + 1; i <= k; i ++)
			cout << t[1];
		puts("");
		return 0;
	}
	int r = k;
	while(s[r] == t[cnt] && r)
	{
		r --;
	}
	int tmp = upper_bound(t + 1, t + cnt + 1, s[r]) - t;

	for (int i = 1; i <= r - 1; i ++)
	ans += s[i];
	ans += t[tmp];
	for (int i = r + 1; i <= k; i ++)
	ans += t[1];
	//reverse(ans.begin(), ans.end());
	cout << ans << '\n';
}


#include <bits/stdc++.h>

using namespace std;

const int N = 1e5 + 10;

int n, k;
char s[N];
char t[N];
int cnt;
string ans;

int main()
{
    //
	scanf("%d%d", &n, &k);
	scanf("%s", s + 1);
	strcpy(t + 1, s + 1);
	sort(t + 1, t + n + 1);
	cnt = unique(t + 1, t + n + 1) - (t + 1);
	bool flag = false;
	int r = k;
	while(s[r] == t[cnt] && r)
	{
		r --;
	}
	int tmp = upper_bound(t + 1, t + cnt + 1, s[r]) - t;

	for (int i = 1; i <= r - 1; i ++)
	ans += s[i];
	ans += t[tmp];
	for (int i = r + 1; i <= k; i ++)
	ans += t[1];
	//reverse(ans.begin(), ans.end());
	cout << ans << '\n';
}


#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define sc(x) scanf("%lld",&x)
#define pr(x) printf("%lld\n",x)
#define clr(x) memset(x, 0, sizeof(x))
#define all(x) x.begin(), x.end()
typedef pair<ll, ll> pii;
typedef vector< ll > vl;
typedef vector< pii > vpii;

#define trace2(x, y)             cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)          cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)       cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define trace5(a, b, c, d, e)    cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<endl;

//DONT WASTE YOUR TIME......i said don't waste -_-
//prove yourself remember....fuck ps&&as hard....show them your are better then them
//Be confident.....dont lose hope.......You can do it.....
//dimaag  khoob h tere meh ....bas concentration ki kami h
//CONCENTRATE
//A,B,C dimaag nhi ...observation h .....zyaada mat sochna unme.....bas observe karna dhyaan se aur implement kar daal jitni jaldi ho sake

//capture it

// fortunately or unfortunately tu sabse badaah chodu h ....ek number ka chutiyaa -_-

const ll N= 1e6+55,mod = 1e9+7;

set<char>ss;
set<char>::iterator it;
int main() {
 	//freopen("task.in","r",stdin);freopen("task.out","w",stdout);
	string s,ans="";
	ll n,k,i,j;
	cin>>n>>k;
	cin>>s;
	k--;
	for(i=0;i<n;i++)ss.insert(s[i]);
	char ch=*(ss.begin());
	for(i=min(k,n-1);i>=0;i--){
		if(k<0)break;
		it=ss.upper_bound(s[i]);
		if(it!=ss.end()){
			ans+=*it;
			k--;
			break;
		}
		else{
			k--;
			ans+=ch;
		}
		//cout<<ans<<"\n";
	}
	i--;
	while(i>=0 && k>=0){
		ans+=s[i];
		i--;
		k--;
	}
	reverse(ans.begin(),ans.end());
	while(k>=0){
		ans+=ch;
		k--;
	}
	cout<<ans<<"\n";
}


#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define sc(x) scanf("%lld",&x)
#define pr(x) printf("%lld\n",x)
#define clr(x) memset(x, 0, sizeof(x))
#define all(x) x.begin(), x.end()
typedef pair<ll, ll> pii;
typedef vector< ll > vl;
typedef vector< pii > vpii;

#define trace2(x, y)             cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)          cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)       cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define trace5(a, b, c, d, e)    cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<endl;

//DONT WASTE YOUR TIME......i said don't waste -_-
//prove yourself remember....fuck ps&&as hard....show them your are better then them
//Be confident.....dont lose hope.......You can do it.....
//dimaag  khoob h tere meh ....bas concentration ki kami h
//CONCENTRATE
//A,B,C dimaag nhi ...observation h .....zyaada mat sochna unme.....bas observe karna dhyaan se aur implement kar daal jitni jaldi ho sake

//capture it

// fortunately or unfortunately tu sabse badaah chodu h ....ek number ka chutiyaa -_-

const ll N= 1e6+55,mod = 1e9+7;

set<char>ss;
set<char>::iterator it;
int main() {
 	//freopen("task.in","r",stdin);freopen("task.out","w",stdout);
	string s,ans="";
	ll n,k,i,j;
	cin>>n>>k;
	cin>>s;
	k--;
	for(i=0;i<n;i++)ss.insert(s[i]);
	char ch=*(ss.begin());
	if(k>(n-1)){
		k-=(n);
		while(k>=0){
			s+=ch;
			k--;
		}
		cout<<s<<"\n";
		return 0;
	}
	for(i=min(k,n-1);i>=0;i--){
		if(k<0)break;
		it=ss.upper_bound(s[i]);
		if(it!=ss.end()){
			ans+=*it;
			k--;
			break;
		}
		else{
			k--;
			ans+=ch;
		}
		//cout<<ans<<"\n";
	}
	i--;
	while(i>=0 && k>=0){
		ans+=s[i];
		i--;
		k--;
	}
	reverse(ans.begin(),ans.end());
	while(k>=0){
		ans+=ch;
		k--;
	}
	cout<<ans<<"\n";
}


#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define sc(x) scanf("%lld",&x)
#define pr(x) printf("%lld\n",x)
#define clr(x) memset(x, 0, sizeof(x))
#define all(x) x.begin(), x.end()
typedef pair<ll, ll> pii;
typedef vector< ll > vl;
typedef vector< pii > vpii;

#define trace2(x, y)             cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)          cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)       cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define trace5(a, b, c, d, e)    cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<endl;

//DONT WASTE YOUR TIME......i said don't waste -_-
//prove yourself remember....fuck ps&&as hard....show them your are better then them
//Be confident.....dont lose hope.......You can do it.....
//dimaag  khoob h tere meh ....bas concentration ki kami h
//CONCENTRATE
//A,B,C dimaag nhi ...observation h .....zyaada mat sochna unme.....bas observe karna dhyaan se aur implement kar daal jitni jaldi ho sake

//capture it

// fortunately or unfortunately tu sabse badaah chodu h ....ek number ka chutiyaa -_-

const ll N= 1e6+55,mod = 1e9+7;

set<char>ss;
set<char>::iterator it;
int main() {
 	//freopen("task.in","r",stdin);freopen("task.out","w",stdout);
	string s,ans="";
	ll n,k,i,j;
	cin>>n>>k;
	cin>>s;
	k--;
	for(i=0;i<n;i++)ss.insert(s[i]);
	char ch=*(ss.begin());
	for(i=min(k,n-1);i>=0;i--){
		if(k<0)break;
		it=ss.upper_bound(s[i]);
		if(it!=ss.end()){
			ans+=*it;
			k--;
			break;
		}
		else{
			k--;
			ans+=ch;
		}
		//cout<<ans<<"\n";
	}
	i--;
	while(i>=0 && k>=0){
		ans+=s[i];
		i--;
		k--;
	}
	while(k>=0){
		ans+=ch;
		k--;
	}

	reverse(ans.begin(),ans.end());
	cout<<ans<<"\n";
}


#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define sc(x) scanf("%lld",&x)
#define pr(x) printf("%lld\n",x)
#define clr(x) memset(x, 0, sizeof(x))
#define all(x) x.begin(), x.end()
typedef pair<ll, ll> pii;
typedef vector< ll > vl;
typedef vector< pii > vpii;

#define trace2(x, y)             cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)          cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)       cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define trace5(a, b, c, d, e)    cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<endl;

//DONT WASTE YOUR TIME......i said don't waste -_-
//prove yourself remember....fuck ps&&as hard....show them your are better then them
//Be confident.....dont lose hope.......You can do it.....
//dimaag  khoob h tere meh ....bas concentration ki kami h
//CONCENTRATE
//A,B,C dimaag nhi ...observation h .....zyaada mat sochna unme.....bas observe karna dhyaan se aur implement kar daal jitni jaldi ho sake

//capture it

// fortunately or unfortunately tu sabse badaah chodu h ....ek number ka chutiyaa -_-

const ll N= 1e6+55,mod = 1e9+7;

set<char>ss;
set<char>::iterator it;
int main() {
 	//freopen("task.in","r",stdin);freopen("task.out","w",stdout);
	string s,ans="";
	ll n,k,i,j;
	cin>>n>>k;
	cin>>s;
	for(i=0;i<n;i++)ss.insert(s[i]);
	char ch=*(ss.begin());
	for(i=n-1;i>=0;i--){
		if(k<=0)break;
		it=ss.upper_bound(s[i]);
		if(it!=ss.end()){
			ans+=*it;
			break;
		}
		else{
			ans+=ch;
		}
		k--;
	}
	i--;
	while(i>=0 && k>0){
		ans+=s[i];
		i--;
		k--;
	}
	while(k>0){
		ans+=ch;
		k--;
	}
	reverse(ans.begin(),ans.end());
	cout<<ans<<"\n";
}


#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define sc(x) scanf("%lld",&x)
#define pr(x) printf("%lld\n",x)
#define clr(x) memset(x, 0, sizeof(x))
#define all(x) x.begin(), x.end()
typedef pair<ll, ll> pii;
typedef vector< ll > vl;
typedef vector< pii > vpii;

#define trace2(x, y)             cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)          cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)       cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define trace5(a, b, c, d, e)    cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<endl;

//DONT WASTE YOUR TIME......i said don't waste -_-
//prove yourself remember....fuck ps&&as hard....show them your are better then them
//Be confident.....dont lose hope.......You can do it.....
//dimaag  khoob h tere meh ....bas concentration ki kami h
//CONCENTRATE
//A,B,C dimaag nhi ...observation h .....zyaada mat sochna unme.....bas observe karna dhyaan se aur implement kar daal jitni jaldi ho sake

//capture it

// fortunately or unfortunately tu sabse badaah chodu h ....ek number ka chutiyaa -_-

const ll N= 1e6+55,mod = 1e9+7;

int main() {
 //	freopen("task.in","r",stdin);freopen("task.out","w",stdout);
	string s;
	ll n,k,i,j;
	cin>>n>>k;
	cin>>s;
	sort(s.begin(),s.end());
	char ch=s[n-1];
	for(i=0;i<k;i++)cout<<ch;
	cout<<"\n";

}


#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define sc(x) scanf("%lld",&x)
#define pr(x) printf("%lld\n",x)
#define clr(x) memset(x, 0, sizeof(x))
#define all(x) x.begin(), x.end()
typedef pair<ll, ll> pii;
typedef vector< ll > vl;
typedef vector< pii > vpii;

#define trace2(x, y)             cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)          cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)       cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define trace5(a, b, c, d, e)    cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<endl;

//DONT WASTE YOUR TIME......i said don't waste -_-
//prove yourself remember....fuck ps&&as hard....show them your are better then them
//Be confident.....dont lose hope.......You can do it.....
//dimaag  khoob h tere meh ....bas concentration ki kami h
//CONCENTRATE
//A,B,C dimaag nhi ...observation h .....zyaada mat sochna unme.....bas observe karna dhyaan se aur implement kar daal jitni jaldi ho sake

//capture it

// fortunately or unfortunately tu sabse badaah chodu h ....ek number ka chutiyaa -_-

const ll N= 1e6+55,mod = 1e9+7;

set<char>ss;
set<char>::iterator it;
int main() {
 	//freopen("task.in","r",stdin);freopen("task.out","w",stdout);
	string s,ans="";
	ll n,k,i,j;
	cin>>n>>k;
	cin>>s;
	for(i=0;i<n;i++)ss.insert(s[i]);
	char ch=*(ss.begin());
	for(i=n-1;i>=0;i--){
		if(k<=0)break;
		it=ss.upper_bound(s[i]);
		if(it!=ss.end()){
			ans+=*it;
			k--;
			break;
		}
		else{
			k--;
			ans+=ch;
		}
	}
	i--;
	while(i>=0 && k>0){
		ans+=s[i];
		i--;
		k--;
	}
	while(k>0){
		ans+=ch;
		k--;
	}
	reverse(ans.begin(),ans.end());
	cout<<ans<<"\n";
}


#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define sc(x) scanf("%lld",&x)
#define pr(x) printf("%lld\n",x)
#define clr(x) memset(x, 0, sizeof(x))
#define all(x) x.begin(), x.end()
typedef pair<ll, ll> pii;
typedef vector< ll > vl;
typedef vector< pii > vpii;

#define trace2(x, y)             cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)          cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)       cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define trace5(a, b, c, d, e)    cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<endl;

//DONT WASTE YOUR TIME......i said don't waste -_-
//prove yourself remember....fuck ps&&as hard....show them your are better then them
//Be confident.....dont lose hope.......You can do it.....
//dimaag  khoob h tere meh ....bas concentration ki kami h
//CONCENTRATE
//A,B,C dimaag nhi ...observation h .....zyaada mat sochna unme.....bas observe karna dhyaan se aur implement kar daal jitni jaldi ho sake

//capture it

// fortunately or unfortunately tu sabse badaah chodu h ....ek number ka chutiyaa -_-

const ll N= 1e6+55,mod = 1e9+7;

set<char>ss;
set<char>::iterator it;
int main() {
 	//freopen("task.in","r",stdin);freopen("task.out","w",stdout);
	string s,ans="";
	ll n,k,i,j;
	cin>>n>>k;
	cin>>s;
	for(i=0;i<n;i++)ss.insert(s[i]);
	char ch=*(ss.begin());
	for(i=n-1;i>=0;i--){
		it=ss.upper_bound(s[i]);
		if(it!=ss.end()){
			ans+=*it;
			break;
		}
		else{
			ans+=ch;
		}
	}
	i--;
	while(i>=0){
		ans+=s[i];
		i--;
	}
	reverse(ans.begin(),ans.end());
	cout<<ans<<"\n";
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k;
    cin>>n>>k;
    string s,t;
    cin>>s;
    char Min='z',Max='a';
    for(int i=0;i<s.size();++i)
    {
        Min=min(Min,s[i]);
        Max=max(Max,s[i]);
    }
    for(int i=0;i<k;++i)t+=Min;
    t[t.size()-1]=Max;
    for(int i=t.size()-1;i>=1;i--)
    {
        if(t>s)
        {
            cout<<t<<endl;return 0;
        }
        swap(t[i],t[i-1]);
    }
    cout<<t<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
bool freq[26];
string ans,str,s;
int k;
void rec(int idx)
{
    if(idx>=k)
    {
        if(str>s)
        {
            if(ans.empty())ans=str;
            else ans=min(ans,str);
        }
        return;
    }
    for(int i=0;i<26;++i)if(freq[i]){str+=char(i+'a');rec(idx+1);str.pop_back();}
}
int main()
{
    int n;
    cin>>n>>k;
    cin>>s;
    char Min='z';
    for(int i=0;i<s.size();++i){freq[s[i]-'a']=1;Min=min(Min,s[i]);}
    /*rec(0);
    cout<<ans<<endl;*/
    ans="";
    bool bol=0;
    int i;
    if(s.size()>=k)i=k-1;
    else i=s.size()-1;
    for(;i>=0;--i)
    {
        if(bol==1)
        {
            ans.push_back(s[i]);
        }
        else
        {
            bool b=0;
            for(int j=0;j<26;++j)
            {
                if(freq[j]&&char('a'+j)>s[i])
                {
                    b=1;
                    bol=1;
                    ans.push_back(char('a'+j));
                    break;
                }
            }
            if(!b) ans.push_back(Min);
        }
    }
    reverse(ans.begin(),ans.end());
    cout<<ans;
    if(k>s.size())for(int i=0;i<k-s.size();++i)cout<<Min;
    cout<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
bool freq[26];
string ans,str,s;
int k;
void rec(int idx)
{
    if(idx>=k)
    {
        if(str>s)
        {
            if(ans.empty())ans=str;
            else ans=min(ans,str);
        }
        return;
    }
    for(int i=0;i<26;++i)if(freq[i]){str+=char(i+'a');rec(idx+1);str.pop_back();}
}
int main()
{
    int n;
    cin>>n>>k;
    cin>>s;
    char Min='z';
    for(int i=0;i<s.size();++i){freq[s[i]-'a']=1;Min=min(Min,s[i]);}
    /*rec(0);
    cout<<ans<<endl;*/
    ans="";
    bool bol=0;
    for(int i=s.size()-1;i>=0;--i)
    {
        if(bol==1)
        {
            ans.push_back(s[i]);
        }
        else
        {
            bool b=0;
            for(int j=0;j<26;++j)
            {
                if(freq[j]&&char('a'+j)>s[i])
                {
                    b=1;
                    bol=1;
                    ans.push_back(char('a'+j));
                    break;
                }
            }
            if(!b) ans.push_back(Min);
        }
    }
    reverse(ans.begin(),ans.end());
    cout<<ans;
    for(int i=0;i<k-s.size();++i)cout<<Min;
    cout<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k;
    cin>>n>>k;
    string s,t;
    cin>>s;
    set<char>st;
    for(int i=0;i<s.size();++i)st.insert(s[i]);
    for(int i=0;i<k;++i)t+=*(st.begin());
    string ans="";
    for(set<char>::iterator it=st.begin();it!=st.end();++it)
    {
        string temp=t;
        temp[temp.size()-1]=*it;
        for(int i=temp.size()-1;i>=1;--i)
        {
            if(temp>s)
            {
                if(ans.empty())ans=temp;
                else ans=min(ans,temp);
            }
            swap(temp[i],temp[i-1]);
        }
        if(temp>s)
        {
            if(ans.empty())ans=temp;
            else ans=min(ans,temp);
        }

    }
    cout<<ans<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
bool freq[26];
string ans,str,s;
int k;
void rec(int idx)
{
    if(idx>=k)
    {
        if(str>s)
        {
            if(ans.empty())ans=str;
            else ans=min(ans,str);
        }
        return;
    }
    for(int i=0;i<26;++i)if(freq[i]){str+=char(i+'a');rec(idx+1);str.pop_back();}
}
int main()
{
    int n;
    cin>>n>>k;
    cin>>s;
    char Min='z';
    for(int i=0;i<s.size();++i){freq[s[i]-'a']=1;Min=min(Min,s[i]);}
    /*rec(0);
    cout<<ans<<endl;*/
    ans="";
    bool bol=0;
    for(int i=k-1;i>=0;--i)
    {
        if(bol==1)
        {
            ans.push_back(s[i]);
        }
        else
        {
            bool b=0;
            for(int j=0;j<26;++j)
            {
                if(freq[j]&&char('a'+j)>s[i])
                {
                    b=1;
                    bol=1;
                    ans.push_back(char('a'+j));
                    break;
                }
            }
            if(!b) ans.push_back(Min);
        }
    }
    reverse(ans.begin(),ans.end());
    cout<<ans<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
bool freq[26];
string ans,str,s;
int k;
void rec(int idx)
{
    if(idx>=k)
    {
        if(str>s)
        {
            if(ans.empty())ans=str;
            else ans=min(ans,str);
        }
        return;
    }
    for(int i=0;i<26;++i)if(freq[i]){str+=char(i+'a');rec(idx+1);str.pop_back();}
}
int main()
{
    int n;
    cin>>n>>k;
    cin>>s;
    char Min='z';
    for(int i=0;i<s.size();++i){freq[s[i]-'a']=1;Min=min(Min,s[i]);}
    if(s.size()<k)
    {
        cout<<s;
        for(int i=0;i<k-s.size();++i)cout<<Min;
        cout<<endl;
        return 0;
    }
    ans="";
    bool bol=0;
    for(int i=k-1;i>=0;--i)
    {
        if(bol==1)
        {
            ans.push_back(s[i]);
        }
        else
        {
            bool b=0;
            for(int j=0;j<26;++j)
            {
                if(freq[j]&&char('a'+j)>s[i])
                {
                    b=1;
                    bol=1;
                    ans.push_back(char('a'+j));
                    break;
                }
            }
            if(!b) ans.push_back(Min);
        }
    }
    reverse(ans.begin(),ans.end());
    cout<<ans<<endl;
    return 0;
}


#include<cstdio>
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<set>
using namespace std;

typedef long long int ll;
typedef pair<int, int> dot;
#define X first
#define Y second

int main()
{
        int n, k;
        cin >> n >> k;
        string s;
        cin >> s;
        int tmp[256] = {0};
        set<char> S;
        for(auto it: s)
                tmp[it] = 1;
        for(int i = 0; i < 256; ++i)
                if(tmp[i] == 1)
                        S.insert(tmp[i]);
        if(k > n)
                cout << s << (*S.begin()) << endl;
        else
        {
                string ans(s, 0, k);
                char largest = *S.rbegin();
                char smallest = *S.begin();
                for(int i = k - 1; i >= 0; i--)
                {
                        if(ans[i] == largest)
                                ans[i] = smallest;
                        else
                        {
                                auto it = S.find(ans[i]);
                                ans[i] = *(++it);
                                break;
                        }
                }
                cout << ans << endl;
        }
        return 0;
}


#include<cstdio>
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<set>
using namespace std;

typedef long long int ll;
typedef pair<int, int> dot;
#define X first
#define Y second

int main()
{
        int n, k;
        cin >> n >> k;
        string s;
        cin >> s;
        int tmp[256] = {0};
        set<char> S;
        for(auto it: s)
                tmp[it] = 1;
        for(int i = 0, it; i < 256; ++i, it = tmp[i])
                if(it == 1)
                        S.insert(i);
        if(k > n)
                cout << s << (*S.begin()) << endl;
        else
        {
                string ans(s, 0, k);
                char largest = *S.rbegin();
                char smallest = *S.begin();
                for(int i = k - 1; i >= 0; i--)
                {
                        if(ans[i] == largest)
                                ans[i] = smallest;
                        else
                        {
                                auto it = S.find(ans[i]);
                                ans[i] = *(++it);
                                break;
                        }
                }
                cout << ans << endl;
        }
}


#include<cstdio>
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<set>
using namespace std;

typedef long long int ll;
typedef pair<int, int> dot;
#define X first
#define Y second

int main()
{
        int n, k;
        cin >> n >> k;
        string s;
        cin >> s;
        int tmp[256] = {0};
        set<char> S;
        for(auto it: s)
                tmp[it] = 1;
        for(int i = 0; i < 256; ++i)
                if(tmp[i] == 1)
                        S.insert(i);
        if(k > n)
                cout << s << (*S.begin()) << endl;
        else
        {
                string ans(s, 0, k);
                char largest = *S.rbegin();
                char smallest = *S.begin();
                for(int i = k - 1; i >= 0; i--)
                {
                        if(ans[i] == largest)
                                ans[i] = smallest;
                        else
                        {
                                auto it = S.find(ans[i]);
                                ans[i] = *(++it);
                                break;
                        }
                }
                cout << ans << endl;
        }
        return 0;
}


#include<cstdio>
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<set>
using namespace std;

typedef long long int ll;
typedef pair<int, int> dot;
#define X first
#define Y second

int main()
{
        int n, k;
        cin >> n >> k;
        string s;
        cin >> s;
        int tmp[256] = {0};
        set<char> S;
        for(auto it: s)
                tmp[it] = 1;
        for(int i = 0, it; i < 256; ++i, it = tmp[i])
                if(it == 1)
                        S.insert(i);
        if(k > n)
                cout << s << (*S.begin()) << endl;
        else
        {
                string ans(s, 0, k);
                char largest = *S.rbegin();
                char smallest = *S.begin();
                for(int i = k - 1; i >= 0; i--)
                {
                        if(ans[i] == largest)
                                ans[i] = smallest;
                        else
                        {
                                auto it = S.find(ans[i]);
                                ans[i] = *(++it);
                                break;
                        }
                }
                cout << ans << endl;
        }
        return 0;
}


#include<cstdio>
#include<iostream>
#include<string>
using namespace std;

int main()
{
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    cout << s;
}


#include<cstdio>
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<set>
using namespace std;

typedef long long int ll;
typedef pair<int, int> dot;
#define X first
#define Y second

int main()
{
        int n, k;
        cin >> n >> k;
        string s;
        cin >> s;
        int tmp[256] = {0};
        set<char> S;
        for(auto it: s)
                tmp[it] = 1;
        for(int i = 0; i < 256; ++i)
                if(tmp[i] == 1)
                        S.insert(i);
        if(k > n)
                cout << s << string(k - n, *S.begin()) << endl;
        else
        {
                string ans(s, 0, k);
                char largest = *S.rbegin();
                char smallest = *S.begin();
                for(int i = k - 1; i >= 0; i--)
                {
                        if(ans[i] == largest)
                                ans[i] = smallest;
                        else
                        {
                                auto it = S.find(ans[i]);
                                ans[i] = *(++it);
                                break;
                        }
                }
                cout << ans << endl;
        }
        return 0;
}


#include <cstdio>
#include<math.h>
#include<string.h>
#include<algorithm>
#include<iostream>
using namespace std;
int main()
{
    int n,k;
    char a[100001];
    char b[100001];
    while(~scanf("%d%d",&n,&k))
    {
        getchar();
        gets(a);
        int minn=27;
        int maxx=-1;
        int q[26];
        memset(q,0,sizeof(q));
        int len=strlen(a);
        int cnt=0;
        for(int i=0; i<len; i++)
        {
            q[a[i]-'a']=1;
        }
        for(int i=0; i<26; i++)
        {
            if(q[i]==1)
            {
                cnt++;
            }
        }
        for(int i=0; i<26; i++)
        {
            if(q[i]==1)
            {
                minn=i;
                break;
            }
        }
        for(int i=25; i>=0; i--)
        {
            if(q[i]==1)
            {
                maxx=i;
                break;
            }
        }
        if(k>n)
        {
            for(int i=len; i<k; i++)
            {
                a[i]=minn+'a';
            }
            for(int i=0;i<k;i++)
            {
                printf("%c",a[i]);
            }
            printf("\n");
        }
        else
        {
            if(cnt==1)
            {
                for(int i=0; i<k; i++)
                {
                    a[i]=minn+'a';
                }
                for(int i=0; i<k; i++)
                {
                    printf("%c",a[i]);
                }
                printf("\n");
            }
            else
            {
                int flag=0;
                for(int i=k-1; i>=0; i--)
                {
                    if(a[i]-'a'!=maxx)
                    {
                        for(int t=a[i]-'a'+1; t<26; t++)
                        {
                            if(q[t]==1)
                            {
                                a[i]=t+'a';
                                flag=1;
                                break;
                            }
                        }
                        if(flag==1)
                        {
                            for(int j=i+1; j<k; j++)
                            {
                                a[j]=minn+'a';
                            }
                            break;
                        }
                    }
                }
                for(int i=0; i<k; i++)
                {
                    printf("%c",a[i]);
                }
                printf("\n");
            }
        }
    }
    return 0;
}


#include <cstdio>
#include<math.h>
#include<string.h>
#include<algorithm>
#include<iostream>
using namespace std;
int main()
{
    int n,k;
    char a[100001];
    char b[100001];
    while(~scanf("%d%d",&n,&k))
    {
        getchar();
        gets(a);
        int minn=27;
        int maxx=-1;
        int q[26];
        memset(q,0,sizeof(q));
        int len=strlen(a);
        int cnt=0;
        for(int i=0; i<len; i++)
        {
            q[a[i]-'a']=1;
        }
        for(int i=0; i<26; i++)
        {
            if(q[i]==1)
            {
                cnt++;
            }
        }
        for(int i=0; i<26; i++)
        {
            if(q[i]==1)
            {
                minn=i;
                break;
            }
        }
        for(int i=25; i>=0; i--)
        {
            if(q[i]==1)
            {
                maxx=i;
                break;
            }
        }
        if(k>n)
        {
            for(int i=len; i<k; i++)
            {
                a[i]=minn+'a';
            }
            puts(a);
        }
        else
        {
            if(cnt==2)
            {
                int flag=0;
                for(int i=0; i<len; i++)
                {
                    if(a[i]-'a'!=maxx&&a[i]-'a'!=minn)
                    {
                        for(int t=maxx-1; t>=0; t--)
                        {
                            if(q[t]==1)
                            {
                                a[i]=t+'a';
                                flag=1;
                                break;
                            }
                        }
                        if(flag==1)
                        {
                            for(int j=i+1; j<k; j++)
                            {
                                a[j]=minn+'a';
                            }
                            break;
                        }
                    }
                    else if(a[i]-'a'==minn)
                    {
                        for(int t=minn+1; t<26; t++)
                        {
                            if(q[t]==1)
                            {
                                a[i]=t+'a';
                                flag=1;
                                break;
                            }
                        }
                        if(flag==1)
                        {
                            for(int j=i+1; j<k; j++)
                            {
                                a[j]=minn+'a';
                            }
                            break;
                        }
                    }
                }
                for(int i=0; i<k; i++)
                {
                    printf("%c",a[i]);
                }
                printf("\n");
            }
            else
            {
                int flag=0;
                for(int i=k-1;i>=0;i--)
                {
                    if(a[i]-'a'!=maxx)
                    {
                        for(int t=a[i]-'a'+1;t<26;t++)
                        {
                            if(q[t]==1)
                            {
                                a[i]=t+'a';
                                flag=1;
                                break;
                            }
                        }
                        if(flag==1)
                        {
                            for(int j=i+1;j<k;j++)
                            {
                                a[j]=minn+'a';
                            }
                            break;
                        }
                    }
                }
                for(int i=0; i<k; i++)
                {
                    printf("%c",a[i]);
                }
                printf("\n");
            }
        }
    }
    return 0;
}


#include <cstdio>
#include<math.h>
#include<string.h>
#include<algorithm>
#include<iostream>
using namespace std;
int main()
{
    int n,k;
    char a[100001];
    char b[100001];
    while(~scanf("%d%d",&n,&k))
    {
        getchar();
        gets(a);
        int minn=27;
        int maxx=-1;
        int q[26];
        memset(q,0,sizeof(q));
        int len=strlen(a);
        int cnt=0;
        for(int i=0; i<len; i++)
        {
            q[a[i]-'a']=1;
        }
        for(int i=0; i<26; i++)
        {
            if(q[i]==1)
            {
                cnt++;
            }
        }
        for(int i=0; i<26; i++)
        {
            if(q[i]==1)
            {
                minn=i;
                break;
            }
        }
        for(int i=25; i>=0; i--)
        {
            if(q[i]==1)
            {
                maxx=i;
                break;
            }
        }
        if(k>n)
        {
            for(int i=len; i<k; i++)
            {
                a[i]=minn+'a';
            }
            puts(a);
        }
        else
        {
//            if(cnt==2)
//            {
//                int flag=0;
//                for(int i=0; i<len; i++)
//                {
//                    if(a[i]-'a'!=maxx&&a[i]-'a'!=minn)
//                    {
//                        for(int t=maxx-1; t>=0; t--)
//                        {
//                            if(q[t]==1)
//                            {
//                                a[i]=t+'a';
//                                flag=1;
//                                break;
//                            }
//                        }
//                        if(flag==1)
//                        {
//                            for(int j=i+1; j<k; j++)
//                            {
//                                a[j]=minn+'a';
//                            }
//                            break;
//                        }
//                    }
//                    else if(a[i]-'a'==minn)
//                    {
//                        for(int t=minn+1; t<26; t++)
//                        {
//                            if(q[t]==1)
//                            {
//                                a[i]=t+'a';
//                                flag=1;
//                                break;
//                            }
//                        }
//                        if(flag==1)
//                        {
//                            for(int j=i+1; j<k; j++)
//                            {
//                                a[j]=minn+'a';
//                            }
//                            break;
//                        }
//                    }
//                }
//                for(int i=0; i<k; i++)
//                {
//                    printf("%c",a[i]);
//                }
//                printf("\n");
//            }
            if(cnt==1)
            {
                for(int i=0; i<k; i++)
                {
                    a[i]=minn+'a';
                }
                for(int i=0; i<k; i++)
                {
                    printf("%c",a[i]);
                }
                printf("\n");
            }
            else
            {
                int flag=0;
                for(int i=k-1; i>=0; i--)
                {
                    if(a[i]-'a'!=maxx)
                    {
                        for(int t=a[i]-'a'+1; t<26; t++)
                        {
                            if(q[t]==1)
                            {
                                a[i]=t+'a';
                                flag=1;
                                break;
                            }
                        }
                        if(flag==1)
                        {
                            for(int j=i+1; j<k; j++)
                            {
                                a[j]=minn+'a';
                            }
                            break;
                        }
                    }
                }
                for(int i=0; i<k; i++)
                {
                    printf("%c",a[i]);
                }
                printf("\n");
            }
//        }
        }
        return 0;
    }


#include <cstdio>
#include<math.h>
#include<string.h>
#include<algorithm>
#include<iostream>
using namespace std;
int main()
{
    int n,k;
    char a[100001];
    char b[100001];
    while(~scanf("%d%d",&n,&k))
    {
        getchar();
        gets(a);
        int minn=27;
        int maxx=-1;
        int q[26];
        memset(q,0,sizeof(q));
        int len=strlen(a);
        int cnt=0;
        for(int i=0; i<len; i++)
        {
            q[a[i]-'a']=1;
        }
        for(int i=0; i<26; i++)
        {
            if(q[i]==1)
            {
                cnt++;
            }
        }
        for(int i=0; i<26; i++)
        {
            if(q[i]==1)
            {
                minn=i;
                break;
            }
        }
        for(int i=25; i>=0; i--)
        {
            if(q[i]==1)
            {
                maxx=i;
                break;
            }
        }
        if(k>n)
        {
            for(int i=len; i<k; i++)
            {
                a[i]=minn+'a';
            }
            puts(a);
        }
        else
        {
//            if(cnt==2)
//            {
//                int flag=0;
//                for(int i=0; i<len; i++)
//                {
//                    if(a[i]-'a'!=maxx&&a[i]-'a'!=minn)
//                    {
//                        for(int t=maxx-1; t>=0; t--)
//                        {
//                            if(q[t]==1)
//                            {
//                                a[i]=t+'a';
//                                flag=1;
//                                break;
//                            }
//                        }
//                        if(flag==1)
//                        {
//                            for(int j=i+1; j<k; j++)
//                            {
//                                a[j]=minn+'a';
//                            }
//                            break;
//                        }
//                    }
//                    else if(a[i]-'a'==minn)
//                    {
//                        for(int t=minn+1; t<26; t++)
//                        {
//                            if(q[t]==1)
//                            {
//                                a[i]=t+'a';
//                                flag=1;
//                                break;
//                            }
//                        }
//                        if(flag==1)
//                        {
//                            for(int j=i+1; j<k; j++)
//                            {
//                                a[j]=minn+'a';
//                            }
//                            break;
//                        }
//                    }
//                }
//                for(int i=0; i<k; i++)
//                {
//                    printf("%c",a[i]);
//                }
//                printf("\n");
//            }
            if(cnt==1)
            {
                for(int i=0; i<k; i++)
                {
                    a[i]=minn+'a';
                }
                for(int i=0; i<k; i++)
                {
                    printf("%c",a[i]);
                }
                printf("\n");
            }
            else
            {
                int flag=0;
                for(int i=k-1; i>=0; i--)
                {
                    if(a[i]-'a'!=maxx)
                    {
                        for(int t=a[i]-'a'+1; t<26; t++)
                        {
                            if(q[t]==1)
                            {
                                a[i]=t+'a';
                                flag=1;
                                break;
                            }
                        }
                        if(flag==1)
                        {
                            for(int j=i+1; j<k; j++)
                            {
                                a[j]=minn+'a';
                            }
                            break;
                        }
                    }
                }
                for(int i=0; i<k; i++)
                {
                    printf("%c",a[i]);
                }
                printf("\n");
            }
        }
    }
    return 0;
}


#include <cstdio>
#include<math.h>
#include<string.h>
#include<algorithm>
#include<iostream>
using namespace std;
int main()
{
    int n,k;
    char a[100001];
    char b[100001];
    while(~scanf("%d%d",&n,&k))
    {
        getchar();
        gets(a);
        int minn=27;
        int maxx=-1;
        int q[26];
        memset(q,0,sizeof(q));
        int len=strlen(a);
        int cnt=0;
        for(int i=0; i<len; i++)
        {
            q[a[i]-'a']=1;
        }
        for(int i=0; i<26; i++)
        {
            if(q[i]==1)
            {
                cnt++;
            }
        }
        for(int i=0; i<26; i++)
        {
            if(q[i]==1)
            {
                minn=i;
                break;
            }
        }
        for(int i=25; i>=0; i--)
        {
            if(q[i]==1)
            {
                maxx=i;
                break;
            }
        }
        if(k>n)
        {
            for(int i=len; i<k; i++)
            {
                a[i]=minn+'a';
            }
            puts(a);
        }
        else
        {
//            if(cnt==2)
//            {
//                int flag=0;
//                for(int i=0; i<len; i++)
//                {
//                    if(a[i]-'a'!=maxx&&a[i]-'a'!=minn)
//                    {
//                        for(int t=maxx-1; t>=0; t--)
//                        {
//                            if(q[t]==1)
//                            {
//                                a[i]=t+'a';
//                                flag=1;
//                                break;
//                            }
//                        }
//                        if(flag==1)
//                        {
//                            for(int j=i+1; j<k; j++)
//                            {
//                                a[j]=minn+'a';
//                            }
//                            break;
//                        }
//                    }
//                    else if(a[i]-'a'==minn)
//                    {
//                        for(int t=minn+1; t<26; t++)
//                        {
//                            if(q[t]==1)
//                            {
//                                a[i]=t+'a';
//                                flag=1;
//                                break;
//                            }
//                        }
//                        if(flag==1)
//                        {
//                            for(int j=i+1; j<k; j++)
//                            {
//                                a[j]=minn+'a';
//                            }
//                            break;
//                        }
//                    }
//                }
//                for(int i=0; i<k; i++)
//                {
//                    printf("%c",a[i]);
//                }
//                printf("\n");
//            }
//            else
//            {
                int flag=0;
                for(int i=k-1;i>=0;i--)
                {
                    if(a[i]-'a'!=maxx)
                    {
                        for(int t=a[i]-'a'+1;t<26;t++)
                        {
                            if(q[t]==1)
                            {
                                a[i]=t+'a';
                                flag=1;
                                break;
                            }
                        }
                        if(flag==1)
                        {
                            for(int j=i+1;j<k;j++)
                            {
                                a[j]=minn+'a';
                            }
                            break;
                        }
                    }
                }
                for(int i=0; i<k; i++)
                {
                    printf("%c",a[i]);
                }
                printf("\n");
            }
//        }
    }
    return 0;
}


#include <cstdio>
#include<math.h>
#include<string.h>
#include<algorithm>
#include<iostream>
using namespace std;
int main()
{
    int n,k;
    char a[100001];
    char b[100001];
    while(~scanf("%d%d",&n,&k))
    {
        getchar();
        gets(a);
        int minn=27;
        int maxx=-1;
        int q[26];
        memset(q,0,sizeof(q));
        int len=strlen(a);
        int cnt=0;
        for(int i=0; i<len; i++)
        {
            q[a[i]-'a']=1;
        }
        for(int i=0; i<26; i++)
        {
            if(q[i]==1)
            {
                cnt++;
            }
        }
        for(int i=0; i<26; i++)
        {
            if(q[i]==1)
            {
                minn=i;
                break;
            }
        }
        for(int i=25; i>=0; i--)
        {
            if(q[i]==1)
            {
                maxx=i;
                break;
            }
        }
        if(k>n)
        {
            for(int i=len; i<k; i++)
            {
                a[i]=minn+'a';
            }
            puts(a);
        }
        else
        {
            if(cnt==2)
            {
                int flag=0;
                for(int i=0; i<len; i++)
                {
                    if(a[i]-'a'!=maxx&&a[i]-'a'!=minn)
                    {
                        for(int t=maxx-1; t>=0; t--)
                        {
                            if(q[t]==1)
                            {
                                a[i]=t+'a';
                                flag=1;
                                break;
                            }
                        }
                        if(flag==1)
                        {
                            for(int j=i+1; j<k; j++)
                            {
                                a[j]=minn+'a';
                            }
                            break;
                        }
                    }
                    else if(a[i]-'a'==minn)
                    {
                        for(int t=minn+1; t<26; t++)
                        {
                            if(q[t]==1)
                            {
                                a[i]=t+'a';
                                flag=1;
                                break;
                            }
                        }
                        if(flag==1)
                        {
                            for(int j=i+1; j<k; j++)
                            {
                                a[j]=minn+'a';
                            }
                            break;
                        }
                    }
                }
                for(int i=0; i<k; i++)
                {
                    printf("%c",a[i]);
                }
                printf("\n");
            }
            else
            {
                int flag=0;
                for(int i=0; i<len; i++)
                {
                    if(a[i]-'a'!=minn&&a[i]-'a'!=maxx)
                    {
                        for(int t=a[i]-'a'+1; t<26; t++)
                        {
                            if(q[t]==1)
                            {
                                a[i]=t+'a';
                                flag=1;
                                break;
                            }
                        }
                        if(flag==1)
                        {
                            for(int j=i+1; j<k; j++)
                            {
                                a[j]=minn+'a';
                            }
                            break;
                        }
                    }
                }
                for(int i=0; i<k; i++)
                {
                    printf("%c",a[i]);
                }
                printf("\n");
            }
        }
    }
    return 0;
}


#include<iostream>
#include<algorithm>
#include<cstring>
#include<stdio.h>
#include<string>
#include<vector>
#include<math.h>
#include<set>
using namespace std;
typedef long long LL;
const int inf = 1e9;
bool vis[30];
int ans[100005];
int main()
{
	int n, k;
	cin >> n >> k;
	string s;
	cin >> s;
	for (int i = 0;i < s.size();i++)
		vis[s[i] - 'a'] = 1;
	int themax = 26;
	int themin = 0;
	while (!vis[themax])themax--;
	while (!vis[themin])themin++;
	int i;
	for ( i = k - 1;i >= 0;i--)
	{
		if (s[i] - 'a' == themax)
			ans[i] = themin;
		else
		{
			int tmp = s[i] - 'a'+1;
			while (!vis[tmp])tmp++;
			ans[i] =tmp;
			break;
		}
	}
	for (int j = i - 1;j >= 0;j--)
		ans[j] = s[j] - 'a';
	for (int i = 0;i < k;i++)
		printf("%c", ans[i] + 'a');
}


#include<iostream>
#include<algorithm>
#include<cstring>
#include<stdio.h>
#include<string>
#include<vector>
#include<math.h>
#include<set>
using namespace std;
typedef long long LL;
const int inf = 1e9;
bool vis[30];
int ans[100005];
int main()
{
	int n, k;
	cin >> n >> k;
	string s;
	cin >> s;
	for (int i = 0;i < s.size();i++)
		vis[s[i] - 'a'] = 1;
	int themax = 29;
	int themin = 0;
	while (!vis[themax])themax--;
	while (!vis[themin])themin++;
	int i;
	for ( i = k - 1;i >= 0;i--)
	{
		if (s[i] - 'a' == themax)
			ans[i] = themin;
		else
		{
			int tmp = s[i] - 'a'+1;
			while (!vis[tmp]&&tmp<26)tmp++;
			ans[i] =tmp;
			break;
		}
	}
	for (int j = i - 1;j >= 0;j--)
		ans[j] = s[j] - 'a';
	for (int i = 0;i < k;i++)
		printf("%c", ans[i] + 'a');
}


#include<iostream>
#include<algorithm>
#include<cstring>
#include<stdio.h>
#include<string>
#include<vector>
#include<math.h>
#include<set>
using namespace std;
typedef long long LL;
const int inf = 1e9;
bool vis[30];
int ans[1000005];
int main()
{
	int n, k;
	cin >> n >> k;
	string s;
	cin >> s;
	for (int i = 0;i < s.size();i++)
		vis[s[i] - 'a'] = 1;
	int themax = 29;
	int themin = 0;
	while (!vis[themax])themax--;
	while (!vis[themin])themin++;
	int i;
	for ( i = k - 1;i >= 0;i--)
	{
		if (s[i] - 'a' == themax)
			ans[i] = themin;
		else
		{
			int tmp = s[i] - 'a'+1;
			while (!vis[tmp])tmp++;
			ans[i] =tmp;
			break;
		}
	}
	for (int j = i - 1;j >= 0;j--)
		ans[j] = s[j] - 'a';
	for (int i = 0;i < k;i++)
		printf("%c", ans[i] + 'a');
}


#include<iostream>
#include<algorithm>
#include<cstring>
#include<stdio.h>
#include<string>
#include<vector>
#include<math.h>
#include<set>
using namespace std;
typedef long long LL;
const int inf = 1e9;
bool vis[30];
int ans[100005];
int main()
{
	int n, k;
	cin >> n >> k;
	string s;
	cin >> s;
	for (int i = 0;i < s.size();i++)
		vis[s[i] - 'a'] = 1;

	int themax = 29;
	int themin = 0;
	while (!vis[themax])themax--;
	while (!vis[themin])themin++;
	if (n <= k)
	{
		int i;
		for (i = k - 1;i >= 0;i--)
		{
			if (s[i] - 'a' == themax)
				ans[i] = themin;
			else
			{
				int tmp = s[i] - 'a' + 1;
				while (!vis[tmp])tmp++;
				ans[i] = tmp;
				break;
			}
		}
		for (int j = i - 1;j >= 0;j--)
			ans[j] = s[j] - 'a';
		for (int i = 0;i < k;i++)
			printf("%c", ans[i] + 'a');
	}
	else
	{
		cout << s;
		printf("%c", themin + 'a');
	}
}


#include<iostream>
#include<algorithm>
#include<cstring>
#include<stdio.h>
#include<string>
#include<vector>
#include<math.h>
#include<set>
using namespace std;
typedef long long LL;
const int inf = 1e9;
bool vis[30];
int ans[100005];
int main()
{
	int n, k;
	cin >> n >> k;
	string s;
	cin >> s;
	for (int i = 0;i < s.size();i++)
		vis[s[i] - 'a'] = 1;

	int themax = 29;
	int themin = 0;
	while (!vis[themax])themax--;
	while (!vis[themin])themin++;
	if (n >= k)
	{
		int i;
		for (i = k - 1;i >= 0;i--)
		{
			if (s[i] - 'a' == themax)
				ans[i] = themin;
			else
			{
				int tmp = s[i] - 'a' + 1;
				while (!vis[tmp])tmp++;
				ans[i] = tmp;
				break;
			}
		}
		for (int j = i - 1;j >= 0;j--)
			ans[j] = s[j] - 'a';
		for (int i = 0;i < k;i++)
			printf("%c", ans[i] + 'a');
	}
	else
	{
		cout << s;
		printf("%c", themin + 'a');
	}
}


#include<iostream>
#include<algorithm>
#include<cstring>
#include<stdio.h>
#include<string>
#include<vector>
#include<math.h>
#include<set>
using namespace std;
typedef long long LL;
const int inf = 1e9;
bool vis[30];
int ans[100005];
int main()
{
	int n, k;
	cin >> n >> k;
	string s;
	cin >> s;
	for (int i = 0;i < s.size();i++)
		vis[s[i] - 'a'] = 1;

	int themax = 29;
	int themin = 0;
	while (!vis[themax])themax--;
	while (!vis[themin])themin++;
	if (n >= k)
	{
		int i;
		for (i = k - 1;i >= 0;i--)
		{
			if (s[i] - 'a' == themax)
				ans[i] = themin;
			else
			{
				int tmp = s[i] - 'a' + 1;
				while (!vis[tmp])tmp++;
				ans[i] = tmp;
				break;
			}
		}
		for (int j = i - 1;j >= 0;j--)
			ans[j] = s[j] - 'a';
		for (int i = 0;i < k;i++)
			printf("%c", ans[i] + 'a');
	}
	else
	{
		cout << s;
		for(int i=0;i<k-n;i++)
		printf("%c", themin + 'a');
	}
}


#include <cstdio>
#include <iostream>
#include <vector>
#include <queue>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
int l,r,i,n,m,k,t,b,ans,te,a[100],mid;
bool le[1000];char c[100000+10];char ch;
int main()
{
    scanf("%d%d",&n,&k);
    scanf("%s",c);
    for(int i=0;i<strlen(c);++i)
    {
        t=c[i]-97;
        le[t]=1;
    }
    b=0;
    for(int i=0;i<=26;++i)
    {
        if(le[i])
        {
            b++;
            a[b]=i;
        }
    }
    if(k>n)
    {
        printf("%s",c);
        ch=a[1]+97;
        for(int i=1;i<=k-strlen(c);++i)
            printf("%c",ch);
        return 0;
    }
    r=k;
    l=0;
    while(l<r-1)
    {
        mid=(r+l)/2;
        t=c[mid]-97;
        if(t<a[b])
            l=mid;
        else r=mid;
    }
    t=c[l+1]-97;
    while(t<a[b])
    {
        l++;
        t=c[l+1]-97;
    }
    for(int i=0;i<l;++i)
        printf("%c",c[i]);
    t=c[l]-97;
    for(int i=0;i<=26;++i)
    {
        if(le[i]&&i>t)
        {
            ch=i+97;
            printf("%c",ch);
            break;
        }
    }
    l++;
    ch=a[1]+97;
    for(int i=1;i<=k-l;++i)
        printf("%c",ch);
    return 0;
}


#include <cstdio>
#include <iostream>
#include <vector>
#include <queue>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
int len,l,r,i,n,m,k,t,b,ans,te,a[100],mid;
bool le[1000];char c[100000+10];char ch;
int main()
{
    scanf("%d%d",&n,&k);
    scanf("%s",c);
    len=strlen(c);
    for(int i=0;i<len;++i)
    {
        t=c[i]-97;
        le[t]=1;
    }
    b=0;
    for(int i=0;i<=26;++i)
    {
        if(le[i])
        {
            b++;
            a[b]=i;
        }
    }
    if(k>n)
    {
        printf("%s",c);
        ch=a[1]+97;
        for(int i=1;i<=k-strlen(c);++i)
            printf("%c",ch);
        return 0;
    }
   // c[len]=a[b]+97;
    for(int i=k-1;i>=0;--i)
    {
        t=c[i]-97;
        te=c[i+1]-97;
        if(t!=a[b]||(te!=a[b]&&i!=k-1))
        {
            l=i;
            break;
        }
        l=i;
    }
        for(int i=0;i<l;++i)
            printf("%c",c[i]);
        t=c[l]-97;
        for(int i=0;i<=26;++i)
        {
            if(le[i]&&i>t)
            {
                ch=i+97;
                printf("%c",ch);
                break;
            }
        }
        l++;
        ch=a[1]+97;
        for(int i=1;i<=k-l;++i)
            printf("%c",ch);
    return 0;
}


#include <cstdio>
#include <iostream>
#include <vector>
#include <queue>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
int l,r,i,n,m,k,t,b,ans,te,a[100],mid;
bool le[1000];char c[100000+10];char ch;
int main()
{
    scanf("%d%d",&n,&k);
    scanf("%s",c);
    for(int i=0;i<strlen(c);++i)
    {
        t=c[i]-97;
        le[t]=1;
    }
    b=0;
    for(int i=0;i<=26;++i)
    {
        if(le[i])
        {
            b++;
            a[b]=i;
        }
    }
    if(k>n)
    {
        printf("%s",c);
        ch=a[1]+97;
        for(int i=1;i<=k-strlen(c);++i)
            printf("%c",ch);
        return 0;
    }
    r=k;
    l=0;
    while(l<r-1)
    {
        mid=(r+l)/2;
        t=c[mid]-97;
        if(t<a[b])
            l=mid;
        else r=mid;
    }
    for(int i=0;i<l;++i)
        printf("%c",c[i]);
    t=c[l]-97;
    for(int i=0;i<=26;++i)
    {
        if(le[i]&&i>t)
        {
            ch=i+97;
            printf("%c",ch);
            break;
        }
    }
    l++;
    ch=a[1]+97;
    for(int i=1;i<=k-l;++i)
        printf("%c",ch);
    return 0;
}


#include <cstdio>
#include <iostream>
#include <vector>
#include <queue>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
int len,l,r,i,n,m,k,t,b,ans,te,a[100],mid;
bool le[1000];char c[100000+10];char ch;
int main()
{
    scanf("%d%d",&n,&k);
    scanf("%s",c);
    len=strlen(c);
    for(int i=0;i<len;++i)
    {
        t=c[i]-97;
        le[t]=1;
    }
    b=0;
    for(int i=0;i<=26;++i)
    {
        if(le[i])
        {
            b++;
            a[b]=i;
        }
    }
    if(k>n)
    {
        printf("%s",c);
        ch=a[1]+97;
        for(int i=1;i<=k-len;++i)
            printf("%c",ch);
        return 0;
    }
   // c[len]=a[b]+97;
    for(int i=k-1;i>=0;--i)
    {
        t=c[i]-97;
        te=c[i+1]-97;
        if(t!=a[b]||(te!=a[b]&&i!=k-1))
        {
            l=i;
            break;
        }
        l=i;
    }
        for(int i=0;i<l;++i)
            printf("%c",c[i]);
        t=c[l]-97;
        for(int i=0;i<=26;++i)
        {
            if(le[i]&&i>t)
            {
                ch=i+97;
                printf("%c",ch);
                break;
            }
        }
        l++;
        ch=a[1]+97;
        for(int i=1;i<=k-l;++i)
            printf("%c",ch);
    return 0;
}


#include <cstdio>
#include <iostream>
#include <vector>
#include <queue>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
long long  r,i,n,m,k,t,a,b,ans,te;
int main()
{
    scanf("%lld%lld%lld%lld",&n,&k,&a,&b);
    ans=0;
    if(k>n)
    {
        ans=(n-1)*a;
        printf("%lld",ans);
        return 0;
    }
    while(n!=1)
    {
        if(n%k!=0)
        {
          te=n;
          t=n/k;
          n=t*k;
          te=te-n;
          ans=ans+a*te;
          continue;
        }
        if(n%k==0)
        {
            t=n/k;
            if( (n-t)*a<=b )
            {
                ans=ans+ (n-1)*a;
                break;
            }
            n=n/k;
            ans=ans+b;
        }
    }
    printf("%lld",ans);
    return 0;
}


#include <cstdio>
#include <iostream>
#include <vector>
#include <queue>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
int len,l,r,i,n,m,k,t,b,ans,te,a[100],mid;
bool le[1000];char c[100000+10];char ch;
int main()
{
    scanf("%d%d",&n,&k);
    scanf("%s",c);
    len=strlen(c);
    for(int i=0;i<len;++i)
    {
        t=c[i]-97;
        le[t]=1;
    }
    b=0;
    for(int i=0;i<=26;++i)
    {
        if(le[i])
        {
            b++;
            a[b]=i;
        }
    }
    if(k>n)
    {
        printf("%s",c);
        ch=a[1]+97;
        for(int i=1;i<=k-strlen(c);++i)
            printf("%c",ch);
        return 0;
    }
    c[len]=a[b]+97;
    for(int i=k-1;i>=0;--i)
    {
        t=c[i]-97;
        te=c[i+1]-97;
        if(t!=a[b]||te!=a[b])
        {
            l=i;
            break;
        }
        l=i;
    }
        for(int i=0;i<l;++i)
            printf("%c",c[i]);
        t=c[l]-97;
        for(int i=0;i<=26;++i)
        {
            if(le[i]&&i>t)
            {
                ch=i+97;
                printf("%c",ch);
                break;
            }
        }
        l++;
        ch=a[1]+97;
        for(int i=1;i<=k-l;++i)
            printf("%c",ch);
    return 0;
}


#include <cstdio>
#include <iostream>
#include <vector>
#include <queue>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
int l,r,i,n,m,k,t,b,ans,te,a[100],mid;
bool le[1000];char c[100000+10];char ch;
int main()
{
    scanf("%d%d",&n,&k);
    scanf("%s",c);
    for(int i=0;i<strlen(c);++i)
    {
        t=c[i]-97;
        le[t]=1;
    }
    b=0;
    for(int i=0;i<=26;++i)
    {
        if(le[i])
        {
            b++;
            a[b]=i;
        }
    }
    if(k>n)
    {
        printf("%s",c);
        ch=a[1]+97;
        for(int i=1;i<=k-strlen(c);++i)
            printf("%c",ch);
        return 0;
    }
    r=k-1;
    l=0;
    while(l<=r-1)
    {
        mid=(r+l)/2;
        if(mid==l)
            break;
        t=c[mid]-97;
        if(t>=a[b])
            r=mid-1;
        else l=mid;
    }
    t=c[l+1]-97;
    while(t<a[b])
    {
        t=c[l+1]-97;
        if(t<a[b])
            l=l+1;
    }
    for(int i=0;i<l;++i)
        printf("%c",c[i]);
    t=c[l]-97;
    for(int i=0;i<=26;++i)
    {
        if(le[i]&&i>t)
        {
            ch=i+97;
            printf("%c",ch);
            break;
        }
    }
    l++;
    ch=a[1]+97;
    for(int i=1;i<=k-l;++i)
        printf("%c",ch);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
    int n,k,i,j,last=-1,letter;
    string s,res;
    cin>>n>>k;
    cin>>s;
    if(k>n)
    {
        res=s;
        while(res.size()<k)
        {
            res.push_back('a');
        }
        cout<<res<<endl;
        return 0;
    }
    vector<bool>chk(130,0);
    for(i=0;i<s.size();i++)
    {
        chk[s[i]]=1;
    }
    for(j=min(k-1,n-1);j>=0;j--)
    {
        //cout<<"j="<<j<<endl;
        int ck=0;
        for(i=s[j]+1;i<='z';i++)
        {
            if(chk[i]==1)
            {
                letter=i;
                last=j;
                ck=1;
                break;
            }
        }
        //cout<<"chk="<<ck<<endl;
        if(ck==1)
        {
            break;
        }
    }
    for(i=0;i<last;i++)
    {
        res.push_back(s[i]);
    }
    res.push_back(letter);
    while(res.size()<k)
    {
        res.push_back('a');
    }
    cout<<res<<endl;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
    int n,k,i,j,last=-1,letter,lowest=2e9;
    string s,res;
    cin>>n>>k;
    cin>>s;
    vector<bool>mark(1000,0);
    for(i=0;i<s.size();i++)
    {
        int c=s[i];
        mark[c]=1;
        lowest=min(lowest,c);
    }

    for(i=n-1;i>=0;i--)
    {
        int c=s[i],chk=0;
        for(j=s[i]+1;j<='z';j++)
        {
            if(mark[j]==1)
            {
                last=i;
                letter=j;
                chk=1;
                break;
            }
        }
        if(chk)
        {
            break;
        }
    }
    if(last==-1)
    {
        res=s;
        while(res.size()<k)
        {
            res.push_back(lowest);
        }
    }
    else
    {
        for(i=0;i<last;i++)
        {
            res.push_back(s[i]);
        }
        res.push_back(letter);
        while(res.size()<k)
        {
            res.push_back(lowest);
        }
    }
    cout<<res<<endl;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
    int n,k,i,j,last=-1,letter,lowest=2e9;
    string s,res;
    cin>>n>>k;
    cin>>s;
    vector<bool>mark(1000,0);
    for(i=0;i<s.size();i++)
    {
        int c=s[i];
        mark[c]=1;
        lowest=min(lowest,c);
    }
    if(k>n)
    {
        res=s;
        while(res.size()<k)
        {
            res.push_back(lowest);
        }
        cout<<res<<endl;
        return 0;
    }
    for(i=min(n-1,k-1);i>=0;i--)
    {
        int c=s[i],chk=0;
        for(j=s[i]+1;j<='z';j++)
        {
            if(mark[j]==1)
            {
                last=i;
                letter=j;
                chk=1;
                break;
            }
        }
        if(chk)
        {
            break;
        }
    }
    for(i=0;i<last;i++)
    {
        res.push_back(s[i]);
    }
    res.push_back(letter);

    while(res.size()<k)
    {
        res.push_back(lowest);
    }
    cout<<res<<endl;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
    int n,k,i,j,last=-1,letter;
    string s,res;
    cin>>n>>k;
    cin>>s;
    if(k>n)
    {
        res=s;
        while(res.size()<k)
        {
            res.push_back('a');
        }
        cout<<res<<endl;
        return 0;
    }
    vector<bool>chk(130,0);
    for(i=0;i<s.size();i++)
    {
        chk[s[i]]=1;
    }
    for(j=min(k-1,n-1);j>=0;j--)
    {
        cout<<"j="<<j<<endl;
        int ck=0;
        for(i=s[j]+1;i<='z';i++)
        {
            if(chk[i]==1)
            {
                letter=i;
                last=j;
                ck=1;
                break;
            }
        }
        cout<<"chk="<<ck<<endl;
        if(ck==1)
        {
            break;
        }
    }
    for(i=0;i<last;i++)
    {
        res.push_back(s[i]);
    }
    res.push_back(letter);
    while(res.size()<k)
    {
        res.push_back('a');
    }
    cout<<res<<endl;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
    int n,k,i,j,last=-1,letter,lowest=2e9;
    string s,res;
    cin>>n>>k;
    cin>>s;
    vector<bool>mark(1000,0);
    for(i=0;i<s.size();i++)
    {
        int c=s[i];
        mark[c]=1;
        lowest=min(lowest,c);
    }
    if(k>n)
    {
        res=s;
        while(res.size()<k)
        {
            res.push_back(lowest);
        }
        cout<<res<<endl;
        return 0;
    }
    for(i=n-1;i>=0;i--)
    {
        int c=s[i],chk=0;
        for(j=s[i]+1;j<='z';j++)
        {
            if(mark[j]==1)
            {
                last=i;
                letter=j;
                chk=1;
                break;
            }
        }
        if(chk)
        {
            break;
        }
    }
    for(i=0;i<last;i++)
    {
        res.push_back(s[i]);
    }
    res.push_back(letter);

    while(res.size()<k)
    {
        res.push_back(lowest);
    }
    cout<<res<<endl;
}


#include<cstdio>
#include<cstring>
#include<string>
#include<sstream>
#include<iostream>
#include<set>
#include<map>
#include<queue>
#include<vector>
#include<algorithm>
#include<cctype>
#include<math.h>
#include<stdlib.h>
#include<stack>
#include<ctime>
#define mst(a,b) memset(a,b,sizeof(a))
#define ALL(x) x.begin(),x.end()
#define INS(x) inserter(x,x.begin())
#define pii pair<int,int>
const int N = 1e9;
const int mod=(int)1e9+7;
const int INF=0x3f3f3f3f;
const long long LINF=(1LL<<62);
typedef long long LL;
//#define LOCAL
const double PI = acos(-1.0);
const int maxn=1e3+5;
using namespace std;

int main()
{
#ifdef LOCAL
    freopen("test.txt", "r", stdin);
#endif // LOCAL
    //ios::sync_with_stdio(false);
    int n, k; scanf("%d%d", &n, &k);
    string s; cin>>s;string t = s;
    vector<char> em;
    sort(t.begin(),t.end());
    //cout<<s<<endl;
    em.push_back(t[0]);
    for(int i = 1; i < n; i++){
        if(t[i]==t[i-1]) continue;
        em.push_back(t[i]);
    }
    string ans="";
    if(k>n){
        ans+=s;
        for(int i = 0; i < k-n; i++) ans+=t[0];
        cout<<ans<<endl;
    }
    else{
        int is = 1;
        for(int i = 1; (i <= k)&&is; i++){
            if(i==k) {
                for(int j = 0; (j < em.size())&&is; j++){
                    if(em[j]>s[i-1]){
                        ans+=em[j];
                        is = 0;
                    }
                }
            }
            else{
                if(em.back()>s[i]) ans+=s[i-1];
                else {
                    for(int j = 0; (j < em.size())&&is; j++){
                        if(em[j]>s[i-1]){
                            ans+=em[j];
                            while(ans.length()<k) ans+=t[0];
                            is = 0;
                        }
                    }
                }
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}


#include<cstdio>
#include<cstring>
#include<string>
#include<sstream>
#include<iostream>
#include<set>
#include<map>
#include<queue>
#include<vector>
#include<algorithm>
#include<cctype>
#include<math.h>
#include<stdlib.h>
#include<stack>
#include<ctime>
#define mst(a,b) memset(a,b,sizeof(a))
#define ALL(x) x.begin(),x.end()
#define INS(x) inserter(x,x.begin())
#define pii pair<int,int>
const int N = 1e9;
const int mod=(int)1e9+7;
const int INF=0x3f3f3f3f;
const long long LINF=(1LL<<62);
typedef long long LL;
//#define LOCAL
const double PI = acos(-1.0);
const int maxn=1e3+5;
using namespace std;

int main()
{
#ifdef LOCAL
    freopen("test.txt", "r", stdin);
#endif // LOCAL
    ios::sync_with_stdio(false);
    int n, k; scanf("%d%d", &n, &k);
    string s; cin>>s;string t = s;
    vector<char> em;
    sort(t.begin(),t.end());
    //cout<<s<<endl;
    em.push_back(t[0]);
    for(int i = 1; i < n; i++){
        if(t[i]==t[i-1]) continue;
        em.push_back(t[i]);
    }
    string ans;
    if(k>n){
        ans+=s;
        for(int i = 0; i < k-n; i++) ans+=t[0];
        cout<<ans<<endl;
    }
    else{
        int is = 1;
        for(int i = 1; (i <= k)&&is; i++){
            if(i==k) {
                for(int j = 0; (j < em.size())&&is; j++){
                    if(em[j]>s[i-1]){
                        ans+=em[j];
                        is = 0;
                    }
                }
            }
            else{
                if(em.back()>s[i]) ans+=s[i-1];
                else {
                    for(int j = 0; (j < em.size())&&is; j++){
                        if(em[j]>s[i-1]){
                            ans+=em[j];
                            while(ans.length()<k) ans+=t[0];
                            is = 0;
                        }
                    }
                }
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}


#include<cstdio>
#include<cstring>
#include<string>
#include<sstream>
#include<iostream>
#include<set>
#include<map>
#include<queue>
#include<vector>
#include<algorithm>
#include<cctype>
#include<math.h>
#include<stdlib.h>
#include<stack>
#include<ctime>
#define mst(a,b) memset(a,b,sizeof(a))
#define ALL(x) x.begin(),x.end()
#define INS(x) inserter(x,x.begin())
#define pii pair<int,int>
const int N = 1e9;
const int mod=(int)1e9+7;
const int INF=0x3f3f3f3f;
const long long LINF=(1LL<<62);
typedef long long LL;
//#define LOCAL
const double PI = acos(-1.0);
const int maxn=1e3+5;
using namespace std;

int cnt[maxn];

int main()
{
#ifdef LOCAL
    freopen("test.txt", "r", stdin);
#endif // LOCAL
    //ios::sync_with_stdio(false);
    int n, k; scanf("%d%d", &n, &k);
    string s; cin>>s;string t = s;
    vector<char> em;
    sort(t.begin(),t.end());
    //cout<<s<<endl;
    em.push_back(t[0]);
    for(int i = 1; i < n; i++){
        cnt[t[i]]++;
        if(t[i]==t[i-1]) continue;
        em.push_back(t[i]);
    }
    string ans="";
    if(n==1&&k==1) cout<<s<<endl;
    else if(k>n){
        ans+=s;
        for(int i = 0; i < k-n; i++) ans+=em[0];
        cout<<ans<<endl;
    }
    else{
        int is = 1;
        for(int i = 1; (i <= k)&&is; i++){
            if(i==k) {
                for(int j = 0; (j < em.size())&&is; j++){
                    if(em[j]>s[i-1]){
                        ans+=em[j];
                        is = 0;
                    }
                }
            }
            else{
                if(em.back()>=s[i]&&cnt[em.back()]<n-i) {ans+=s[i-1];cnt[s[i-1]]--;}
                else {
                    for(int j = 0; (j < em.size())&&is; j++){
                        if(em[j]>s[i-1]){
                            ans+=em[j];
                            while(ans.length()<k) ans+=em[0];
                            is = 0;
                        }
                    }
                }
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}


#include<cstdio>
#include<cstring>
#include<string>
#include<sstream>
#include<iostream>
#include<set>
#include<map>
#include<queue>
#include<vector>
#include<algorithm>
#include<cctype>
#include<math.h>
#include<stdlib.h>
#include<stack>
#include<ctime>
#define mst(a,b) memset(a,b,sizeof(a))
#define ALL(x) x.begin(),x.end()
#define INS(x) inserter(x,x.begin())
#define pii pair<int,int>
const int N = 1e9;
const int mod=(int)1e9+7;
const int INF=0x3f3f3f3f;
const long long LINF=(1LL<<62);
typedef long long LL;
//#define LOCAL
const double PI = acos(-1.0);
const int maxn=1e3+5;
using namespace std;

int cnt[maxn];

int main()
{
#ifdef LOCAL
    freopen("test.txt", "r", stdin);
#endif // LOCAL
    //ios::sync_with_stdio(false);
    int n, k; scanf("%d%d", &n, &k);
    string s; cin>>s;string t = s;
    vector<char> em;
    sort(t.begin(),t.end());
    //cout<<s<<endl;
    em.push_back(t[0]);
    for(int i = 1; i < n; i++){
        cnt[t[i]]++;
        if(t[i]==t[i-1]) continue;
        em.push_back(t[i]);
    }
    string ans="";
    if(k>n){
        ans+=s;
        for(int i = 0; i < k-n; i++) ans+=em[0];
        cout<<ans<<endl;
    }
    else{
        ans = s.substr(0,k);
        for(int i = k-1; i >= 0; i--){
            //char temp = ans[i];
            if(ans[i]==em.back()) continue;
            else{
                for(int j = 0; j < em.size(); j++){
                    if(em[j]>ans[i]) {ans[i] = em[j];break;}
                }
                for(int j = i+1; j < k; j++) ans[j] = em[0];
                cout<<ans<<endl;
                return 0;
            }
        }
    }
    return 0;
}


#include<cstdio>
#include<cstring>
#include<string>
#include<sstream>
#include<iostream>
#include<set>
#include<map>
#include<queue>
#include<vector>
#include<algorithm>
#include<cctype>
#include<math.h>
#include<stdlib.h>
#include<stack>
#include<ctime>
#define mst(a,b) memset(a,b,sizeof(a))
#define ALL(x) x.begin(),x.end()
#define INS(x) inserter(x,x.begin())
#define pii pair<int,int>
const int N = 1e9;
const int mod=(int)1e9+7;
const int INF=0x3f3f3f3f;
const long long LINF=(1LL<<62);
typedef long long LL;
//#define LOCAL
const double PI = acos(-1.0);
const int maxn=1e3+5;
using namespace std;

int main()
{
#ifdef LOCAL
    freopen("test.txt", "r", stdin);
#endif // LOCAL
    ios::sync_with_stdio(false);
    int n, k; scanf("%d%d", &n, &k);
    string s; cin>>s;string t = s;
    vector<char> em;
    sort(t.begin(),t.end());
    //cout<<s<<endl;
    em.push_back(t[0]);
    for(int i = 1; i < n; i++){
        if(t[i]==t[i-1]) continue;
        em.push_back(t[i]);
    }
    string ans="";
    if(k>n){
        ans+=s;
        for(int i = 0; i < k-n; i++) ans+=t[0];
        cout<<ans<<endl;
    }
    else{
        int is = 1;
        for(int i = 1; (i <= k)&&is; i++){
            if(i==k) {
                for(int j = 0; (j < em.size())&&is; j++){
                    if(em[j]>s[i-1]){
                        ans+=em[j];
                        is = 0;
                    }
                }
            }
            else{
                if(em.back()>s[i]) ans+=s[i-1];
                else {
                    for(int j = 0; (j < em.size())&&is; j++){
                        if(em[j]>s[i-1]){
                            ans+=em[j];
                            while(ans.length()<k) ans+=t[0];
                            is = 0;
                        }
                    }
                }
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main(){
	int n,k;
	set<char> ss;
	string a;
	cin>>n>>k;
	cin>>a;
	char c='a',d='z';
	for(int i=0;i<n;i++){
		ss.insert(a[i]);
		if(a[i]>c)  c=a[i];
		if(a[i]<d)  d=a[i];
	}
	if(k>n){
		cout<<a;
		int w=k-n;
		while(w--){
			cout<<d;
		}
		cout<<endl;
		return 0;
	}
	bool ok=false;
	int i;
	if(a[0]!=c){
		for(i=0;i<k;i++){
			if((i!=k-1&&a[i+1]!=c)||a[i]==a[i+1])  cout<<a[i];
			else{
				set<char>::iterator it;
				for(it=ss.begin();it!=ss.end();it++)
					if(*it==a[i]){
						it++;
						cout<<*it;
						break;
					}
				ok=true;
				break;
			}
		}
		if(ok)  for(;i<k-1;i++)  cout<<d;
		cout<<endl;
	}
	else{
		int j;
		for(j=0;j<k;j++)
			if(a[j]==c)  cout<<c;
			else  break;
		set<char>::iterator it;
		for(it=ss.begin();it!=ss.end();it++)
			if(*it==a[j]){
				it++;
				cout<<*it;
				break;
			}
		for(;j<k-1;j++)
			cout<<d;
		cout<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main(){
	int n,k;
	set<char> ss;
	string a;
	cin>>n>>k;
	cin>>a;
	char c='a',d='z';
	for(int i=0;i<n;i++){
		ss.insert(a[i]);
		if(a[i]>c)  c=a[i];
		if(a[i]<d)  d=a[i];
	}
	if(k>n){
		cout<<a;
		int w=k-n;
		while(w--){
			cout<<d;
		}
		cout<<endl;
		return 0;
	}
	bool ok=false;
	int i;
	for(i=0;i<k;i++){
		if((i!=k-1&&a[i+1]!=c)||a[i]==a[i+1])  cout<<a[i];
		else{
			set<char>::iterator it;
			for(it=ss.begin();it!=ss.end();it++)
				if(*it==a[i]){
					it++;
					cout<<*it;
					break;
				}
			ok=true;
			break;
		}
	}
	if(ok)  for(;i<k-1;i++)  cout<<d;
	cout<<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define pb push_back

const int maxn=1e6+10;
int n,k;
bool vis[35];
char a[maxn],b[maxn];
vector<int> s;

int main(){
	scanf("%d%d",&n,&k);
	scanf("%s",a);
	for(int i=0;i<n;i++)
		if(!vis[a[i]-'a']){
			s.pb(a[i]-'a');
			vis[a[i]-'a']=true;
		}
	sort(s.begin(),s.end());
	int num=s.size();
	if(k>n){
		printf("%s",a);
		int fuck=k-n;
		while(fuck--){
			printf("%c",s[0]+'a');
		}
		printf("\n");
		return 0;
	}
	int pos=-1;
	for(int i=k-1;i>=0;i--){
		if(a[i]!=s[num-1]+'a'){
			pos=i;
			break;
		}
	}
	if(pos==-1)  pos=k-1;
	int i;
	for(i=0;i<k;i++){
		if(i==pos){
			int fuck;
			for(int j=0;j<num;j++){
				if(a[i]==s[j]+'a'){
					fuck=j;
					break;
				}
			}
			printf("%c",s[fuck+1]+'a');
			break;
		}
		else  printf("%c",a[i]);
	}
	int mmp=k-i-1;
	while(mmp--){
		printf("%c",s[0]+'a');
	}
	printf("\n");
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main(){
	int n,k;
	set<char> ss;
	string a;
	cin>>n>>k;
	cin>>a;
	char c='a',d='z';
	for(int i=0;i<n;i++){
		ss.insert(a[i]);
		if(a[i]>c)  c=a[i];
		if(a[i]<d)  d=a[i];
	}
	if(k>n){
		cout<<a;
		int w=k-n;
		while(w--){
			cout<<d;
		}
		cout<<endl;
		return 0;
	}
	bool ok=false;
	int i;
	if(a[0]!=c){
		for(i=0;i<k;i++){
			if((i!=k-1&&a[i+1]!=c)||a[i]==a[i+1])  cout<<a[i];
			else{
				set<char>::iterator it;
				for(it=ss.begin();it!=ss.end();it++)
					if(*it==a[i]){
						it++;
						cout<<*it;
						break;
					}
				ok=true;
				break;
			}
		}
		if(ok)  for(;i<k-1;i++)  cout<<d;
		cout<<endl;
	}
	else{
		int j;
		for(j=0;j<k;j++)
			if(a[j]==c)  cout<<c;
		set<char>::iterator it;
		for(it=ss.begin();it!=ss.end();it++)
			if(*it==a[j]){
				it++;
				cout<<*it;
				break;
			}
		for(;j<k-1;j++)
			cout<<d;
		cout<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main(){
	int n,k;
	set<char> ss;
	string a;
	cin>>n>>k;
	cin>>a;
	char c='a',d='z';
	for(int i=0;i<n;i++){
		ss.insert(a[i]);
		if(a[i]>c)  c=a[i];
		if(a[i]<d)  d=a[i];
	}
	if(k>n){
		cout<<a;
		int w=k-n;
		while(w--){
			cout<<d;
		}
		cout<<endl;
		return 0;
	}
	bool ok=false;
	int i;
	for(i=0;i<k;i++){
		if(i!=k-1&&a[i+1]!=c)  cout<<a[i];
		else{
			set<char>::iterator it;
			for(it=ss.begin();it!=ss.end();it++)
				if(*it==a[i]){
					it++;
					cout<<*it;
					break;
				}
			ok=true;
			break;
		}
	}
	if(ok)  for(;i<k-1;i++)  cout<<d;
	cout<<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define pb push_back

const int maxn=1e5+10;
int n,k;
bool vis[35];
char a[maxn],b[maxn];
vector<int> s;

int main(){
	scanf("%d%d",&n,&k);
	scanf("%s",a);
	for(int i=0;i<n;i++)
		if(!vis[a[i]-'a']){
			s.pb(a[i]-'a');
			vis[a[i]-'a']=true;
		}
	sort(s.begin(),s.end());
	int num=s.size();
	if(k>n){
		printf("%s",a);
		int fuck=k-n;
		while(fuck--){
			printf("%c",s[0]+'a');
		}
		printf("\n");
		return 0;
	}
	int pos;
	for(int i=0;i<n;i++)
		if(a[i]!=s[num-1]+'a'){
			pos=i;
			break;
		}
	int mmp=-1;
	for(int i=pos;i<k-1;i++)
		if(a[i+1]==s[num-1]+'a'){
			mmp=i;
			break;
		}
	if(mmp==-1)  mmp=k-1;
	int i;
	for(i=0;i<k;i++){
		if(i==mmp){
			int fuck=0;
			for(int j=0;j<num;j++)
				if(s[j]==a[i]-'a')  fuck=j;
			printf("%c",s[fuck+1]+'a');
			break;
		}
		else  printf("%c",a[i]);
	}
	int shit=k-i-1;
	while(shit--){
		printf("%c",s[0]+'a');
	}
	printf("\n");
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main(){
	int n,k;
	set<char> ss;
	string a;
	cin>>n>>k;
	cin>>a;
	char c='a',d='z';
	for(int i=0;i<n;i++){
		ss.insert(a[i]);
		if(a[i]>c)  c=a[i];
		if(a[i]<d)  d=a[i];
	}
	if(k>n){
		cout<<a;
		int w=k-n;
		while(w--){
			cout<<d;
		}
		cout<<endl;
		return 0;
	}
	bool ok=false;
	int i;
	for(i=0;i<k;i++){
		if(a[i+1]!=c)  cout<<a[i];
		else{
			set<char>::iterator it;
			for(it=ss.begin();it!=ss.end();it++)
				if(*it==a[i]){
					it++;
					cout<<*it;
					break;
				}
			ok=true;
			break;
		}
	}
	if(ok)  for(;i<k-1;i++)  cout<<d;
	cout<<endl;
	return 0;
}


#include <iostream>
#include<stdio.h>
#include<algorithm>
#include<math.h>
using namespace std;
const int maxn = 100000;
char S[maxn+5],F[maxn+5];
int n,k,letter[55];
int main()
{
    scanf("%d %d",&n,&k);
    scanf("%s",S);
    for(int i=0; i<n; i++) letter[S[i]-'a']=1;
    if(k>n)
    {
        printf("%s",S);
        int mi;
        for(mi=0; mi<50&&!letter[mi]; mi++);
        for(int j=n; j<k; j++) printf("%c",'a'+mi);
        printf("\n");
    }
    else
    {
        int ok = -1;
        for(int i=n-1; i>=0; i--)
        {
            if(ok!=-1) break;
            int c = -1;
            for(int j=S[i]-'a'+1; j<30; j++)
            {
                if(letter[j])
                {
                    c = j;
                    break;
                }
            }
            if(c==-1) continue;
            F[i] = 'a'+c;
            ok = i;
        }
        for(int i=0; i<ok; i++) printf("%c",S[i]);
        printf("%c",F[ok]);
        int mi;
        for(mi=0; mi<30&&!letter[mi]; mi++);
        for(int i=ok+1; i<k; i++) printf("%c",'a'+mi);
        printf("\n");
    }
    return 0;
}


#include <iostream>
#include<stdio.h>
#include<algorithm>
#include<math.h>
using namespace std;
const int maxn = 100000;
char S[maxn+5],F[maxn+5];
int n,k,letter[55];
int main()
{
    scanf("%d %d",&n,&k);
    scanf("%s",S);
    for(int i=0; i<n; i++) letter[S[i]-'a']=1;
    if(k>n)
    {
        printf("%s",S);
        int mi;
        for(mi=0; mi<50&&!letter[mi]; mi++);
        for(int j=n; j<k; j++) printf("%c",'a'+mi);
        printf("\n");
    }
    else
    {
       // cout<<" === "<<k<<endl;
        int ok = -1;
        for(int i=k-1; i>=0; i--)
        {
            if(ok!=-1) break;
            int c = -1;
            for(int j=S[i]-'a'+1; j<30; j++)
            {
                if(letter[j])
                {
                    c = j;
                    break;
                }
            }
            if(c==-1) continue;
            F[i] = 'a'+c;
            ok = i;
        }
        for(int i=0; i<ok; i++) printf("%c",S[i]);
        if(ok!=-1) printf("%c",F[ok]);
        int mi;
        for(mi=0; mi<30&&!letter[mi]; mi++);
        for(int i=ok+1; i<k; i++) printf("%c",'a'+mi);
        printf("\n");
    }
    return 0;
}


#include <iostream>
#include<stdio.h>
#include<algorithm>
#include<math.h>
using namespace std;
const int maxn = 100000;
char S[maxn+5],F[maxn+5];
int n,k,letter[55];
int main()
{
    scanf("%d %d",&n,&k);
    scanf("%s",S);
    for(int i=0; i<n; i++) letter[S[i]-'a']=1;
    if(k>n)
    {
        printf("%s",S);
        int i;
        for(i=0; i<50&&!letter[i]; i++);
        for(int j=n; j<k; j++) printf("%c",'a'+i);
        printf("\n");
    }
    else
    {
        int ok = -1;
        for(int i=n-1; i>=0; i--)
        {
            if(ok!=-1) break;
            int c = -1;
            for(int j=S[i]-'a'+1; j<30; j++)
            {
                if(letter[j])
                {
                    c = j;
                    break;
                }
            }
            if(c==-1) continue;
            F[i] = 'a'+c;
            ok = i;
        }
        for(int i=0; i<ok; i++) printf("%c",S[i]);
        printf("%c",F[ok]);
        int mi;
        for(mi=0; mi<30&&!letter[mi]; mi++);
        for(int i=ok+1; i<k; i++) printf("%c",'a'+mi);
        printf("\n");
    }
    return 0;
}


#include <iostream>
#include<stdio.h>
#include<algorithm>
#include<math.h>
using namespace std;
const int maxn = 10000;
char S[maxn+5],F[maxn+5];
int n,k,letter[55];
int main()
{
    scanf("%d %d",&n,&k);
    scanf("%s",S);
    for(int i=0; i<n; i++) letter[S[i]-'a']=1;
    if(k>n)
    {
        printf("%s",S);
        int i;
        for(i=0; i<50&&!letter[i]; i++);
        for(int j=n-1; j<k; j++) printf("%c",'a'+i);
        printf("\n");
    }
    else
    {
        int ok = -1;
        for(int i=n-1; i>=0; i--)
        {
            if(ok!=-1) break;
            int c = -1;
            for(int j=S[i]-'a'+1; j<30; j++)
            {
                if(letter[j])
                {
                    c = j;
                    break;
                }
            }
            if(c==-1) continue;
            F[i] = 'a'+c;
            ok = i;
        }
        for(int i=0; i<ok; i++) printf("%c",S[i]);
        printf("%c",F[ok]);
        int mi;
        for(mi=0; mi<30&&!letter[mi]; mi++);
        for(int i=ok+1; i<k; i++) printf("%c",'a'+mi);
        printf("\n");
    }
    return 0;
}


#include <iostream>
#include<stdio.h>
#include<algorithm>
#include<math.h>
using namespace std;
const int maxn = 10000;
char S[maxn+5],F[maxn+5];
int n,k,letter[50];
int main()
{
    scanf("%d %d",&n,&k);
    scanf("%s",S);
    for(int i=0; i<n; i++) letter[S[i]-'a']=1;
    if(k>n)
    {
        printf("%s",S);
        int i;
        for(i=0; i<=50&&!letter[i]; i++);
        for(int j=1; j<=k-n; j++) printf("%c",'a'+i);
        printf("\n");
    }
    else
    {
        int ok = -1;
        for(int i=n-1; i>=0; i--)
        {
            if(ok!=-1) break;
            int c = -1;
            for(int j=S[i]-'a'+1; j<30; j++)
            {
                if(letter[j])
                {
                    c = j;
                    break;
                }
            }
            //cout<<S[i]<<" === "<<c<<endl;
            if(c==-1) continue;
            F[i] = 'a'+c;
            ok = i;
        }
       // cout<<" ok "<<ok<<endl;
        if(ok==-1)
        {
            int mii=0;
            for(int i=0; i<=30; i++)
            {
                if(letter[i]) mii++;
                if(mii == 2)
                {
                    mii = i;
                    break;
                }
            }
            printf("%c",'a'+mii);
            int mi;
            for(mi=0; mi<30&&!letter[mi]; mi++);
            for(int i=1; i<k; i++) printf("%c",'a'+mi);
            printf("\n");
        }
        else
        {
            for(int i=0; i<ok; i++) printf("%c",S[i]);
            printf("%c",F[ok]);
            int mi;
            for(mi=0; mi<30&&!letter[mi]; mi++);
            for(int i=ok+1; i<k; i++) printf("%c",'a'+mi);
            printf("\n");
        }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define lp(i,m) for(int i =0 ;i<m;i++)
#define lp1(i,b,e) for(int i = b;i<e;i++)
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define Endl '\n'
const int N = 1e6 + 10;
#define pi acos(-1)
#define eps 1e-9
int A[N],seg[4*N];
int dp[100][100];
int ans = 0;
int n;
void Build(int n, int s, int e) {
	if (s == e) {
		seg[n] = A[s];
		return;
	}
	Build(2 * n, s, (s + e) / 2);
	Build(2 * n + 1, (s + e) / 2 + 1, e);

	seg[n] = min(seg[2 * n], seg[2 * n + 1]);
}

int get(int n, int s, int e, int rl, int rr) {
	if (s > rr || e < rl) return 1e9;
	if (s >= rl && e <= rr) {
		return seg[n];
	}

	return min(get(n * 2, s, (s + e) / 2, rl, rr), get(n * 2 + 1, (s + e) / 2 + 1, e, rl, rr));
}
int solve(int index, int sz) {
	if (index == n + 1) return 0;
	int c1 = 1e9, sum = 0;

	for (int i = index; i <= n; ++i) {
		sum += A[i];
	}
}
int main() {
	int n, k;
	string s;
	cin >> n >> k;
	cin >> s;
	set<char> t(s.begin(), s.end());
	if (n < k) {
		cout << s;
		lp(i, k - n) cout << *t.begin();
		return 0;
	}
	int idx = -1;
	char mx = *t.rbegin();
	for (int i = 0; i < n; ++i) {
		if (mx != s[i]) {
			idx = i;
		}
	}
	string m = s;
	sort(m.begin(), m.end());
	for (int i = 0; i < s.size(); ++i) {
		if (s[i] > mx) {
			mx = s[i];
			break;
		}
	}
	for (int i = 0; i < idx; ++i) {
		cout << s[i];
	}
	cout << mx;
	for (int i = idx + 1; i < k; ++i) {
		cout << *t.begin();
	}
	// Think and hold on before coding
	// Think about Reverse Thinking
	// OverFlow ? long long or int
	// keep your mind of array size
	// 2 Minutes Tracing Better Than 20 Minute Penalty
	// Programming Your Mind on Success
	// Corner Case [n == 1 , n == 0 ]
}