#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = 1; i <= (int)(n); i++)
#define drep(i, n) for(int i = (n)-1; i >= 0; i--)
#define ALL(x) (x).begin(), (x).end()
#define dup(x,y) (((x)+(y)-1)/(y))
#define srep(i,s,t) for (int i = s; i < t; ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const int mod = 1000000007;
// const int mod = 998244353;

int trans(string s) {
  int res = 0;
  rep(i, s.size()) {
    res += pow(10, (int)s.size() -1 - i) * (s[i] - '0');
  }
  return res;
}

int main() {
  int n, k;
  cin >> n >> k;
  while (k--) {
    string g = to_string(n);
    sort(ALL(g));
    string g2 = g;
    reverse(ALL(g));
    string g1 = g;
    int f = trans(g1) - trans(g2);
    n = f;
  }
  cout << n << endl;
}
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define ri int
typedef long long ll;
const int maxn=110;
int a[maxn],b[maxn][maxn],n;
ll ans,x;
int main(){
	scanf("%d%lld",&n,&x);
	for(ri i=1;i<=n;++i)scanf("%d",a+i);
	sort(a+1,a+n+1);
	ll ans=x-a[n];
	for(ri i=2;i<=n;++i){
		memset(b,0,sizeof b);
		for(ri j=1;j<=n;++j){
			int tmp=a[j]%i;
			for(ri l=i;l>1;--l)
				for(ri k=0;k<i;++k)
					if(b[k][l-1])
						b[(k+tmp)%i][l]=max(b[(k+tmp)%i][l],b[k][l-1]+a[j]);
			b[tmp][1]=max(b[tmp][1],a[j]);
		}
		if(b[x%i][i])ans=min(ans,(x-b[x%i][i])/i);
	}
	printf("%lld",ans);
	return 0;
}