#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <time.h>
#include <stdio.h>
#include <queue>
#include <unordered_map>
using namespace std;
#define ll long long
#define INF 1e9
#define pb push_back
#define pii pair<int,int>
vector < pair<int, int>> g;
bool cmp(vector<char> a, vector<char> b) {
	for (int i = 0; i < a.size();i++) {
		if (a[i] < b[i])
			return true;
		if (a[i] > b[i])
			return false;
	}
	return false;
}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n, k;
	cin >> n >> k;
	vector<char> a;
	vector<char> is;
	a.resize(n);
	set<char> s;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		s.insert(a[i]);
	}
	vector<char> pr;
	for (set<char>::iterator it = s.begin(); it != s.end(); it++) {
		pr.pb(*it);
	}
	is = a;
	bool cm = false;
	next_permutation(a.begin(), a.end());
	if (k > n) {
		for (int i = 0; i < n; i++) {
			cout << is[i];
		}
		for (int i = n; i < k; i++) {
			cout << pr[0];
		}
		return 0;
	}
	if (cmp(a, is))
		a = is;
	for (int i = 0; i < min(n,k); i++) {
		if (cm) {
			cout << pr[0];
		}
		else {
			char c = a[i];
			for (int j = 0; j < pr.size(); j++) {
				if (pr[j] >= c) {
					cout << pr[j];
					if (pr[j]>is[i])
						cm = true;
					break;
				}
			}
		}
	}
	for (int i = n; i < k; i++) {
		cout << pr[0];
	}

}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <time.h>
#include <stdio.h>
#include <queue>
#include <unordered_map>
using namespace std;
#define ll long long
#define INF 1e9
#define pb push_back
#define pii pair<int,int>
vector < pair<int, int>> g;
bool cmp(vector<char> a, vector<char> b) {
	for (int i = 0; i < a.size();i++) {
		if (a[i] < b[i])
			return true;
		if (a[i] > b[i])
			return false;
	}
	return false;
}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n, k;
	cin >> n >> k;
	vector<char> a;
	vector<char> is;
	a.resize(n);
	set<char> s;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		s.insert(a[i]);
	}
	vector<char> pr;
	for (set<char>::iterator it = s.begin(); it != s.end(); it++) {
		pr.pb(*it);
	}
	if (k > n) {
		for (int i = 0; i < n; i++) {
			cout << a[i];
		}
		for (int i = n; i < k; i++) {
			cout << pr[0];
		}
		return 0;
	}
	if (n == k) {
		is = a;
		bool cm = false;
			for (int i = n - 1; i > 0; i--) {
				if (a[i] < pr[pr.size() - 1]) {
					for (int j = 0; j < pr.size();j++) {
						if (pr[j] > a[i]) {
							a[i] = pr[j];
							break;
						}
					}
					break;
				}
			}
			for (int i = 0; i < n; i++) {
				if (cm) {
					cout << pr[0];
				}
				else {
					cout << a[i];
					if (a[i] > is[i])
						cm = true;
				}
			}
		return 0;
	}
	int g = 1e9;
	for (int i = k - 1; i >= 0; i--) {
		if (a[i] != pr[pr.size() - 1]) {
			for (int j = 0; j < pr.size(); j++) {
				if (pr[j] > a[i]) {
					a[i] = pr[j];
					g = i;
					break;
				}
			}
			break;
		}
	}
	for (int i = 0; i < k; i++) {
		if (i <= g)
			cout << a[i];

		else
			cout << pr[0];
	}
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <time.h>
#include <stdio.h>
#include <queue>
#include <unordered_map>
using namespace std;
#define ll long long
#define INF 1e9
#define pb push_back
#define pii pair<int,int>
vector < pair<int, int>> g;
bool cmp(vector<char> a, vector<char> b) {
	for (int i = 0; i < a.size();i++) {
		if (a[i] < b[i])
			return true;
		if (a[i] > b[i])
			return false;
	}
	return false;
}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n, k;
	cin >> n >> k;
	vector<char> a;
	vector<char> is;
	a.resize(n);
	set<char> s;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		s.insert(a[i]);
	}
	vector<char> pr;
	for (set<char>::iterator it = s.begin(); it != s.end(); it++) {
		pr.pb(*it);
	}
	if (k > n) {
		for (int i = 0; i < n; i++) {
			cout << a[i];
		}
		for (int i = n; i < k; i++) {
			cout << pr[0];
		}
		return 0;
	}
	if (n == k) {
		vector<char> is;
		is = a;
		bool cm = false;
		next_permutation(a.begin(), a.end());
		if (cmp(a, is)) {
			a = is;
			for (int i = n - 1; i > 0; i--) {
				if (a[i] < pr[pr.size() - 1]) {
					for (int j = 0; j < pr.size();j++) {
						if (pr[j] > a[i]) {
							a[i] = pr[j];
							break;
						}
					}
					break;
				}
			}
		}
			for (int i = 0; i < n; i++) {
				if (cm) {
					cout << pr[0];
				}
				else {
					cout << a[i];
					if (a[i] > is[i])
						cm = true;
				}
			}
		return 0;
	}
	int g = 1e9;
	for (int i = k - 1; i >= 0; i--) {
		if (a[i] != pr[pr.size() - 1]) {
			for (int j = 0; j < pr.size(); j++) {
				if (pr[j] > a[i]) {
					a[i] = pr[j];
					g = i;
					break;
				}
			}
			break;
		}
	}
	for (int i = 0; i < k; i++) {
		if (i <= g)
			cout << a[i];

		else
			cout << pr[0];
	}
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <time.h>
#include <stdio.h>
#include <queue>
#include <unordered_map>
using namespace std;
#define ll long long
#define INF 1e9
#define pb push_back
#define pii pair<int,int>
vector < pair<int, int>> g;
bool cmp(vector<char> a, vector<char> b) {
	for (int i = 0; i < a.size();i++) {
		if (a[i] < b[i])
			return true;
		if (a[i] > b[i])
			return false;
	}
	return false;
}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n, k;
	cin >> n >> k;
	vector<char> a;
	vector<char> is;
	a.resize(n);
	set<char> s;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		s.insert(a[i]);
	}
	vector<char> pr;
	for (set<char>::iterator it = s.begin(); it != s.end(); it++) {
		pr.pb(*it);
	}
	is = a;
	bool cm = false;
	next_permutation(a.begin(), a.end());
	if (k > n) {
		for (int i = 0; i < n; i++) {
			cout << is[i];
		}
		for (int i = n; i < k; i++) {
			cout << pr[0];
		}
		return 0;
	}
	vector<char> ak;
	int g = 1e9;
	if (cmp(a, is))
		a = is;
	for (int i = 0; i < min(n,k); i++) {
		if (cm) {
			ak.push_back(pr[0]);
		}
		else {
			char c = a[i];
			for (int j = 0; j < pr.size(); j++) {
				if (pr[j] >= c) {
					if (j == pr.size() - 1 && i == k - 1 && pr[j] <= is[i]) {
						int k = i;
						while (a[k] == pr[pr.size() - 1])
							k--;
						int m = 0;
						while (pr[m] <= a[k])
							m++;
						ak[k] = pr[m];
						cm = true;
						g = k;
						break;
					}
					if (i == k - 1 && pr[j] <= is[i]) continue;
					ak.push_back(pr[j]);
					if (pr[j]>is[i])
								cm = true;
					break;
				}
			}
		}
	}
	for (int i = 0; i < min(n, k);i++) {
		if (i > g)
			cout << pr[0];
		else
			cout << ak[i];
	}
	for (int i = n; i < k; i++) {
		cout << pr[0];
	}

}


//glory glory man utd <3
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
int n,t;
string s;
set<char> s1;

int main(){
	//ios_base::sync_with_stdio(false);
	// 	cin.tie(NULL);
	//freopen("input.txt","r",stdin);
	// freopen("output.txt","w",stdout);
	// int t;scanf("%d",&t);
	// while(t--){
	cin>>n>>t;
	getline(cin,s);getline(cin,s);
	for(int i=0;i<n;i++){
		s1.insert(s[i]);
	}
	if(t>n){
		string out=s;
		string sorted=s;
		sort(sorted.begin(),sorted.end());
		for(int i=0;i<t-n;i++){
			out+=sorted[0];
		}
		cout<<out;
	}else{
		string sorted=s;
		if(t<n){
			s=s.substr(0,t);
		}

		string out;
		sort(sorted.begin(),sorted.end());
		int i=t-1;
		for(;i>=0;i--){
			auto x=upper_bound(sorted.begin(),sorted.end(),s[i]);
			if(x==sorted.end()){
				i--;
				while(upper_bound(sorted.begin(),sorted.end(),s[i])==sorted.end()&&i>0){
					i--;
				}
				auto y=upper_bound(sorted.begin(),sorted.end(),s[i]);
				out+=*y;
				break;
			}
		}
		if(i==-1) {
			i=s.size()-1;
			auto y=upper_bound(sorted.begin(),sorted.end(),s[i]);
			out+=*y;
			i--;
			for(int j=0;j<s.size()-1;j++){
				out+=s[j];
			}
			i=t;
		}
		else{
			for(int j=0;j<i;j++){
				out+=s[j];
			}
		}
		reverse(out.begin(),out.end());
		for(int j=i+1;j<t;j++){
			out+=sorted[0];
		}
		reverse(out.begin(),out.end());
		cout<<out;
	}

	return 0;
}


//glory glory man utd <3
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
int n,t;
string s;
set<char> s1;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	//freopen("input.txt","r",stdin);
	// freopen("output.txt","w",stdout);
	// int t;scanf("%d",&t);
	// while(t--){
	cin>>n>>t;
	getline(cin,s);getline(cin,s);
	for(int i=0;i<n;i++){
		s1.insert(s[i]);
	}
	if(t>n){
		string out=s;
		string sorted=s;
		sort(sorted.begin(),sorted.end());
		for(int i=0;i<t-n;i++){
			out+=sorted[0];
		}
		cout<<out;
	}else{
		string sorted=s;
		s=s.substr(0,t);
		string out;
		sort(sorted.begin(),sorted.end());
		int i=t-1;
		bool f=0;
		for(;i>=0;i--){
			auto x=upper_bound(sorted.begin(),sorted.end(),s[i]);
			if(x==sorted.end()){
				f=1;
			}else{
				out+=*x;
					break;
				//}
			}
		}
		for(int j=0;j<i;j++){
			out=s[j]+out;
		}
		//reverse(out.begin(),out.end());
		for(int j=0;j<t-i-1;j++){
			out+=sorted[0];
		}
		cout<<out;
	}

	return 0;
}


//glory glory man utd <3
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
int n,t;
string s;
set<char> s1;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	//freopen("input.txt","r",stdin);
	// freopen("output.txt","w",stdout);
	// int t;scanf("%d",&t);
	// while(t--){
	cin>>n>>t;
	getline(cin,s);getline(cin,s);
	for(int i=0;i<n;i++){
		s1.insert(s[i]);
	}
	if(t>n){
		string out=s;
		string sorted=s;
		sort(sorted.begin(),sorted.end());
		for(int i=0;i<t-n;i++){
			out+=sorted[0];
		}
		cout<<out;
	}else{
		string sorted=s;
		s=s.substr(0,t);
		string out=s;
		sort(sorted.begin(),sorted.end());
		int i=t-1;
		bool f=0;
		for(;i>=0;i--){

			auto x=upper_bound(sorted.begin(),sorted.end(),s[i]);
			out.pop_back();
			if(x==sorted.end()){
				f=1;
			}else{
				out+=*x;
					break;
				//}
			}
		}

		//reverse(out.begin(),out.end());
		for(int j=0;j<t-i-1;j++){
			out+=sorted[0];
		}
		cout<<out;
	}

	return 0;
}


//glory glory man utd <3
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
int n,t;
string s;
set<char> s1;

int main(){
	//ios_base::sync_with_stdio(false);
	// 	cin.tie(NULL);
	//freopen("input.txt","r",stdin);
	// freopen("output.txt","w",stdout);
	// int t;scanf("%d",&t);
	// while(t--){
	cin>>n>>t;
	getline(cin,s);getline(cin,s);
	for(int i=0;i<n;i++){
		s1.insert(s[i]);
	}
	if(t>n){
		string out=s;
		string sorted=s;
		sort(sorted.begin(),sorted.end());
		for(int i=0;i<t-n;i++){
			out+=sorted[0];
		}
		cout<<out;
	}else{
		string sorted=s;
		if(t<n){
			s=s.substr(0,t);
		}

		string out;
		sort(sorted.begin(),sorted.end());
		int i=t-1;
		for(;i>=0;i--){
			auto x=upper_bound(sorted.begin(),sorted.end(),s[i]);
			if(x==sorted.end()){
				i--;
				while(upper_bound(sorted.begin(),sorted.end(),s[i])==sorted.end()&&i>0){
					i--;
				}
				auto y=upper_bound(sorted.begin(),sorted.end(),s[i]);
				out+=*y;
				break;
			}
		}
		if(i==-1) {
			i=s.size()-1;
			auto y=upper_bound(sorted.begin(),sorted.end(),s[i]);
			out+=*y;
			i--;
			for(int j=0;j<s.size()-1;j++){
				out+=s[j];
			}
			i=t;
		}
		else{
			for(int j=0;j<i;j++){
				out+=s[j];
			}
			for(int j=i+1;j<t;j++){
				out+=sorted[0];
			}
		}
		reverse(out.begin(),out.end());

		cout<<out;
	}

	return 0;
}


//glory glory man utd <3
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
int n,t;
string s;
set<char> s1;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	//freopen("input.txt","r",stdin);
	// freopen("output.txt","w",stdout);
	// int t;scanf("%d",&t);
	// while(t--){
	cin>>n>>t;
	getline(cin,s);getline(cin,s);
	for(int i=0;i<n;i++){
		s1.insert(s[i]);
	}
	if(t>n){
		string out=s;
		string sorted=s;
		sort(sorted.begin(),sorted.end());
		for(int i=0;i<t-n;i++){
			out+=sorted[0];
		}
		cout<<out;
	}else{
		string sorted=s;
		s=s.substr(0,t);
		string out;
		sort(sorted.begin(),sorted.end());
		int i=t-1;
		bool f=0;
		for(;i>=0;i--){
			auto x=upper_bound(sorted.begin(),sorted.end(),s[i]);
			if(x==sorted.end()){
				f=1;
			}else{
				out+=*x;
					break;
				//}
			}
		}
		for(int j=0;j<i;j++){
			out+=s[j];
		}
		reverse(out.begin(),out.end());
		for(int j=0;j<t-i-1;j++){
			out+=sorted[0];
		}
		cout<<out;
	}

	return 0;
}


//glory glory man utd <3
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
int n,t;
string s;
set<char> s1;

int main(){
	//ios_base::sync_with_stdio(false);
	// 	cin.tie(NULL);
	//freopen("input.txt","r",stdin);
	// freopen("output.txt","w",stdout);
	// int t;scanf("%d",&t);
	// while(t--){
	cin>>n>>t;
	getline(cin,s);getline(cin,s);
	for(int i=0;i<n;i++){
		s1.insert(s[i]);
	}
	if(t>n){
		string out=s;
		string sorted=s;
		sort(sorted.begin(),sorted.end());
		for(int i=0;i<t-n;i++){
			out+=sorted[0];
		}
		cout<<out;
	}else{
		string sorted=s;
		if(t<n){
			s=s.substr(0,t);
		}

		string out;
		sort(sorted.begin(),sorted.end());
		int i=t-1;
		for(;i>=0;i--){
			auto x=upper_bound(sorted.begin(),sorted.end(),s[i]);
			if(x==sorted.end()){
				i--;
				while(upper_bound(sorted.begin(),sorted.end(),s[i])==sorted.end()&&i>0){
					i--;
				}
				auto y=upper_bound(sorted.begin(),sorted.end(),s[i]);
				out+=*y;
				break;
			}
		}
		//cout<<out<<endl;
		if(i==-1) {
			i=s.size()-1;
			auto y=upper_bound(sorted.begin(),sorted.end(),s[i]);
			out+=*y;
			i--;
			for(int j=0;j<s.size()-1;j++){
				out+=s[j];
			}
			i=t;
			reverse(out.begin(),out.end());
		}
		else{
			for(int j=0;j<i;j++){
				out+=s[j];
			}
			reverse(out.begin(),out.end());
			//cout<<out<<endl;
			for(int j=i+1;j<t;j++){
				out+=sorted[0];
			}
		}

		cout<<out;
	}

	return 0;
}


//glory glory man utd <3
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
int n,t;
string s;
set<char> s1;

int main(){
	//ios_base::sync_with_stdio(false);
	// 	cin.tie(NULL);
	//freopen("input.txt","r",stdin);
	// freopen("output.txt","w",stdout);
	// int t;scanf("%d",&t);
	// while(t--){
	cin>>n>>t;
	getline(cin,s);getline(cin,s);
	for(int i=0;i<n;i++){
		s1.insert(s[i]);
	}
	if(t>n){
		string out=s;
		string sorted=s;
		sort(sorted.begin(),sorted.end());
		for(int i=0;i<t-n;i++){
			out+=sorted[0];
		}
		cout<<out;
	}else{
		string sorted=s;
		if(t<n){
			s=s.substr(0,t);
		}

		string out;
		sort(sorted.begin(),sorted.end());
		int i=t-1;
		for(;i>=0;i--){
			auto x=upper_bound(sorted.begin(),sorted.end(),s[i]);
			if(x==sorted.end()){
				i--;
				while(upper_bound(sorted.begin(),sorted.end(),s[i])==sorted.end()&&i>0){
					i--;
				}
				auto y=upper_bound(sorted.begin(),sorted.end(),s[i]);
				out+=*y;
				break;
			}
		}
		if(i==-1) {
			i=s.size()-1;
			auto y=upper_bound(sorted.begin(),sorted.end(),s[i]);
			out+=*y;
			i--;
			for(int j=0;j<s.size()-1;j++){
				out+=s[j];
			}
			i=t;
		}
		else{
			for(int j=0;j<i;j++){
				out+=s[j];
			}
			reverse(out.begin(),out.end());
			for(int j=i+1;j<t;j++){
				out+=sorted[0];
			}
		}
		reverse(out.begin(),out.end());

		cout<<out;
	}

	return 0;
}


//glory glory man utd <3
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
int n,t;
string s;
set<char> s1;

int main(){
	//ios_base::sync_with_stdio(false);
	// 	cin.tie(NULL);
	//freopen("input.txt","r",stdin);
	// freopen("output.txt","w",stdout);
	// int t;scanf("%d",&t);
	// while(t--){
	cin>>n>>t;
	getline(cin,s);getline(cin,s);
	for(int i=0;i<n;i++){
		s1.insert(s[i]);
	}
	if(t>n){
		string out=s;
		string sorted=s;
		sort(sorted.begin(),sorted.end());
		for(int i=0;i<t-n;i++){
			out+=sorted[0];
		}
		cout<<out;
	}else{
		string sorted=s;
		if(t<n){
			s=s.substr(0,t);
		}

		string out;
		sort(sorted.begin(),sorted.end());
		int i=t-1;
		for(;i>=0;i--){
			auto x=upper_bound(sorted.begin(),sorted.end(),s[i]);
			if(x==sorted.end()){
				i--;
				while(upper_bound(sorted.begin(),sorted.end(),s[i])==sorted.end()&&i>0){
					i--;
				}
				auto y=upper_bound(sorted.begin(),sorted.end(),s[i]);
				out+=*y;
				break;
			}
		}
		if(i==-1) {
			i=s.size()-1;
			auto y=upper_bound(sorted.begin(),sorted.end(),s[i]);
			out+=*y;
			i--;
			for(int j=0;j<s.size()-1;j++){
				out+=s[j];
			}
			i=t;
		}
		else{
			for(int j=0;j<i;j++){
				out+=s[j];
			}
		}
		reverse(out.begin(),out.end());
		for(int j=i+1;j<t;j++){
			out+=sorted[0];
		}
		cout<<out;
	}

	return 0;
}


// by. MiohitoKiri5474
#include<bits/stdc++.h>

#pragma GCC optimize ( "O3" )
#pragma loop_opt ( on )

using namespace std;

typedef long long LL;

// define tools
#define REPP(i,f,s) for ( int i = f ; i < s ; i++ )
#define REPM(i,f,s) for ( int i = f ; i >= s ; i-- )
#define REPALL(i,n) for ( auto &i: n )
#define debuger cout << "111\n"
#define MEM(n,i) memset ( n, i, sizeof n )

// define pair
typedef pair < LL, LL > pll;
typedef pair < int, int > pii;
#define F first
#define S second
#define mp make_pair

// define vector && some stl's api
template < class T > using vec = vector < T >;
typedef vec < int > vi;
typedef vec < LL > vl;
#define pb push_back
#define ep emplace_back
#define REV reverse
#define SZ(n) ( int ) n.size()
#define CLR(n) n.clear()
#define BEG(n) n.begin()
#define END(n) n.end()
#define EMP(n) n.empty()
#define RSZ(n,s) n.resize ( s )
#define ALL(n) BEG ( n ), END ( n )
#define PIO(n) REPALL ( i, n ) cout << i << ' '; cout << '\n'
#define GETDATA(data,n) RSZ ( data, n ); REPALL ( i, data ) cin >> i

// define set
typedef set < int > si;
typedef set < LL > sl;
#define FID(n,Index) ( n.find ( Index ) != n.end() )

// graph
#define GRE(T,edge) vec < T > edge[maxN]
#define UNI(u,v,edge) edge[u].pb ( v ), edge[v].pb ( u )
#define UNIw(u,v,w,edge) edge[u].pb ( mp ( v, w ) ), edge[v].pb ( mp ( u, w ) )

// IO
#define GL(n) getline ( cin, n )

// define stack, queue, pri-queue
template < class T > using stack = stack < T, vec < T > >;
template < class T > using MaxHeap = priority_queue < T, vec < T >, less < T > >;
template < class T > using MinHeap = priority_queue < T, vec < T >, greater < T > >;

// define stringstream
#define sstr stringstream

// number~ remember change maxN
#define INF 0x3f3f3f3f
#define maxN 100005

// ready~ go!
// let's coding and have fun!
// I can solve this problem!

int main(){
	ios::sync_with_stdio ( false );
	cin.tie ( 0 );
	cout.tie ( 0 );

	int n, len;
	string str;
	set < char > can;
	set < string > lib, tmp;
	cin >> n >> len >> str;

	REPALL ( i, str ) can.insert ( i );
	if ( SZ ( str ) > len ){
		while ( SZ ( str ) != len )
			str += *BEG ( can );
		cout << str << '\n';
		return 0;
	}
	str[SZ ( str ) - 1]++;
	lib.insert ( "" );
	while ( len-- ){
		REPALL ( i, lib ) REPALL ( j, can ) tmp.insert ( i + j );

		CLR ( lib );
		swap ( lib, tmp );
	}

	cout << *lower_bound ( ALL ( lib ), str )<< '\n';
}


// by. MiohitoKiri5474
#include<bits/stdc++.h>

#pragma GCC optimize ( "O3" )
#pragma loop_opt ( on )

using namespace std;

typedef long long LL;

// define tools
#define REPP(i,f,s) for ( int i = f ; i < s ; i++ )
#define REPM(i,f,s) for ( int i = f ; i >= s ; i-- )
#define REPALL(i,n) for ( auto &i: n )
#define debuger cout << "111\n"
#define MEM(n,i) memset ( n, i, sizeof n )

// define pair
typedef pair < LL, LL > pll;
typedef pair < int, int > pii;
#define F first
#define S second
#define mp make_pair

// define vector && some stl's api
template < class T > using vec = vector < T >;
typedef vec < int > vi;
typedef vec < LL > vl;
#define pb push_back
#define ep emplace_back
#define REV reverse
#define SZ(n) ( int ) n.size()
#define CLR(n) n.clear()
#define BEG(n) n.begin()
#define END(n) n.end()
#define EMP(n) n.empty()
#define RSZ(n,s) n.resize ( s )
#define ALL(n) BEG ( n ), END ( n )
#define PIO(n) REPALL ( i, n ) cout << i << ' '; cout << '\n'
#define GETDATA(data,n) RSZ ( data, n ); REPALL ( i, data ) cin >> i

// define set
typedef set < int > si;
typedef set < LL > sl;
#define FID(n,Index) ( n.find ( Index ) != n.end() )

// graph
#define GRE(T,edge) vec < T > edge[maxN]
#define UNI(u,v,edge) edge[u].pb ( v ), edge[v].pb ( u )
#define UNIw(u,v,w,edge) edge[u].pb ( mp ( v, w ) ), edge[v].pb ( mp ( u, w ) )

// IO
#define GL(n) getline ( cin, n )

// define stack, queue, pri-queue
template < class T > using stack = stack < T, vec < T > >;
template < class T > using MaxHeap = priority_queue < T, vec < T >, less < T > >;
template < class T > using MinHeap = priority_queue < T, vec < T >, greater < T > >;

// define stringstream
#define sstr stringstream

// number~ remember change maxN
#define INF 0x3f3f3f3f
#define maxN 100005

// ready~ go!
// let's coding and have fun!
// I can solve this problem!

inline bool cmp ( string a, string b ){
	int ma = max ( SZ ( a ), SZ ( b ) );
	for ( int i = 0 ; i < ma ; i++ ){
		if ( a[i] == b[i] )
			continue;
		return a[i] < b[i];
	}

	return SZ ( a ) == ma ? false : true;
}

int main(){
	ios::sync_with_stdio ( false );
	cin.tie ( 0 );
	cout.tie ( 0 );

	int n, len;
	string str;
	set < char > can;
	set < string > lib, tmp;
	cin >> n >> len >> str;
	REPALL ( i, str ) can.insert ( i );
	lib.insert ( "" );
	if ( SZ ( str ) >= len )
		str[SZ ( str ) - 1]++;
	while ( len-- ){
		REPALL ( i, lib ) REPALL ( j, can ) tmp.insert ( i + j );

		CLR ( lib );
		swap ( lib, tmp );
	}

	cout << *lower_bound ( ALL ( lib ), str )<< '\n';
}


// by. MiohitoKiri5474
#include<bits/stdc++.h>

#pragma GCC optimize ( "O3" )
#pragma loop_opt ( on )

using namespace std;

typedef long long LL;

// define tools
#define REPP(i,f,s) for ( int i = f ; i < s ; i++ )
#define REPM(i,f,s) for ( int i = f ; i >= s ; i-- )
#define REPALL(i,n) for ( auto &i: n )
#define debuger cout << "111\n"
#define MEM(n,i) memset ( n, i, sizeof n )

// define pair
typedef pair < LL, LL > pll;
typedef pair < int, int > pii;
#define F first
#define S second
#define mp make_pair

// define vector && some stl's api
template < class T > using vec = vector < T >;
typedef vec < int > vi;
typedef vec < LL > vl;
#define pb push_back
#define ep emplace_back
#define REV reverse
#define SZ(n) ( int ) n.size()
#define CLR(n) n.clear()
#define BEG(n) n.begin()
#define END(n) n.end()
#define EMP(n) n.empty()
#define RSZ(n,s) n.resize ( s )
#define ALL(n) BEG ( n ), END ( n )
#define PIO(n) REPALL ( i, n ) cout << i << ' '; cout << '\n'
#define GETDATA(data,n) RSZ ( data, n ); REPALL ( i, data ) cin >> i

// define set
typedef set < int > si;
typedef set < LL > sl;
#define FID(n,Index) ( n.find ( Index ) != n.end() )

// graph
#define GRE(T,edge) vec < T > edge[maxN]
#define UNI(u,v,edge) edge[u].pb ( v ), edge[v].pb ( u )
#define UNIw(u,v,w,edge) edge[u].pb ( mp ( v, w ) ), edge[v].pb ( mp ( u, w ) )

// IO
#define GL(n) getline ( cin, n )

// define stack, queue, pri-queue
template < class T > using stack = stack < T, vec < T > >;
template < class T > using MaxHeap = priority_queue < T, vec < T >, less < T > >;
template < class T > using MinHeap = priority_queue < T, vec < T >, greater < T > >;

// define stringstream
#define sstr stringstream

// number~ remember change maxN
#define INF 0x3f3f3f3f
#define maxN 100005

// ready~ go!
// let's coding and have fun!
// I can solve this problem!

int main(){
	ios::sync_with_stdio ( false );
	cin.tie ( 0 );
	cout.tie ( 0 );

	int n, len;
	string str, ans;
	set < char > can;
	cin >> n >> len >> str;

	REPALL ( i, str ) can.insert ( i );
	if ( SZ ( str ) < len ){
		cout << str;
		REPP ( i, SZ ( str ), len ) cout << *BEG ( can );
		cout << '\n';
		return 0;
	}
	if ( SZ ( str ) == len ){
		ans = str;
		int idx;
		for ( idx = n - 1 ; idx >= 0 ; idx-- ){
			if ( ans[idx] != *can.rbegin() )
				break;
		}

		ans[idx]++;
		ans[idx] = *lower_bound ( ALL ( can ), ans[idx] );
		for ( int i = idx + 1 ; i < n ; i++ )
			ans[i] = *BEG ( can );

		cout << ans << '\n';
		return 0;
	}

	// SZ ( str ) > len
	len--;
	if ( str[len] == *can.rbegin() ){
		len--;
		REPP ( i, 0, len ) cout << str[i];
		cout << *lower_bound ( ALL ( can ), str[len + 1] ) << *BEG ( can ) << '\n';

		return 0;
	}
	REPP ( i, 0, len ) cout << str[i];
	cout << *lower_bound ( ALL ( can ), str[len + 1] ) << '\n';
}


// by. MiohitoKiri5474
#include<bits/stdc++.h>

#pragma GCC optimize ( "O3" )
#pragma loop_opt ( on )

using namespace std;

typedef long long LL;

// define tools
#define REPP(i,f,s) for ( int i = f ; i < s ; i++ )
#define REPM(i,f,s) for ( int i = f ; i >= s ; i-- )
#define REPALL(i,n) for ( auto &i: n )
#define debuger cout << "111\n"
#define MEM(n,i) memset ( n, i, sizeof n )

// define pair
typedef pair < LL, LL > pll;
typedef pair < int, int > pii;
#define F first
#define S second
#define mp make_pair

// define vector && some stl's api
template < class T > using vec = vector < T >;
typedef vec < int > vi;
typedef vec < LL > vl;
#define pb push_back
#define ep emplace_back
#define REV reverse
#define SZ(n) ( int ) n.size()
#define CLR(n) n.clear()
#define BEG(n) n.begin()
#define END(n) n.end()
#define EMP(n) n.empty()
#define RSZ(n,s) n.resize ( s )
#define ALL(n) BEG ( n ), END ( n )
#define PIO(n) REPALL ( i, n ) cout << i << ' '; cout << '\n'
#define GETDATA(data,n) RSZ ( data, n ); REPALL ( i, data ) cin >> i

// define set
typedef set < int > si;
typedef set < LL > sl;
#define FID(n,Index) ( n.find ( Index ) != n.end() )

// graph
#define GRE(T,edge) vec < T > edge[maxN]
#define UNI(u,v,edge) edge[u].pb ( v ), edge[v].pb ( u )
#define UNIw(u,v,w,edge) edge[u].pb ( mp ( v, w ) ), edge[v].pb ( mp ( u, w ) )

// IO
#define GL(n) getline ( cin, n )

// define stack, queue, pri-queue
template < class T > using stack = stack < T, vec < T > >;
template < class T > using MaxHeap = priority_queue < T, vec < T >, less < T > >;
template < class T > using MinHeap = priority_queue < T, vec < T >, greater < T > >;

// define stringstream
#define sstr stringstream

// number~ remember change maxN
#define INF 0x3f3f3f3f
#define maxN 100005

// ready~ go!
// let's coding and have fun!
// I can solve this problem!

int main(){
	ios::sync_with_stdio ( false );
	cin.tie ( 0 );
	cout.tie ( 0 );

	int n, len, w;
	string str, ans;
	set < char > can;
	cin >> n >> len >> str;

	REPALL ( i, str ) can.insert ( i );
	if ( SZ ( str ) < len ){
		cout << str;
		REPP ( i, SZ ( str ), len ) cout << *BEG ( can );
		cout << '\n';
		return 0;
	}
	if ( SZ ( str ) == len ){
		ans = str;
		int idx;
		for ( idx = n - 1 ; idx >= 0 ; idx-- ){
			if ( ans[idx] != *can.rbegin() )
				break;
		}

		ans[idx]++;
		ans[idx] = *lower_bound ( ALL ( can ), ans[idx] );
		for ( int i = idx + 1 ; i < n ; i++ )
			ans[i] = *BEG ( can );

		cout << ans << '\n';
		return 0;
	}

	// SZ ( str ) > len
	w = len - 1;
	while ( str[w] == *can.rbegin() )
		w--;
	REPP ( i, 0, w ) cout << str[i];
	str[w]++;
	cout << *lower_bound ( ALL ( can ), str[w++] );
	REPP ( i, w, len ) cout << *BEG ( can );
	cout << '\n';
}


// by. MiohitoKiri5474
#include<bits/stdc++.h>

#pragma GCC optimize ( "O3" )
#pragma loop_opt ( on )

using namespace std;

typedef long long LL;

// define tools
#define REPP(i,f,s) for ( int i = f ; i < s ; i++ )
#define REPM(i,f,s) for ( int i = f ; i >= s ; i-- )
#define REPALL(i,n) for ( auto &i: n )
#define debuger cout << "111\n"
#define MEM(n,i) memset ( n, i, sizeof n )

// define pair
typedef pair < LL, LL > pll;
typedef pair < int, int > pii;
#define F first
#define S second
#define mp make_pair

// define vector && some stl's api
template < class T > using vec = vector < T >;
typedef vec < int > vi;
typedef vec < LL > vl;
#define pb push_back
#define ep emplace_back
#define REV reverse
#define SZ(n) ( int ) n.size()
#define CLR(n) n.clear()
#define BEG(n) n.begin()
#define END(n) n.end()
#define EMP(n) n.empty()
#define RSZ(n,s) n.resize ( s )
#define ALL(n) BEG ( n ), END ( n )
#define PIO(n) REPALL ( i, n ) cout << i << ' '; cout << '\n'
#define GETDATA(data,n) RSZ ( data, n ); REPALL ( i, data ) cin >> i

// define set
typedef set < int > si;
typedef set < LL > sl;
#define FID(n,Index) ( n.find ( Index ) != n.end() )

// graph
#define GRE(T,edge) vec < T > edge[maxN]
#define UNI(u,v,edge) edge[u].pb ( v ), edge[v].pb ( u )
#define UNIw(u,v,w,edge) edge[u].pb ( mp ( v, w ) ), edge[v].pb ( mp ( u, w ) )

// IO
#define GL(n) getline ( cin, n )

// define stack, queue, pri-queue
template < class T > using stack = stack < T, vec < T > >;
template < class T > using MaxHeap = priority_queue < T, vec < T >, less < T > >;
template < class T > using MinHeap = priority_queue < T, vec < T >, greater < T > >;

// define stringstream
#define sstr stringstream

// number~ remember change maxN
#define INF 0x3f3f3f3f
#define maxN 100005

// ready~ go!
// let's coding and have fun!
// I can solve this problem!

int main(){
	ios::sync_with_stdio ( false );
	cin.tie ( 0 );
	cout.tie ( 0 );

	int n, len, w;
	string str, ans;
	set < char > can;
	cin >> n >> len >> str;

	REPALL ( i, str ) can.insert ( i );
	if ( SZ ( str ) < len ){
		cout << str;
		REPP ( i, SZ ( str ), len ) cout << *BEG ( can );
		cout << '\n';
		return 0;
	}
	if ( SZ ( str ) == len ){
		ans = str;
		int idx;
		for ( idx = n - 1 ; idx >= 0 ; idx-- ){
			if ( ans[idx] != *can.rbegin() )
				break;
		}

		ans[idx]++;
		ans[idx] = *lower_bound ( ALL ( can ), ans[idx] );
		for ( int i = idx + 1 ; i < n ; i++ )
			ans[i] = *BEG ( can );

		cout << ans << '\n';
		return 0;
	}

	// SZ ( str ) > len
	w = len - 1;
	while ( str[w] == *can.rbegin() )
		w--;
	REPP ( i, 0, w ) cout << str[i];
	cout << *lower_bound ( ALL ( can ), str[++w] );
	REPP ( i, w, len ) cout << *BEG ( can );
	cout << '\n';
}


// by. MiohitoKiri5474
#include<bits/stdc++.h>

#pragma GCC optimize ( "O3" )
#pragma loop_opt ( on )

using namespace std;

typedef long long LL;

// define tools
#define REPP(i,f,s) for ( int i = f ; i < s ; i++ )
#define REPM(i,f,s) for ( int i = f ; i >= s ; i-- )
#define REPALL(i,n) for ( auto &i: n )
#define debuger cout << "111\n"
#define MEM(n,i) memset ( n, i, sizeof n )

// define pair
typedef pair < LL, LL > pll;
typedef pair < int, int > pii;
#define F first
#define S second
#define mp make_pair

// define vector && some stl's api
template < class T > using vec = vector < T >;
typedef vec < int > vi;
typedef vec < LL > vl;
#define pb push_back
#define ep emplace_back
#define REV reverse
#define SZ(n) ( int ) n.size()
#define CLR(n) n.clear()
#define BEG(n) n.begin()
#define END(n) n.end()
#define EMP(n) n.empty()
#define RSZ(n,s) n.resize ( s )
#define ALL(n) BEG ( n ), END ( n )
#define PIO(n) REPALL ( i, n ) cout << i << ' '; cout << '\n'
#define GETDATA(data,n) RSZ ( data, n ); REPALL ( i, data ) cin >> i

// define set
typedef set < int > si;
typedef set < LL > sl;
#define FID(n,Index) ( n.find ( Index ) != n.end() )

// graph
#define GRE(T,edge) vec < T > edge[maxN]
#define UNI(u,v,edge) edge[u].pb ( v ), edge[v].pb ( u )
#define UNIw(u,v,w,edge) edge[u].pb ( mp ( v, w ) ), edge[v].pb ( mp ( u, w ) )

// IO
#define GL(n) getline ( cin, n )

// define stack, queue, pri-queue
template < class T > using stack = stack < T, vec < T > >;
template < class T > using MaxHeap = priority_queue < T, vec < T >, less < T > >;
template < class T > using MinHeap = priority_queue < T, vec < T >, greater < T > >;

// define stringstream
#define sstr stringstream

// number~ remember change maxN
#define INF 0x3f3f3f3f
#define maxN 100005

// ready~ go!
// let's coding and have fun!
// I can solve this problem!

int main(){
	ios::sync_with_stdio ( false );
	cin.tie ( 0 );
	cout.tie ( 0 );

	int n, len;
	string str;
	set < char > can;
	set < string > lib, tmp;
	cin >> n >> len >> str;

	REPALL ( i, str ) can.insert ( i );
	if ( SZ ( str ) < len ){
		while ( SZ ( str ) != len )
			str += *BEG ( can );
		cout << str << '\n';
		return 0;
	}
	str[SZ ( str ) - 1]++;
	lib.insert ( "" );
	while ( len-- ){
		REPALL ( i, lib ) REPALL ( j, can ) tmp.insert ( i + j );

		CLR ( lib );
		swap ( lib, tmp );
	}

	cout << *lower_bound ( ALL ( lib ), str )<< '\n';
}


// by. MiohitoKiri5474
#include<bits/stdc++.h>

#pragma GCC optimize ( "O3" )
#pragma loop_opt ( on )

using namespace std;

typedef long long LL;

// define tools
#define REPP(i,f,s) for ( int i = f ; i < s ; i++ )
#define REPM(i,f,s) for ( int i = f ; i >= s ; i-- )
#define REPALL(i,n) for ( auto &i: n )
#define debuger cout << "111\n"
#define MEM(n,i) memset ( n, i, sizeof n )

// define pair
typedef pair < LL, LL > pll;
typedef pair < int, int > pii;
#define F first
#define S second
#define mp make_pair

// define vector && some stl's api
template < class T > using vec = vector < T >;
typedef vec < int > vi;
typedef vec < LL > vl;
#define pb push_back
#define ep emplace_back
#define REV reverse
#define SZ(n) ( int ) n.size()
#define CLR(n) n.clear()
#define BEG(n) n.begin()
#define END(n) n.end()
#define EMP(n) n.empty()
#define RSZ(n,s) n.resize ( s )
#define ALL(n) BEG ( n ), END ( n )
#define PIO(n) REPALL ( i, n ) cout << i << ' '; cout << '\n'
#define GETDATA(data,n) RSZ ( data, n ); REPALL ( i, data ) cin >> i

// define set
typedef set < int > si;
typedef set < LL > sl;
#define FID(n,Index) ( n.find ( Index ) != n.end() )

// graph
#define GRE(T,edge) vec < T > edge[maxN]
#define UNI(u,v,edge) edge[u].pb ( v ), edge[v].pb ( u )
#define UNIw(u,v,w,edge) edge[u].pb ( mp ( v, w ) ), edge[v].pb ( mp ( u, w ) )

// IO
#define GL(n) getline ( cin, n )

// define stack, queue, pri-queue
template < class T > using stack = stack < T, vec < T > >;
template < class T > using MaxHeap = priority_queue < T, vec < T >, less < T > >;
template < class T > using MinHeap = priority_queue < T, vec < T >, greater < T > >;

// define stringstream
#define sstr stringstream

// number~ remember change maxN
#define INF 0x3f3f3f3f
#define maxN 100005

// ready~ go!
// let's coding and have fun!
// I can solve this problem!

int main(){
	ios::sync_with_stdio ( false );
	cin.tie ( 0 );
	cout.tie ( 0 );

	int n, len;
	string str, ans;
	set < char > can;
	cin >> n >> len >> str;

	REPALL ( i, str ) can.insert ( i );
	if ( SZ ( str ) < len ){
		cout << str;
		REPP ( i, SZ ( str ), len ) cout << *BEG ( can );
		cout << '\n';
		return 0;
	}
	if ( SZ ( str ) == len ){
		ans = str;
		int idx;
		for ( idx = n - 1 ; idx >= 0 ; idx-- ){
			if ( ans[idx] != *can.rbegin() )
				break;
		}

		ans[idx]++;
		ans[idx] = *lower_bound ( ALL ( can ), ans[idx] );
		for ( int i = idx + 1 ; i < n ; i++ )
			ans[i] = *BEG ( can );

		cout << ans << '\n';
		return 0;
	}

	// SZ ( str ) > len
	len--;
	REPP ( i, 0, len ) cout << str[i];
	cout << *lower_bound ( ALL ( can ), str[len + 1] ) << '\n';
}


// by. MiohitoKiri5474
#include<bits/stdc++.h>

#pragma GCC optimize ( "O3" )
#pragma loop_opt ( on )

using namespace std;

typedef long long LL;

// define tools
#define REPP(i,f,s) for ( int i = f ; i < s ; i++ )
#define REPM(i,f,s) for ( int i = f ; i >= s ; i-- )
#define REPALL(i,n) for ( auto &i: n )
#define debuger cout << "111\n"
#define MEM(n,i) memset ( n, i, sizeof n )

// define pair
typedef pair < LL, LL > pll;
typedef pair < int, int > pii;
#define F first
#define S second
#define mp make_pair

// define vector && some stl's api
template < class T > using vec = vector < T >;
typedef vec < int > vi;
typedef vec < LL > vl;
#define pb push_back
#define ep emplace_back
#define REV reverse
#define SZ(n) ( int ) n.size()
#define CLR(n) n.clear()
#define BEG(n) n.begin()
#define END(n) n.end()
#define EMP(n) n.empty()
#define RSZ(n,s) n.resize ( s )
#define ALL(n) BEG ( n ), END ( n )
#define PIO(n) REPALL ( i, n ) cout << i << ' '; cout << '\n'
#define GETDATA(data,n) RSZ ( data, n ); REPALL ( i, data ) cin >> i

// define set
typedef set < int > si;
typedef set < LL > sl;
#define FID(n,Index) ( n.find ( Index ) != n.end() )

// graph
#define GRE(T,edge) vec < T > edge[maxN]
#define UNI(u,v,edge) edge[u].pb ( v ), edge[v].pb ( u )
#define UNIw(u,v,w,edge) edge[u].pb ( mp ( v, w ) ), edge[v].pb ( mp ( u, w ) )

// IO
#define GL(n) getline ( cin, n )

// define stack, queue, pri-queue
template < class T > using stack = stack < T, vec < T > >;
template < class T > using MaxHeap = priority_queue < T, vec < T >, less < T > >;
template < class T > using MinHeap = priority_queue < T, vec < T >, greater < T > >;

// define stringstream
#define sstr stringstream

// number~ remember change maxN
#define INF 0x3f3f3f3f
#define maxN 100005

// ready~ go!
// let's coding and have fun!
// I can solve this problem!

int main(){
	ios::sync_with_stdio ( false );
	cin.tie ( 0 );
	cout.tie ( 0 );

	int n, len;
	string str;
	set < char > can;
	set < string > lib, tmp;
	cin >> n >> len >> str;

	REPALL ( i, str ) can.insert ( i );
	if ( SZ ( str ) >= len ){
		while ( SZ ( str ) != len )
			str += *BEG ( can );
		cout << str << '\n';
		return 0;
	}
	lib.insert ( "" );
	while ( len-- ){
		REPALL ( i, lib ) REPALL ( j, can ) tmp.insert ( i + j );

		CLR ( lib );
		swap ( lib, tmp );
	}

	cout << *lower_bound ( ALL ( lib ), str )<< '\n';
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    int t=1;
    //cin>>t;
    while(t--){
            int n=0,k=0;
            cin>>n>>k;
            string st;
            cin>>st;
            string cons="";
            vector<char> v;
            map<char,int> mp;
            for(int i=0;i<n;i++){
                if(mp[st[i]]==0){
                    mp[st[i]]=1;
                    v.push_back(st[i]);
                }
            }
            sort(v.begin(),v.end());
            int sz=v.size();
            if(k<n){
                int i=0;
                for(i=0;i<k-1;i++)
                    cons=cons+st[i];
                char m=st[i];
              //  cout<<"m="<<m<<endl;
                for(i=0;i<sz;i++)
                    if(v[i]==m)
                    break;
               // cout<<"i="<<i<<endl;
                cons=cons+v[i+1];

            }
            else if(k>n){
                cons=st;
                for(int i=n;i<k;i++)
                    cons=cons+v[0];
            }
            else{
                int i=0;
                for(i=n-1;i>=0;i--){
                    if(st[i]!=v[sz-1])
                        break;
                }
                //cout<<"i="<<i<<endl;
                char m=st[i];
                //cout<<"m="<<m<<endl;
                int j=0;
                for(j=0;j<sz;j++){
                    if(v[j]==m)
                        break;
                }
                m=v[j+1];
                //cout<<"m="<<m<<endl;
                int f=i;
                for(i=0;i<f;i++)
                    cons=cons+st[i];
                cons=cons+m;
                for(int i=f+1;i<n;i++)
                    cons=cons+v[0];
            }
            cout<<cons<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    int t=1;
    //cin>>t;
    while(t--){
            int n=0,k=0;
            cin>>n>>k;
            string st;
            cin>>st;
            string cons="";
            vector<char> v;
            map<char,int> mp;
            for(int i=0;i<n;i++){
                if(mp[st[i]]==0){
                    mp[st[i]]=1;
                    v.push_back(st[i]);
                }
            }
            sort(v.begin(),v.end());
            int sz=v.size();
            if(k<n){
                int i=0;
                for(i=0;i<k-1;i++)
                    cons=cons+st[i];
                char m=st[i];
                for(i=0;i<sz;i++)
                    if(v[i]==m)
                    break;
                if(i==sz-1){
                    cons="";
                    int j=0;
                    for(j=0;j<k-1;j++)
                        cons=cons+v[0];
                    m=st[0];
                    for(j=0;j<sz;i++)
                    if(v[j]==m)
                    break;
                    cons=v[j+1]+cons;
                }

            }
            else if(k>n){
                cons=st;
                for(int i=n;i<k;i++)
                    cons=cons+v[0];
            }
            else{
                int i=0;
                for(i=n-1;i>=0;i--){
                    if(st[i]!=v[sz-1])
                        break;
                }
                char m=st[i];
                int j=0;
                for(j=0;j<sz;j++){
                    if(v[j]==m)
                        break;
                }
                m=v[j+1];
                int f=i;
                for(i=0;i<f;i++)
                    cons=cons+st[i];
                cons=cons+m;
                for(int i=f+1;i<n;i++)
                    cons=cons+v[0];
            }
            cout<<cons<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    int t=1;
    //cin>>t;
    while(t--){
            int n=0,k=0;
            cin>>n>>k;
            string st;
            cin>>st;
            string cons="";
            vector<char> v;
            map<char,int> mp;
            for(int i=0;i<n;i++){
                if(mp[st[i]]==0){
                    mp[st[i]]=1;
                    v.push_back(st[i]);
                }
            }
            sort(v.begin(),v.end());
            int sz=v.size();
            if(k<n){
                int i=0;
                st=st.substr(0,k);
                i=0;n=k;
                for(i=n-1;i>=0;i--){
                    if(st[i]!=v[sz-1])
                        break;
                }
                char m=st[i];
                int j=0;
                for(j=0;j<sz;j++){
                    if(v[j]==m)
                        break;
                }
                m=v[j+1];
                int f=i;
                for(i=0;i<f;i++)
                    cons=cons+st[i];
                cons=cons+m;
                for(int i=f+1;i<n;i++)
                    cons=cons+v[0];

            }
            else if(k>n){
                cons=st;
                for(int i=n;i<k;i++)
                    cons=cons+v[0];
            }
            else{
                int i=0;
                for(i=n-1;i>=0;i--){
                    if(st[i]!=v[sz-1])
                        break;
                }
                char m=st[i];
                int j=0;
                for(j=0;j<sz;j++){
                    if(v[j]==m)
                        break;
                }
                m=v[j+1];
                int f=i;
                for(i=0;i<f;i++)
                    cons=cons+st[i];
                cons=cons+m;
                for(int i=f+1;i<n;i++)
                    cons=cons+v[0];
            }
            cout<<cons<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    int t=1;
    //cin>>t;
    while(t--){
            int n=0,k=0;
            cin>>n>>k;
            string st;
            cin>>st;
            string cons="";
            vector<char> v;
            map<char,int> mp;
            for(int i=0;i<n;i++){
                if(mp[st[i]]==0){
                    mp[st[i]]=1;
                    v.push_back(st[i]);
                }
            }
            sort(v.begin(),v.end());
            int sz=v.size();
            if(k<n){
                int i=0;
                for(i=0;i<k-1;i++)
                    cons=cons+st[i];
                char m=st[i];
                for(i=0;i<sz;i++)
                    if(v[i]==m)
                    break;
                if(i==sz-1){
                    cons="";
                    int j=0;
                    for(j=0;j<k-1;j++)
                        cons=cons+v[0];
                    m=st[0];
                    //cout<<"m="<<m<<endl;
                    for(j=0;j<sz;j++)
                    if(v[j]==m)
                    break;
                    //cout<<"hey"<<endl;
                    //cout<<"j="<<j<<endl;
                    cons=v[j+1]+cons;
                }
                else{
                    cons=cons+v[i+1];
                }
            }
            else if(k>n){
                cons=st;
                for(int i=n;i<k;i++)
                    cons=cons+v[0];
            }
            else{
                int i=0;
                for(i=n-1;i>=0;i--){
                    if(st[i]!=v[sz-1])
                        break;
                }
                char m=st[i];
                int j=0;
                for(j=0;j<sz;j++){
                    if(v[j]==m)
                        break;
                }
                m=v[j+1];
                int f=i;
                for(i=0;i<f;i++)
                    cons=cons+st[i];
                cons=cons+m;
                for(int i=f+1;i<n;i++)
                    cons=cons+v[0];
            }
            cout<<cons<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    int t=1;
    //cin>>t;
    while(t--){
            int n=0,k=0;
            cin>>n>>k;
            string st;
            cin>>st;
            string cons="";
            vector<char> v;
            map<char,int> mp;
            for(int i=0;i<n;i++){
                if(mp[st[i]]==0){
                    mp[st[i]]=1;
                    v.push_back(st[i]);
                }
            }
            sort(v.begin(),v.end());
            int sz=v.size();
            if(k<n){
                int i=0;
                for(i=0;i<k-1;i++)
                    cons=cons+st[i];
                char m=st[i];
                for(i=0;i<sz;i++)
                    if(v[i]==m)
                    break;
                if(i==sz-1){
                    cons="";
                    int j=0;
                    for(j=0;j<k-1;j++)
                        cons=cons+v[0];
                    m=st[0];
                    for(j=0;j<sz;i++)
                    if(v[j]==m)
                    break;
                    cons=v[j+1]+cons;
                }
                else{
                    cons=cons+v[i+1];
                }
            }
            else if(k>n){
                cons=st;
                for(int i=n;i<k;i++)
                    cons=cons+v[0];
            }
            else{
                int i=0;
                for(i=n-1;i>=0;i--){
                    if(st[i]!=v[sz-1])
                        break;
                }
                char m=st[i];
                int j=0;
                for(j=0;j<sz;j++){
                    if(v[j]==m)
                        break;
                }
                m=v[j+1];
                int f=i;
                for(i=0;i<f;i++)
                    cons=cons+st[i];
                cons=cons+m;
                for(int i=f+1;i<n;i++)
                    cons=cons+v[0];
            }
            cout<<cons<<endl;
    }
}


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

int a[26];
char s[110000],s1[110000];
int main()
{
    int n,k;
    scanf("%d %d",&n,&k);
    scanf("%s",s);
    strcpy(s1,s);
    sort(s1,s1+n);

    if(n<k)
    {
        printf("%s",s);
        for(int i=1;i<=k-n;i++)printf("%c",s1[0]);
    }
    else
    {
        for(int i=k-1;i>=0;i--)
        {
            int upper=upper_bound(s1,s1+n,s[i])-s1;
            if(i==k-1)
            {
                if(isalpha(s[upper])==true)
                {
                    for(int j=0;j<=i-1;j++)
                        printf("%c",s[j]);
                    printf("%c",s1[upper]);
                    break;
                }
            }
            else
            {
                if(isalpha(s[upper])==true)
                {
                    for(int j=0;j<=i-1;j++)
                        printf("%c",s[j]);

                    printf("%c",s1[upper_bound(s1,s1+n,s[i])-s1]);

                    for(int z=1;z<k-i;z++)printf("%c",s1[0]);
                    break;
                }
            }
        }
    }
    printf("\n");
}


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

bool A[27];
char s[110000];

int main()
{
    int n,k;
    scanf("%d %d",&n,&k);
    scanf("%s",s);

    for(int i=0;i<n;i++)
        A[s[i]-'a'+1]=true;

    if(k>n)
    {
        for(int i=1;i<=26;i++)
        {
            if(A[i]==true)
            {
                s[n]='a'+i-1;
                s[n+1]='\0';
                break;
            }
        }
    }
    else
    {
        bool flag=false;
        for(int j=k-1;j>=0;j--)
        {
            char c=s[j];
            int temp=c-'a'+1;
            for(int i=temp+1;i<=26;i++)
            {
                if(A[i]==true)
                {
                    s[j]='a'+i-1;
                    s[j+1]='\0';
                    flag=true;
                    break;
                }
            }
            if(flag==true)
            {
                for(int m=1;m<=26;m++)
                {
                    if(A[m]==true)
                    {
                        for(int l=j+1;l<=k-1;l++)
                            s[l]='a'+m-1;
                        s[k]='\0';
                        break;
                    }
                }
                break;
            }
        }
    }
    printf("%s\n",s);
}


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

bool A[27];
char s[11];

int main()
{
    int n,k;
    scanf("%d %d",&n,&k);
    scanf("%s",s);

    for(int i=0;i<n;i++)
        A[s[i]-'a'+1]=true;

    if(k>n)
    {
        for(int i=1;i<=26;i++)
        {
            if(A[i]==true)
            {
                s[n]='a'+i-1;
                s[n+1]='\0';
                break;
            }
        }
    }
    else
    {
        bool flag=false;
        for(int j=k-1;j>=0;j--)
        {
            char c=s[j-1];
            int temp=c-'a'+1;
            for(int i=temp+1;i<=26;i++)
            {
                if(A[i]==true)
                {
                    s[j-1]='a'+i-1;
                    s[j]='\0';
                    flag=true;
                    break;
                }
            }
            if(flag==true)
            {
                for(int m=1;m<=26;m++)
                {
                    if(A[m]==true)
                    {
                        for(int l=j;l<=k-1;l++)
                            s[l]='a'+m-1;
                        s[k]='\0';
                        break;
                    }
                }
                break;
            }
        }
    }
    printf("%s\n",s);
}


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

bool A[27];
char s[11];

int main()
{
    int n,k;
    scanf("%d %d",&n,&k);
    scanf("%s",s);

    for(int i=0;i<n;i++)
        A[s[i]-'a'+1]=true;

    if(k>n)
    {
        for(int i=1;i<=26;i++)
        {
            if(A[i]==true)
            {
                s[n]='a'+i-1;
                s[n+1]='\0';
                break;
            }
        }
    }
    else
    {
        bool flag=false;
        for(int j=k-1;j>=0;j--)
        {
            char c=s[j];
            int temp=c-'a'+1;
            for(int i=temp+1;i<=26;i++)
            {
                if(A[i]==true)
                {
                    s[j]='a'+i-1;
                    s[j+1]='\0';
                    flag=true;
                    break;
                }
            }
            if(flag==true)
            {
                for(int m=1;m<=26;m++)
                {
                    if(A[m]==true)
                    {
                        for(int l=j+1;l<=k-1;l++)
                            s[l]='a'+m-1;
                        s[k]='\0';
                        break;
                    }
                }
                break;
            }
        }
    }
    printf("%s\n",s);
}


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

bool A[27];
char s[110000];

int main()
{
    int n,k;
    scanf("%d %d",&n,&k);
    scanf("%s",s);

    for(int i=0;i<n;i++)
        A[s[i]-'a'+1]=true;

    if(k>n)
    {
        for(int i=1;i<=26;i++)
        {
            if(A[i]==true)
            {
                for(int j=n;j<=k-1;j++)
                    s[j]='a'+i-1;
                s[k]='\0';
                break;
            }
        }
    }
    else
    {
        bool flag=false;
        for(int j=k-1;j>=0;j--)
        {
            char c=s[j];
            int temp=c-'a'+1;
            for(int i=temp+1;i<=26;i++)
            {
                if(A[i]==true)
                {
                    s[j]='a'+i-1;
                    s[j+1]='\0';
                    flag=true;
                    break;
                }
            }
            if(flag==true)
            {
                for(int m=1;m<=26;m++)
                {
                    if(A[m]==true)
                    {
                        for(int l=j+1;l<=k-1;l++)
                            s[l]='a'+m-1;
                        s[k]='\0';
                        break;
                    }
                }
                break;
            }
        }
    }
    printf("%s\n",s);
}


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

int a[26];
char s[110000],s1[110000];
int main()
{
    int n,k;
    scanf("%d %d",&n,&k);
    scanf("%s",s);
    strcpy(s1,s);
    sort(s1,s1+n);

    if(n<k)
    {
        printf("%s",s);
        for(int i=1;i<=k-n;i++)printf("%c",s1[0]);
    }
    else
    {
        for(int i=k-1;i>=0;i--)
        {
            int upper=upper_bound(s1,s1+n,s[i])-s1;
            if(i==k-1)
            {
                if(isalpha(s[upper])==true)
                {
                    for(int j=0;j<=i-1;j++)
                        printf("%c",s[j]);
                    printf("%c",s1[upper]);
                    break;
                }
            }
            else
            {
                if(isalpha(s[upper])==true)
                {
                    for(int j=0;j<=i-1;j++)
                        printf("%c",s[j]);

                    printf("%c",s1[upper_bound(s1,s1+n,s[i])-s1]);

                    for(int z=1;z<k-i;z++)printf("%c",s1[0]);
                    break;
                }
            }
        }
    }
    printf("\n");
}


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

int a[26];
char s[110000],s1[110000];
int main()
{
    int n,k;
    scanf("%d %d",&n,&k);
    scanf("%s",s);
    strcpy(s1,s);
    sort(s1,s1+n);

    if(n<k)
    {
        printf("%s",s);
        for(int i=1;i<=k-n;i++)printf("%c",s1[0]);
    }
    else
    {
        for(int i=k-1;i>=0;i--)
        {
            int upper=upper_bound(s1,s1+n,s[i])-s1;
            if(i==k-1)
            {
                if(isalpha(s[upper])==true)
                {
                    for(int j=0;j<=i-1;j++)
                        printf("%c",s[j]);
                    printf("%c",s1[upper]);
                    break;
                }
            }
            else
            {
                if(isalpha(s[upper])==true)
                {
                    for(int j=0;j<=i-1;j++)
                        printf("%c",s[j]);

                    printf("%c",s1[upper_bound(s1,s1+n,s[i])-s1]);

                    for(int z=1;z<k-i;z++)printf("%c",s1[0]);
                    break;
                }
            }
        }
    }
    return 0;
}


#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define ios		ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;

int main()
{
	ios

	int n,k;
	cin>>n>>k;

	string s;
	cin>>s;

	int a[26]={0};

	for(int i=0;i<s.size();i++)
	{
		a[s[i]-'a']++;
	}
	char ch;
	char b[26],j=0;
	for(int i=0;i<=25;i++)
	{
		if(a[i]>0)
		{
			b[j]=char(i+97);
			j++;
		}
	}

	if(k>n)
	{
		cout<<s;
		for(int i=n;i<k;i++)
		{
			cout<<b[0];
		}
		return 0;
	}

	if(k<=n)
	{
		//cout<<b[0]<<" "<<b[j-1]<<endl;
		int flag=0;
		int t=min(n,k);
		char d[t];
		for(int i=t-1;i>=0;i--)
		{
			cout<<s[i]<<endl;
			if(s[i]!=b[j-1])
			{
				if(flag==0)
				{
					flag=1;
					for(int l=0;l<j;l++)
					{
						if(b[l]>s[i])
						{
							d[i]=b[l];
							break;
						}
					}
					//cout<<1<<endl;
				}
				else
				{
					d[i]=s[i];
					//cout<<2<<endl;
				}

			}
			if(s[i]==b[j-1])
			{
				if(flag==0)
				{
					d[i]=b[0];
					//cout<<3<<endl;
				}
				else
				{
					d[i]=s[i];
					//cout<<4<<endl;
				}

			}

		}
		for(int i=0;i<t;i++)
		cout<<d[i];
		return 0;
	}

}


#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define ios		ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;

int main()
{
	ios

	int n,k;
	cin>>n>>k;

	string s;
	cin>>s;

	int a[26]={0};

	for(int i=0;i<s.size();i++)
	{
		a[s[i]-'a']++;
	}
	char ch;
	for(int i=25;i>=0;i--)
	{
		if(a[i]>0)
		{
			ch=char(i+97);
			break;
		}
	}

	for(int i=0;i<k;i++)
	cout<<ch;

}


#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define ios		ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;

int main()
{
	ios

	int n,k;
	cin>>n>>k;

	string s;
	cin>>s;

	int a[26]={0};

	for(int i=0;i<s.size();i++)
	{
		a[s[i]-'a']++;
	}
	char ch;
	char b[26],j=0;
	for(int i=0;i<=25;i++)
	{
		if(a[i]>0)
		{
			b[j]=char(i+97);
			j++;
		}
	}

	if(k>n)
	{
		cout<<s;
		for(int i=n;i<k;i++)
		{
			cout<<b[0];
		}
		return 0;
	}

	if(k<=n)
	{
		//cout<<b[0]<<" "<<b[j-1]<<endl;
		int flag=0;
		int t=min(n,k);
		char d[t];
		for(int i=t-1;i>=0;i--)
		{
			//cout<<s[i]<<endl;
			if(s[i]!=b[j-1])
			{
				if(flag==0)
				{
					flag=1;
					for(int l=0;l<j;l++)
					{
						if(b[l]>s[i])
						{
							d[i]=b[l];
							break;
						}
					}
					//cout<<1<<endl;
				}
				else
				{
					d[i]=s[i];
					//cout<<2<<endl;
				}

			}
			if(s[i]==b[j-1])
			{
				if(flag==0)
				{
					d[i]=b[0];
					//cout<<3<<endl;
				}
				else
				{
					d[i]=s[i];
					//cout<<4<<endl;
				}

			}

		}
		for(int i=0;i<t;i++)
		cout<<d[i];
		return 0;
	}

}


#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define MOD 1000000007
#define pp pop_back
#define MAXN   100001
#define mp make_pair
#define endl '\n'
#define ff first
#define ss second
#define mapcl map<char,ll>
#define mapll map<ll,ll>
#define cmp complex<double>
#define pi 3.141592653589793238462643383279502884197169399375105820974944592307816406286
#define inf LLONG_MAX
void fast(){ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);}
typedef long long ll;
int main()
{
	ll n,k;
	cin>>n>>k;
	string s;
	cin>>s;
	string ans;
	mapcl m;
	for(ll i=0;i<n;i++)
	m[s[i]]=1;

	char sm='z';
	for(char i='a';i<='z';i++)
	{
		if(m[i]==1)
		{
			sm=i;
			break;
		}
	}
	if(k>n)
	{
		cout<<s;
		ll rem=k-n;
		while(rem--)
		cout<<sm;
		return 0;
	}
	for(ll i=0;i<k;i++)
		ans+=s[i];
	ll st;
	for(ll i=k-1;i>=0;i--)
	{

		ll flag=0;
		char x=ans[i];
		x++;
		for(char X=x;X<='z';X++)
		{
			if(m[X]==1)
			{
				flag=1;
				st=i+1;
				ans[i]=X;
				break;
			}
		}
		if(flag==1)
		break;
	}
	for(ll i=st;i<k;i++)
	{
		ans[i]=sm;
	}
	cout<<ans<<endl;
}


#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define MOD 1000000007
#define pp pop_back
#define MAXN   100001
#define mp make_pair
#define endl '\n'
#define ff first
#define ss second
#define mapcl map<char,ll>
#define mapll map<ll,ll>
#define cmp complex<double>
#define pi 3.141592653589793238462643383279502884197169399375105820974944592307816406286
#define inf LLONG_MAX
void fast(){ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);}
typedef long long ll;
int main()
{
	ll n,k;
	cin>>n>>k;
	string s;
	cin>>s;
	string ans;
	mapcl m;
	for(ll i=0;i<n;i++)
	m[s[i]]=1;

	char sm='z';
	for(char i='a';i<='z';i++)
	{
		if(m[i]==1)
		{
			sm=i;
			break;
		}
	}
	if(k>n)
	{
		cout<<s;
		ll rem=k-n;
		while(rem--)
		cout<<sm;
		return 0;
	}
	ll st;
	for(ll i=k-1;i>=0;i--)
	{
		for(ll i=0;i<k;i++)
		ans+=s[i];
		ll flag=0;
		char x=ans[i];
		x++;
		for(char X=x;X<='z';X++)
		{
			if(m[X]==1)
			{
				flag=1;
				st=i+1;
				ans[i]=X;
				break;
			}
		}
		if(flag==1)
		break;
	}
	for(ll i=st;i<k;i++)
	{
		ans[i]=sm;
	}
	cout<<ans<<endl;
}


#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define ios		ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;

int main()
{
	ios

	int n,k;
	cin>>n>>k;

	string s;
	cin>>s;

	int a[26]={0};

	for(int i=0;i<s.size();i++)
	{
		a[s[i]-'a']++;
	}
	char ch;
	char b[26],j=0;
	for(int i=0;i<=25;i++)
	{
		if(a[i]>0)
		{
			b[j]=char(i+97);
			j++;
		}
	}

	if(k>n)
	{
		cout<<s;
		for(int i=n;i<k;i++)
		{
			cout<<b[0];
		}
		return 0;
	}

	if(k<=n)
	{
		//cout<<b[0]<<" "<<b[j-1]<<endl;
		int flag=0;
		int t=min(n,k);
		char d[t];
		for(int i=t-1;i>=0;i--)
		{
			//cout<<s[i]<<endl;
			if(s[i]!=b[j-1])
			{
				if(flag==0)
				{
					flag=1;
					d[i]=b[j-1];
					//cout<<1<<endl;
				}
				else
				{
					d[i]=s[i];
					//cout<<2<<endl;
				}

			}
			if(s[i]==b[j-1])
			{
				if(flag==0)
				{
					d[i]=b[0];
					//cout<<3<<endl;
				}
				else
				{
					d[i]=s[i];
					//cout<<4<<endl;
				}

			}

		}
		for(int i=0;i<t;i++)
		cout<<d[i];
		return 0;
	}

}


#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define sz size()
#define x first
#define y second
#define pi pair <int, int>
#define pii pair <pi, pi>
#define vi vector <int>
const ll mod = 1e9 + 7;
int n, k;
string s;
char mx, mn='a'-1;
int c['z'+1];

int32_t main(){
    ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();
    cin>>n>>k;
    cin>>s;
    for(int i=0; i<n; i++){
        c[s[i]]=1;
    }
    for(char i='a'; i<='z'; i++){
        if(mn<'a' && c[i]) mn=i;
        if(c[i]) mx=i;
    }
    if(k>n){
        cout<<s;
        for(int i=n; i<k; i++) cout<<mn;
        return 0;
    }
    for(int i=k-1; i>=0; i--){
        if(s[i]!=mx){
            char z=s[i];
            for(char j=mx; j>z; j--){
                if(c[j]) s[i]=j;
            }
            for(int f=i+1; f<n; f++) s[f]=mn;
            //cout<<i;
            break;
        }
    }
    for(int i=0; i<k; i++) cout<<s[i];
}


#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define sz size()
#define x first
#define y second
#define pi pair <int, int>
#define pii pair <pi, pi>
#define vi vector <int>
const ll mod = 1e9 + 7;
int n, k;
string s;
char mx, mn='a'-1;
int c['z'+1];

int32_t main(){
    ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();
    cin>>n>>k;
    cin>>s;
    for(int i=0; i<n; i++){
        c[s[i]]=1;
    }
    for(char i='a'; i<='z'; i++){
        if(mn<'a' && c[i]) mn=i;
        if(c[i]) mx=i;
    }
    if(k>n){
        cout<<s;
        for(int i=n; i<k; i++) cout<<mn;
        return 0;
    }
    for(int i=k-1; i>=0; i--){
        if(s[i]!=mx){
            for(char j=s[i]; j<=mx; j++){
                if(c[j]) s[i]=j;
            }
            for(int f=i+1; f<n; f++) s[f]=mn;
            break;
        }
    } ;
    for(int i=0; i<k; i++) cout<<s[i];
}


#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define sz size()
#define x first
#define y second
#define pi pair <int, int>
#define pii pair <pi, pi>
#define vi vector <int>
const ll mod = 1e9 + 7;
int n, k;
string s;
char mx, mn='a'-1;
int c['z'+1];

int32_t main(){
    ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();
    cin>>n>>k;
    cin>>s;
    for(int i=0; i<n; i++){
        c[s[i]]=1;
    }
    for(char i='a'; i<='z'; i++){
        if(mn<'a' && c[i]) mn=i;
        if(c[i]) mx=i;
    }
    if(k>n){
        cout<<s;
        for(int i=n; i<k; i++) cout<<mn;
        return 0;
    }
    for(int i=k-1; i>=0; i--){
        if(s[i]!=mx){
            for(char j=s[i]; j<mx; j++){
                if(c[j]) s[i]=j;
            }
            for(int f=i+1; f<n; f++) s[f]=mn;
            break;
        }
    } ;
    for(int i=0; i<k; i++) cout<<s[i];
}


#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define sz size()
#define x first
#define y second
#define pi pair <int, int>
#define pii pair <pi, pi>
#define vi vector <int>
const ll mod = 1e9 + 7;
int n, k;
string s;
char mx, mn='a'-1;
int c['z'+1];

int32_t main(){
    ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();
    cin>>n>>k;
    cin>>s;
    for(int i=0; i<n; i++){
        c[s[i]]=1;
    }
    for(char i='a'; i<='z'; i++){
        if(mn<'a' && c[i]) mn=i;
        if(c[i]) mx=i;
    }
    if(k>n){
        cout<<s;
        for(int i=n; i<k; i++) cout<<mn;
        return 0;
    }
    for(int i=k-1; i>=0; i--){
        if(s[i]!=mx){
            for(char j=s[i]+1; j<=mx; j++){
                if(c[j]) s[i]=j;
            }
            for(int f=i+1; f<n; f++) s[f]=mn;
            break;
        }
    } ;
    for(int i=0; i<k; i++) cout<<s[i];
}


#include<bits/stdc++.h>
using namespace std;
int n,t,ans=-1;
string s,s1;
int main()
{
      cin>>n>>t>>s;
      s1=s;
      sort(s1.begin(),s1.end());
      char c=s1[0],C=s1[n-1];
      for(int i=0; i<t; i++)
      {     if(i>n-1)
                  {cout<<c; continue;}
            if(int(s[i+1])-int(C))
            {     cout<<s[i]; continue; }
            int j=i+1;
            while(!(s[j]-s[j+1])) j++;
            if(j-n+1) { cout<<s[i]; continue; }
            else
                  { for(int j=0; j<n; j++ )
                        { if(int(s1[j])>int(s[i]))
                              {
                                    cout<<char(s1[j]); ans=i; break;
                              }
                        }
                        break;
                  }
      }
      //cout<<ans; return 0;
      if(ans+1) for(int j=ans+1; j<t; j++) cout<<c;
}


#include<bits/stdc++.h>
using namespace std;
int n,t,ans=-1,answ;
string s,s1;
int main()
{
      cin>>n>>t>>s;
      s1=s;
      sort(s1.begin(),s1.end());
      char c=s1[0],C=s1[n-1];
      for(int i=0; i<t; i++)
      {
            //cout<<answ<<endl;
            if(answ>=t-1)
            {
                  for(int j=0; j<n; j++)
                  if(s1[j]>s[i]) { cout<<s1[j]; return 0; }
            }
            if(i>n-1)
                  {cout<<c; continue;}
            if(int(s[i+1])-int(C))
            {     answ++; cout<<s[i]; continue; }
            int j=i+1;
            while(!(s[j]-s[j+1])) j++;
            if(j-n+1) { answ++; cout<<s[i]; continue; }
            else
                  { for(int j=0; j<n; j++ )
                        { if(int(s1[j])>int(s[i]))
                              {
                                    cout<<char(s1[j]); ans=i; break;
                              }
                        }
                        break;
                  }
      }
     // cout<<ans; return 0;
      if(ans+1) for(int j=ans+1; j<t; j++) cout<<c;
}


#include<bits/stdc++.h>
using namespace std;
int n,t,ans=-1,answ;
string s,s1;
int main()
{
      cin>>n>>t>>s;
      s1=s;
      sort(s1.begin(),s1.end());
      char c=s1[0],C=s1[n-1];
      if(t>n)
      {
            for(int i=0; i<t; i++) if(i<n) cout<<s[i]; else cout<<c;
            return 0;
      }
      for(int i=0; i<t; i++)
      {
            //cout<<answ<<endl;
            if(answ>=t-1)
            {
                  for(int j=0; j<n; j++)
                  if(s1[j]>s[i]) { cout<<s1[j]; return 0; }
            }
            if(int(s[i+1])-int(C))
            {     answ++; cout<<s[i]; continue; }
            int j=i+1;
            while(!(s[j]-s[j+1])) j++;
            if(j+1<t) { answ++; cout<<s[i]; continue; }
            else
                  { for(int j=0; j<n; j++ )
                        { if(int(s1[j])>int(s[i]))
                              {
                                    cout<<char(s1[j]); ans=i; break;
                              }
                        }
                        break;
                  }
      }
     // cout<<ans; return 0;
      if(ans+1) for(int j=ans+1; j<t; j++) cout<<c;
}


#include<bits/stdc++.h>
using namespace std;
int n,t,ans=-1,answ;
string s,s1;
int main()
{
      cin>>n>>t>>s;
      s1=s;
      sort(s1.begin(),s1.end());
      char c=s1[0],C=s1[n-1];
      if(t>n)
      {
            for(int i=0; i<t; i++) if(i<n) cout<<s[i]; else cout<<c;
            return 0;
      }
      for(int i=0; i<t; i++)
      {
            //cout<<answ<<endl;
            if(answ>=t-1)
            {
                  for(int j=0; j<n; j++)
                  if(s1[j]>s[i]) { cout<<s1[j]; return 0; }
            }
            if(int(s[i+1])-int(C))
            {     answ++; cout<<s[i]; continue; }
            int j=i+1;
            while(!(s[j]-s[j+1])) j++;
            if(j-n+1) { answ++; cout<<s[i]; continue; }
            else
                  { for(int j=0; j<n; j++ )
                        { if(int(s1[j])>int(s[i]))
                              {
                                    cout<<char(s1[j]); ans=i; break;
                              }
                        }
                        break;
                  }
      }
     // cout<<ans; return 0;
      if(ans+1) for(int j=ans+1; j<t; j++) cout<<c;
}


#include<bits/stdc++.h>
using namespace std;
int n,t,ans=-1,answ;
string s,s1;
int main()
{
      cin>>n>>t>>s;
      s1=s;
      sort(s1.begin(),s1.end());
      char c=s1[0],C=s1[n-1];
      if(t>n)
      {
            for(int i=0; i<t; i++) if(i<n) cout<<s[i]; else cout<<c;
            return 0;
      }
      for(int i=0; i<t; i++)
      {
            //cout<<answ<<endl;
            if(answ>=t-1)
            {
                  for(int j=0; j<n; j++)
                  if(s1[j]>s[i]) { cout<<s1[j]; return 0; }
            }
            if(int(s[i+1])-int(C))
            {     answ++; cout<<s[i]; continue; }
            int j=i+1;
            while(!(s[j]-s[j+1])) j++;
            if(j-t+1) { answ++; cout<<s[i]; continue; }
            else
                  { for(int j=0; j<n; j++ )
                        { if(int(s1[j])>int(s[i]))
                              {
                                    cout<<char(s1[j]); ans=i; break;
                              }
                        }
                        break;
                  }
      }
     // cout<<ans; return 0;
      if(ans+1) for(int j=ans+1; j<t; j++) cout<<c;
}


#include<bits/stdc++.h>
using namespace std;
int n,t,ans=-1;
string s,s1;
int main()
{
      cin>>n>>t>>s;
      s1=s;
      sort(s1.begin(),s1.end());
      char c=s1[0],C=s1[n-1];
      for(int i=0; i<t; i++) { if(i>n-1) {cout<<c; continue;} if(int(s[i+1])-int(C)) cout<<s[i]; else { for(int j=0; j<n; j++ ){ if(int(s1[j])>int(s[i])){ cout<<char(s1[j]); ans=i; break; } } break;} }
      if(ans+1) for(int j=ans+1; j<t; j++) cout<<c;
}


#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> ii;
typedef vector< ii > vii;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef	vector<pair<int,pair<int,int > > > viii;
typedef long long int lli;

#define rep(i,a,b) for(int i=a;i<b;i++)
#define repv(i,a,b) for(int i=b-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(a) (int)(a.size())

#define si(n) scanf("%d",&n)
#define dout(n) printf("%d\n",n)
#define sll(n) scanf("%lld",&n)
#define lldout(n) printf("%lld\n",n)
const int N = (int)1e5 + 10;
lli vis[N];
vvi v;
int dfs(int t){
	vis[t]=1;
	rep(i,0,v[t].size()){
		if(vis[v[t][t]]==0){
			dfs(v[t][i]);
		}
	}
	return 0;
}
int gcd(int a,int b) { return b==0 ? a : gcd (b,a%b);}
int lcm(int a,int b) { return a*(b/gcd(a,b));}
int main(){
	int  n,k;
	cin>>n>>k;
	string s;
	cin>>s;
	char g=s[0];
	rep(i,0,sz(s)){
		if(s[i]>s[0]){g=s[i];}
	}
	rep(i,0,k){
		cout<<g;
	}
	cout<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> ii;
typedef vector< ii > vii;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef	vector<pair<int,pair<int,int > > > viii;
typedef long long int lli;

#define rep(i,a,b) for(int i=a;i<b;i++)
#define repv(i,a,b) for(int i=b-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(a) (int)(a.size())

#define si(n) scanf("%d",&n)
#define dout(n) printf("%d\n",n)
#define sll(n) scanf("%lld",&n)
#define lldout(n) printf("%lld\n",n)
const int N = (int)1e5 + 10;
lli vis[N];
vvi v;
int dfs(int t){
	vis[t]=1;
	rep(i,0,v[t].size()){
		if(vis[v[t][t]]==0){
			dfs(v[t][i]);
		}
	}
	return 0;
}
int gcd(int a,int b) { return b==0 ? a : gcd (b,a%b);}
int lcm(int a,int b) { return a*(b/gcd(a,b));}
int main(){
	int  n,k;
	cin>>n>>k;
	string s;
	cin>>s;
	vector<char> g;
	char a[100005];
	rep(i,0,sz(s))g.pb(s[i]);
	rep(i,0,k)a[i]=s[i];
	sort(g.begin(),g.end());
	reverse(g.begin(),g.end());

	if(k>n){
		rep(i,0,n)cout<<s[i];
		for(int i=n;i<k;i++)cout<<g[sz(g)-1];
		cout<<endl;
	}
	else{
	for(int i=k-1;i>=0;i--){
		if(a[i]!=g[0]){a[i]=g[0];break;}
		else a[i]=s[0];
	}
	rep(i,0,k)cout<<a[i];
	cout<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> ii;
typedef vector< ii > vii;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef	vector<pair<int,pair<int,int > > > viii;
typedef long long int lli;

#define rep(i,a,b) for(int i=a;i<b;i++)
#define repv(i,a,b) for(int i=b-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(a) (int)(a.size())

#define si(n) scanf("%d",&n)
#define dout(n) printf("%d\n",n)
#define sll(n) scanf("%lld",&n)
#define lldout(n) printf("%lld\n",n)
const int N = (int)1e5 + 10;
lli vis[N];
vvi v;
int dfs(int t){
	vis[t]=1;
	rep(i,0,v[t].size()){
		if(vis[v[t][t]]==0){
			dfs(v[t][i]);
		}
	}
	return 0;
}
int gcd(int a,int b) { return b==0 ? a : gcd (b,a%b);}
int lcm(int a,int b) { return a*(b/gcd(a,b));}
int vis1[30];
int main(){
	int  n,k;
	cin>>n>>k;
	string s;
	cin>>s;
	vector<char> g;
	char a[100005];
	rep(i,0,sz(s)){vis1[s[i]-'a']=1;g.pb(s[i]);}
	rep(i,0,k)a[i]=s[i];
	sort(g.begin(),g.end());
	reverse(g.begin(),g.end());
	if(k>n){
		rep(i,0,n)cout<<s[i];
		for(int i=n;i<k;i++)cout<<g[sz(g)-1];
		cout<<endl;
	}
	else{
		int flg=0;
	for(int i=k-1;i>=0;i--){
		if(a[i]==g[0]) a[i]=g[sz(g)-1];
		else {
			rep(j,0,27){
				if(a[i]<char(97+j) and vis1[char(97+j)-'a']==1){
					a[i]=char(97+j);flg=1;break;
				}
			}
			//cout<<i<<" "<<a[i]<<endl;
		}
		if(flg==1)break;
	}
	rep(i,0,k)cout<<a[i];
	cout<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> ii;
typedef vector< ii > vii;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef	vector<pair<int,pair<int,int > > > viii;
typedef long long int lli;

#define rep(i,a,b) for(int i=a;i<b;i++)
#define repv(i,a,b) for(int i=b-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(a) (int)(a.size())

#define si(n) scanf("%d",&n)
#define dout(n) printf("%d\n",n)
#define sll(n) scanf("%lld",&n)
#define lldout(n) printf("%lld\n",n)
const int N = (int)1e5 + 10;
lli vis[N];
vvi v;
int dfs(int t){
	vis[t]=1;
	rep(i,0,v[t].size()){
		if(vis[v[t][t]]==0){
			dfs(v[t][i]);
		}
	}
	return 0;
}
int gcd(int a,int b) { return b==0 ? a : gcd (b,a%b);}
int lcm(int a,int b) { return a*(b/gcd(a,b));}
int main(){
	int  n,k;
	cin>>n>>k;
	string s;
	cin>>s;
	vector<char> g;
	char a[100005];
	rep(i,0,sz(s))g.pb(s[i]);
	rep(i,0,k)a[i]=s[i];
	sort(g.begin(),g.end());
	reverse(g.begin(),g.end());

	if(k>n){
		rep(i,0,n)cout<<s[i];
		for(int i=n;i<k;i++)cout<<g[sz(g)-1];
		cout<<endl;
	}
	else{
	for(int i=k-1;i>=0;i--){
		if(a[i]!=g[0]){a[i]=g[0];break;}
		else a[i]=g[sz(g)-1];
	}
	rep(i,0,k)cout<<a[i];
	cout<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> ii;
typedef vector< ii > vii;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef	vector<pair<int,pair<int,int > > > viii;
typedef long long int lli;

#define rep(i,a,b) for(int i=a;i<b;i++)
#define repv(i,a,b) for(int i=b-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(a) (int)(a.size())

#define si(n) scanf("%d",&n)
#define dout(n) printf("%d\n",n)
#define sll(n) scanf("%lld",&n)
#define lldout(n) printf("%lld\n",n)
const int N = (int)1e5 + 10;
lli vis[N];
vvi v;
int dfs(int t){
	vis[t]=1;
	rep(i,0,v[t].size()){
		if(vis[v[t][t]]==0){
			dfs(v[t][i]);
		}
	}
	return 0;
}
int gcd(int a,int b) { return b==0 ? a : gcd (b,a%b);}
int lcm(int a,int b) { return a*(b/gcd(a,b));}
int vis1[30];
int main(){
	int  n,k;
	cin>>n>>k;
	string s;
	cin>>s;
	vector<char> g;
	char a[100005];
	rep(i,0,sz(s)){vis1[s[i]-'a']=1;g.pb(s[i]);}
	sort(g.begin(),g.end());
	reverse(g.begin(),g.end());
	if(k>n){
		rep(i,0,n)cout<<s[i];
		for(int i=n;i<k;i++)cout<<g[sz(g)-1];
		cout<<endl;
	}
	else{
	rep(i,0,k)a[i]=s[i];
		int flg=0;
	for(int i=k-1;i>=0;i--){
		if(a[i]==g[0]) a[i]=g[sz(g)-1];
		else {
			rep(j,0,27){
				if(a[i]<char(97+j) and vis1[char(97+j)-'a']==1){
					a[i]=char(97+j);flg=1;break;
				}
			}
			//cout<<i<<" "<<a[i]<<endl;
		}
		if(flg==1)break;
	}
	rep(i,0,k)cout<<a[i];
	cout<<endl;
	}
	return 0;
}


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

string S,s;
int X[30],done[100005];
set <char> bka;

int main()
{
    int N,K,i,j,k;

    cin>>N>>K;

    cin>>S;

    for(i=0;i<S.size();i++)
    X[S[i]-'a']++,bka.insert(S[i]);

    if(K>N)
    {
    int c1=0;
    for(j=0;j<26;j++)
    {
    if(X[j])
    {
    c1=j;
    break;
    }
    }

    s=S;

    for(i=0;i<(K-N);i++)
    s.push_back('a'+c1);
    cout<<s<<"\n";
    return 0;
    }

    if(bka.size()==1)
    {
    for(j=0;j<K;j++)
    s.push_back(S[0]);
    return 0;
    }

    if(bka.size()==2)
    {
    int f;
    for(j=0;j<26;j++)
    {
    if(X[j])
    {
    f=j;    break;
    }
    }
    int second;

    for(i=j+1;i<26;i++)
    {
    if(X[i])
    {
    second=i;    break;
    }
    }

    int pos=0;

    for(i=0;i<N;i++)
    {
    if(S[i]-'a'==second)
    {
    pos=i-1;
    break;
    }
    }

    for(i=0;i<K;i++)
    {
    if(i==pos)
    s.push_back('a'+second);
    else
    s.push_back('a'+f);
    }

    cout<<s<<"\n";
    return 0;
    }

    int small=0,big=25;
    for(i=0;i<26;i++)
    {
    if(X[i])
    {
    small=i;
    break;
    }
    }

    for(i=25;i>=0;i--)
    {
    if(X[i])
    {
    big=i;
    break;
    }
    }

    for(i=K-1;i>=0;i--)
    {
        int now=S[i]-'a';
        if(now==big)
        {
        S[i]='a'+small;
        continue;
        }
        int f=0,get=0;
        for(j=0;j<26;j++)
        {
        if(X[j] && j>now)
        {
        f=1,get=j;
        }
        }

        if(f)
        {
        S[i]='a'+get;
        break;
        }
    }

    for(i=0;i<K;i++)
    cout<<S[i];
    cout<<"\n";
    return 0;
}


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

string S,s;
int X[30],done[100005];
set <char> bka;

int main()
{
    int N,K,i,j,k;

    cin>>N>>K;

    cin>>S;

    for(i=0;i<S.size();i++)
    X[S[i]-'a']++,bka.insert(S[i]);

    if(K>N)
    {
    int c1=0;
    for(j=0;j<26;j++)
    {
    if(X[j])
    {
    c1=j;
    break;
    }
    }

    s=S;

    for(i=0;i<(K-N);i++)
    s.push_back('a'+c1);
    cout<<s<<"\n";
    return 0;
    }

    if(bka.size()==1)
    {
    for(j=0;j<K;j++)
    s.push_back(S[0]);
    return 0;
    }

    if(bka.size()==2)
    {
    int f;
    for(j=0;j<26;j++)
    {
    if(X[j])
    {
    f=j;    break;
    }
    }
    int second;

    for(i=j+1;i<26;i++)
    {
    if(X[i])
    {
    second=i;    break;
    }
    }

    int pos=0;

    for(i=0;i<N;i++)
    {
    if(S[i]-'a'==second)
    {
    pos=i-1;
    break;
    }
    }

    for(i=0;i<K;i++)
    {
    if(i==pos)
    s.push_back('a'+second);
    else
    s.push_back('a'+f);
    }

    cout<<s<<"\n";
    return 0;
    }

    int c1=-1,c2=-1,c3=-1;
    for(j=0;j<26;j++)
    {
    if(X[j] && c1==-1)
    {
    c1=j;
    }
    else if(X[j] && c2==-1)
    {
    c2=j;
    }
    else if(X[j] && c3==-1)
    {
    c3=j;
    }
    }
    int flag=0;

    if(K==1)
    {
    for(j=0;j<26;j++)
    {
    if(S[0]-'a'<j)
    {
    s='a'+j;
    }
    }
    cout<<s<<"\n";
    return 0;
    }
    int pos=0;
    for(i=K-1;i>=0;i--)
    {
        if(S[i]-'a'==c2)
        {
        pos=i;
        break;
        }
    }

    for(i=0;i<K;i++)
    {
    if(i<pos)
    s.push_back(S[i]);
    else if(i==pos)
    s.push_back('a'+c3);
    else
    s.push_back('a'+c1);
    }

    cout<<s<<"\n";
    return 0;
}


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

string S,s;
int X[30],done[100005];
set <char> bka;

int main()
{
    int N,K,i,j,k;

    cin>>N>>K;

    cin>>S;

    for(i=0;i<S.size();i++)
    X[S[i]-'a']++,bka.insert(S[i]);

    if(K>N)
    {
    int c1=0;
    for(j=0;j<26;j++)
    {
    if(X[j])
    {
    c1=j;
    break;
    }
    }

    s=S;

    for(i=0;i<(K-N);i++)
    s.push_back('a'+c1);
    cout<<s<<"\n";
    return 0;
    }

    if(bka.size()==1)
    {
    for(j=0;j<K;j++)
    s.push_back(S[0]);
    return 0;
    }

    if(bka.size()==2)
    {
    int f;
    for(j=0;j<26;j++)
    {
    if(X[j])
    {
    f=j;    break;
    }
    }
    int second;

    for(i=j+1;i<26;i++)
    {
    if(X[i])
    {
    second=i;    break;
    }
    }

    int pos=0;

    for(i=0;i<N;i++)
    {
    if(S[i]-'a'==second)
    {
    pos=i-1;
    break;
    }
    }

    for(i=0;i<K;i++)
    {
    if(i==pos)
    s.push_back('a'+second);
    else
    s.push_back('a'+f);
    }

    cout<<s<<"\n";
    return 0;
    }

    int small=0,big=25;
    for(i=0;i<26;i++)
    {
    if(X[i])
    {
    small=i;
    break;
    }
    }

    for(i=25;i>=0;i--)
    {
    if(X[i])
    {
    big=i;
    break;
    }
    }

    for(i=K-1;i>=0;i--)
    {
        int now=S[i]-'a';
        if(now==big)
        {
        S[i]='a'+small;
        continue;
        }
        int f=0,get=0;
        for(j=0;j<26;j++)
        {
        if(X[j] && j>now)
        {
        f=1,get=j;
        break;
        }
        }

        if(f)
        {
        S[i]='a'+get;
        break;
        }
    }

    for(i=0;i<K;i++)
    cout<<S[i];
    cout<<"\n";
    return 0;
}


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

string S,s;
int X[30],done[100005];
set <char> bka;

int main()
{
    int N,K,i,j,k;

    cin>>N>>K;

    cin>>S;

    for(i=0;i<S.size();i++)
    X[S[i]-'a']++,bka.insert(S[i]);

    if(K>N)
    {
    int c1=0;
    for(j=0;j<26;j++)
    {
    if(X[j])
    {
    c1=j;
    break;
    }
    }

    s=S;

    for(i=0;i<(K-N);i++)
    s.push_back('a'+c1);
    cout<<s<<"\n";
    return 0;
    }

    if(bka.size()==1)
    {
    for(j=0;j<K;j++)
    s.push_back(S[0]);
    return 0;
    }

    if(bka.size()==2)
    {
    int f;
    for(j=0;j<26;j++)
    {
    if(X[j])
    {
    f=j;    break;
    }
    }
    int second;

    for(i=j+1;i<26;i++)
    {
    if(X[i])
    {
    second=i;    break;
    }
    }

    int pos=0;

    for(i=0;i<N;i++)
    {
    if(S[i]-'a'==second)
    {
    pos=i-1;
    break;
    }
    }

    for(i=0;i<K;i++)
    {
    if(i==pos)
    s.push_back('a'+second);
    else
    s.push_back('a'+f);
    }

    cout<<s<<"\n";
    return 0;
    }

    if(K<=N)
    {
    int c1=0;
    for(j=0;j<26;j++)
    {
    if(X[j])
    {
    c1=j;
    break;
    }
    }
    int flag=0;
    for(i=0;i<K;i++)
    {
    if(S[i]-'a'==c1)
    {
    s.push_back(S[i]);
    }
    else
    {
    int now=S[i]-'a';
    int l=0;
    for(j=0;j<26;j++)
    {
    if(X[j] && j>now)
    {
    flag=1;
    s.push_back('a'+j);
    break;
    }
    }
    if(flag)
    break;
    }
    }
    while(s.size()<K)
    {
    s.push_back('a'+c1);
    }

    cout<<s<<"\n";
    }

    return 0;
}


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

string S,s;
int X[30],done[100005];
set <char> bka;

int main()
{
    int N,K,i,j,k;

    cin>>N>>K;

    cin>>S;

    for(i=0;i<S.size();i++)
    X[S[i]-'a']++,bka.insert(S[i]);

    if(K>N)
    {
    int c1=0;
    for(j=0;j<26;j++)
    {
    if(X[j])
    {
    c1=j;
    break;
    }
    }

    s=S;

    for(i=0;i<(K-N);i++)
    s.push_back('a'+c1);
    cout<<s<<"\n";
    return 0;
    }

    if(bka.size()==1)
    {
    for(j=0;j<K;j++)
    s.push_back(S[0]);
    return 0;
    }

    int small=0,big=25;
    for(i=0;i<26;i++)
    {
    if(X[i])
    {
    small=i;
    break;
    }
    }

    for(i=25;i>=0;i--)
    {
    if(X[i])
    {
    big=i;
    break;
    }
    }

    for(i=K-1;i>=0;i--)
    {
        int now=S[i]-'a';
        if(now==big)
        {
        S[i]='a'+small;
        continue;
        }
        int f=0,get=0;
        for(j=0;j<26;j++)
        {
        if(X[j] && j>now)
        {
        f=1,get=j;
        break;
        }
        }

        if(f)
        {
        S[i]='a'+get;
        break;
        }
    }

    for(i=0;i<K;i++)
    cout<<S[i];
    cout<<"\n";
    return 0;
}


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

int main()
{
	int n,k;cin>>n>>k;
	string s;
	cin>>s;
	map<char,int> m;vector<char> v;
	for(int i=0;i<s.length();i++)
		if(m[s[i]]==0){v.push_back(s[i]);m[s[i]]++;}
	sort(v.begin(),v.end());
	if(k>s.length())
	{
		for(int i=1;i<=(int)(k-s.length());i++)
			s+=v[0];
		cout<<s<<endl;
	}
	else
	{
		int i;
		for( i=k-1;i>=0;i--)
		if(s[i]!=v[(int)(v.size()-1)])break;
		for(int j=0;j<v.size();j++)
		{
			if(v[j]>s[i]){s[i]=v[j];break;}
		}
		for(int x=i+1;x<=k-1;x++)
			s[x]=v[0];
		cout<<s.substr(0,k)<<endl;
	}
	return 0;
}


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

int main()
{
	int n,k;cin>>n>>k;
	string s;
	cin>>s;
	map<char,int> m;vector<char> v;
	for(int i=0;i<s.length();i++)
		if(m[s[i]]==0){v.push_back(s[i]);m[s[i]]++;}
	sort(v.begin(),v.end());
	if(k>n))
	{
		for(int i=1;i<=(k-n));i++)
			s+=v[0];
		cout<<s<<endl;
	}
	else
	{
		int i;
		for( i=k-1;i>=0;i--)
		if(s[i]!=v[(int)(v.size()-1)])break;
		for(int j=0;j<v.size();j++)
		{
			if(v[j]>s[i]){s[i]=v[j];break;}
		}
		for(int x=i+1;x<=k-1;x++)
			s[x]=v[0];
		cout<<s.substr(0,k)<<endl;
	}
	return 0;
}


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

int main()
{
	int n,k;cin>>n>>k;
	string s;
	cin>>s;
	map<char,int> m;vector<char> v;
	for(int i=0;i<s.length();i++)
		if(m[s[i]]==0){v.push_back(s[i]);m[s[i]]++;}
	sort(v.begin(),v.end());
	if(k>s.length())
	{
		for(int i=1;i<=(k-(int)s.length());i++)
			s+=v[0];
		cout<<s<<endl;
	}
	else
	{
		int i;
		for( i=k-1;i>=0;i--)
		if(s[i]!=v[(int)(v.size()-1)])break;
		for(int j=0;j<v.size();j++)
		{
			if(v[j]>s[i]){s[i]=v[j];break;}
		}
		for(int x=i+1;x<=k-1;x++)
			s[x]=v[0];
		cout<<s.substr(0,k)<<endl;
	}
	return 0;
}


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

int main()
{
	int n,k;cin>>n>>k;
	string s;
	cin>>s;
	map<char,int> m;vector<char> v;
	for(int i=0;i<s.length();i++)
		if(m[s[i]]==0){v.push_back(s[i]);m[s[i]]++;}
	sort(v.begin(),v.end());
	if(k>n)
	{
		for(int i=1;i<=(int)(k-s.length());i++)
			s+=v[0];
		cout<<s<<endl;
	}
	else
	{
		int i;
		for( i=k-1;i>=0;i--)
		if(s[i]!=v[(int)(v.size()-1)])break;
		for(int j=0;j<v.size();j++)
		{
			if(v[j]>s[i]){s[i]=v[j];break;}
		}
		for(int x=i+1;x<=k-1;x++)
			s[x]=v[0];
		cout<<s.substr(0,k)<<endl;
	}
	return 0;
}


#include <stdio.h>
#include<bits/stdc++.h>
#include<iostream>

using namespace std;
void dfs(vector<vector<int>>&v, int src, int &count, int a, int bug, int arr[], int q)
{
    if(q==0)
    {
        bug = 0;
    }
    if(arr[src]==1)
    {
        bug++;
        if(bug > a)
        {
            return;
        }
    }
    if(v[src].size()==0)
    {
        count++;
        return;
    }
    for(int i=0; i<v[src].size(); i++)
    {
        dfs(v, v[src][i], count, a, bug, arr, arr[v[src][i]]);
    }
    return;
}

int main() {
	int n,a;
	cin>>n>>a;
	int arr[n+1];
	vector<vector<int>>v(n+1);
	arr[0]=0;
	for(int i=1; i<n+1; i++)
	{
	    cin>>arr[i];
	}
	int src;
	for(int i=0; i<n-1; i++)
	{
	    int x, y;
	    cin>>x>>y;
	    if(i==0)
	    {
	        src = x;
	    }
	    v[x].push_back(y);
	}
	int count = 0;
	int bug=0;
	dfs(v, src, count, a, bug, arr, arr[1]);
	cout<<count;
	return 0;
}


#include <stdio.h>
#include<bits/stdc++.h>
#include<iostream>

using namespace std;
void dfs(vector<vector<int>>&v, int src, int &count, int a, int bug, int arr[], int q, vector<int> &vis)
{
    if(vis[src]==1)
    {
        return;
    }
    vis[src] = 1;
    if(q==0)
    {
        bug = 0;
    }
    if(arr[src]==1)
    {
        bug++;
        if(bug > a)
        {
            return;
        }
    }
    if(v[src].size()==0)
    {
        count++;
    }
    for(int i=0; i<v[src].size(); i++)
    {
        dfs(v, v[src][i], count, a, bug, arr, arr[v[src][i]],vis);
    }
    return;
}

int main() {
	int n,a;
	cin>>n>>a;
	int arr[n+1];
	vector<int>vis(n+1,0);
	vector<vector<int>>v(n+1);
	arr[0]=0;
	for(int i=1; i<n+1; i++)
	{
	    cin>>arr[i];
	}
	int src;
	for(int i=0; i<n-1; i++)
	{
	    int x, y;
	    cin>>x>>y;
	    if(x<y)
	    {
	        v[x].push_back(y);
	    }
	    else
	    {
	      v[y].push_back(x);
	    }
	}
	int count = 0;
	int bug=0;
	dfs(v, 1, count, a, bug, arr, arr[1],vis);
	cout<<count;
	return 0;
}


#include <stdio.h>
#include<bits/stdc++.h>
#include<iostream>

using namespace std;
void dfs(vector<vector<int>>&v, int src, int &count, int a, int bug, int arr[], int q, vector<int> &vis)
{
    if(vis[src]==1)
    {
        return;
    }
    vis[src] = 1;
    if(q==0)
    {
        bug = 0;
    }
    if(arr[src]==1)
    {
        bug++;
        if(bug > a)
        {
            return;
        }
    }
    if(v[src].size()==1 && src != 1)
    {
        count++;
    }
    for(int i=0; i<v[src].size(); i++)
    {
        dfs(v, v[src][i], count, a, bug, arr, arr[v[src][i]],vis);
    }
    return;
}

int main() {
	int n,a;
	cin>>n>>a;
	int arr[n+1];
	vector<int>vis(n+1,0);
	vector<vector<int>>v(n+1);
	arr[0]=0;
	for(int i=1; i<n+1; i++)
	{
	    cin>>arr[i];
	}
	for(int i=0; i<n-1; i++)
	{
	    int x, y;
	    cin>>x>>y;
	    v[x].push_back(y);
	    v[y].push_back(x);
	}
	int count = 0;
	int bug=0;
	dfs(v, 1, count, a, bug, arr, arr[1],vis);
	cout<<count;
	return 0;
}


#include <iostream>
#include<bits/stdc++.h>

using namespace std;

void dfs(vector<vector<int>>adj, vector<int>& vis, int count, int &res, int x, int arr[], int a, int m)
{
    if(vis[x]==1)
    {
        return;
    }
    vis[x] = 1;
    if(a == 0)
    {
        count = 0;
    }
    if(arr[x-1]==1)
    {
        count++;
        if(count > m)
        {
            return;
        }
    }
    if(adj[x].size()==1 && x != 1)
    {
        res++;
    }
    for(int i=0; i<adj[x].size(); i++)
    {
        dfs(adj, vis, count, res, adj[x][i], arr, arr[x-1] ,m);
    }
    return;
}

int main() {
	int n,m;
	cin>>n>>m;
	int arr[n];
	for(int i=0; i<n; i++)
	{
	    cin>>arr[i];
	}
	vector<vector<int>>adj(n+1);
	for(int i=0; i<n-1; i++)
	{
	    int a,b;
	    cin>>a>>b;
	    adj[a].push_back(b);
	    adj[b].push_back(a);
	}
	int count = 0;
	vector<int>vis(n+1,0);
	int res = 0;
	dfs(adj,vis,count,res,1,arr, arr[0], m);
	cout<<res;

	return 0;
}


#include <stdio.h>
#include<bits/stdc++.h>
#include<iostream>

using namespace std;
void dfs(vector<vector<int>>&v, int src, int &count, int a, int bug, int arr[], int q)
{
    if(q==0)
    {
        bug = 0;
    }
    if(arr[src]==1)
    {
        bug++;
        if(bug > a)
        {
            return;
        }
    }
    if(v[src].size()==0)
    {
        count++;
        return;
    }
    for(int i=0; i<v[src].size(); i++)
    {
        dfs(v, v[src][i], count, a, bug, arr, arr[v[src][i]]);
    }
    return;
}

int main() {
	int n,a;
	cin>>n>>a;
	int arr[n+1];
	vector<vector<int>>v(n+1);
	arr[0]=0;
	for(int i=1; i<n+1; i++)
	{
	    cin>>arr[i];
	}
	for(int i=0; i<n-1; i++)
	{
	    int x, y;
	    cin>>x>>y;
	    v[x].push_back(y);
	}
	int count = 0;
	int bug=0;
	dfs(v, 1, count, a, bug, arr, arr[1]);
	cout<<count;
	return 0;
}


#include <stdio.h>
#include<bits/stdc++.h>
#include<iostream>

using namespace std;
void dfs(vector<vector<int>>&v, int src, int &count, int a, int &bug, int arr[])
{
    if(arr[src]==1)
    {
        bug++;
        if(bug==a)
        {
            return;
        }
    }
    if(v[src].size()==0)
    {
        count++;
    }
    for(int i=0; i<v[src].size(); i++)
    {
        dfs(v, v[src][i], count, a, bug, arr);
    }

}

int main() {
	int n,a;
	cin>>n>>a;
	int arr[n+1];
	vector<vector<int>>v(n+1);
	arr[0]=0;
	for(int i=1; i<n+1; i++)
	{
	    cin>>arr[i];
	}
	for(int i=0; i<n-1; i++)
	{
	    int x, y;
	    cin>>x>>y;
	    v[x].push_back(y);
	}
	int count = 0;
	int bug;
	if(arr[1]==1)
	{
	    bug = -1;
	}
	if(arr[1]==0)
	{
	    bug = 0;
	}
	dfs(v, 1, count, a, bug, arr);
	cout<<count;
	return 0;
}


/*
Author : Vidish Joshi
*/

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

//#include<boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;

#define ll long long int
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define mod 1000000007
#define FOR1(i, m, n) for(i=m; i<n; i++)
#define FOR2(i, n, m) for(i=n-1; i>=m; i--)
#define re(v) ll v; cin>>v
#define mod 1000000007
#define mod2 998244353
#define mp make_pair
#define pb push_back
#define fill(a) memset(a, 0, sizeof(a))
#define start ll t; cin>>t; while(t--)
#define br "\n"

const ll N = (ll)1e5 + 5;
ll ans = 0, n, m;
unordered_map<ll, ll> a;
bool vis[N];

void dfs(vector<vector<ll> > adj, ll root, ll tc, ll cost){
    vis[root] = 1;
    if(a[root]==1) tc++, cost = max(tc, cost);
    else cost = max(tc, cost), tc = 0;
    if(cost > m) return;
    if(root!=1 && adj[root].size()==1) ans += (cost <= m);

    for(auto it: adj[root]){
        if(vis[it]) continue;
        dfs(adj, it, tc, cost);
    }
}

void solve(){
    cin>>n>>m;
    ll xx;
    for(ll i=1; i<=n; i++){
        cin>>xx;
        if(xx) a[i]=1;
    }

    ll x, y;
    vector<vector<ll> > adj(n+1);
    for(ll i=0; i<n-1; i++){
        cin>>x>>y;
        adj[x].pb(y);
        adj[y].pb(x);
    }

    for(ll i=0; i<(ll)1e5 + 5; i++) vis[i] = 0;
    dfs(adj, 1, 0, 0);
    cout<<ans<<br;
}

int main(){
    FIO;
    solve();
    return 0;
}


/*
Author : Vidish Joshi
*/

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

//#include<boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;

#define ll long long int
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define mod 1000000007
#define FOR1(i, m, n) for(i=m; i<n; i++)
#define FOR2(i, n, m) for(i=n-1; i>=m; i--)
#define re(v) ll v; cin>>v
#define mod 1000000007
#define mod2 998244353
#define mp make_pair
#define pb push_back
#define fill(a) memset(a, 0, sizeof(a))
#define start ll t; cin>>t; while(t--)
#define br "\n"

const ll N = (ll)1e5 + 5;
ll ans = 0, n, m;
ll a[N];
bool vis[N];

void dfs(vector<vector<ll> > adj, ll root, ll tc, ll cost){
    vis[root] = 1;
    if(a[root]==1) tc++, cost = max(tc, cost);
    else cost = max(tc, cost), tc = 0;
    if(cost > m) return;
    if(root!=1 && adj[root].size()==1) ans += (cost <= m);

    for(auto it: adj[root]){
        if(vis[it]) continue;
        dfs(adj, it, tc, cost);
    }
}

void solve(){
    cin>>n>>m;
    for(ll i=1; i<=n; i++) cin>>a[i];

    ll x, y;
    vector<vector<ll> > adj(n+1);
    for(ll i=0; i<n-1; i++){
        cin>>x>>y;
        adj[x].pb(y);
        adj[y].pb(x);
    }

    for(ll i=0; i<(ll)1e5 + 5; i++) vis[i] = 0;
    dfs(adj, 1, 0, 0);
    cout<<ans<<br;
}

int main(){
    FIO;
    solve();
    return 0;
}


/*
Author : Vidish Joshi
*/

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

//#include<boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;

#define ll long long int
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define mod 1000000007
#define FOR1(i, m, n) for(i=m; i<n; i++)
#define FOR2(i, n, m) for(i=n-1; i>=m; i--)
#define re(v) ll v; cin>>v
#define mod 1000000007
#define mod2 998244353
#define mp make_pair
#define pb push_back
#define fill(a) memset(a, 0, sizeof(a))
#define start ll t; cin>>t; while(t--)
#define br "\n"

const ll N = (ll)1e5 + 5;
ll ans = 0, n, m;
unordered_map<ll, ll> a;

void dfs(vector<vector<ll> > adj, ll root, ll tc, ll cost, bool vis[]){
    if(cost>m) return;
    vis[root] = 1;
    if(a[root]==1) tc++, cost = max(tc, cost);
    else cost = max(tc, cost), tc = 0;
    if(cost > m) return;
    if(root!=1 && adj[root].size()==1) ans += (cost <= m);

    for(auto it: adj[root]){
        if(vis[it]) continue;
        dfs(adj, it, tc, cost, vis);
    }
}

void solve(){
    cin>>n>>m;
    ll xx;
    for(ll i=1; i<=n; i++){
        cin>>xx;
        if(xx) a[i]=1;
    }

    ll x, y;
    vector<vector<ll> > adj(n+1);
    for(ll i=0; i<n-1; i++){
        cin>>x>>y;
        adj[x].pb(y);
        adj[y].pb(x);
    }

    bool vis[n+1];
    for(ll i=0; i<=n; i++) vis[i] = 0;
    dfs(adj, 1, 0, 0, vis);
    cout<<ans<<br;
}

int main(){
    FIO;
    solve();
    return 0;
}