#include <bits/stdc++.h>
#define pb push_back
typedef long long ll;
using namespace std;
int solve(int n){
	if (n == 0)
		return 0;
	vector <int> digits;
	while (n){
		digits.pb(n % 10);
		n /= 10;
	}
	sort(digits.begin(), digits.end());
	int small = 0;
	int i = 0;
	n = digits.size();
	while (!digits[i] and i < n)
		++i;
	while (i < n){
		small = small * 10 + digits[i++];
	}
	reverse(digits.begin(), digits.end());
	int big = 0;
	for (int a : digits)
		big = big * 10 + a;
	return big - small;
}
int main() {
	int n, k;
	cin >> n >> k;
	int ans[k + 1];
	ans[0] = n;
	for (int i = 1; i <= k; ++i)
		ans[i] = solve(ans[i - 1]);
	cout << ans[k] << endl;
}
//xtwakioi! xtwddYnoi(双重含义)!
#include <bits/stdc++.h>
#define ri register
#define int long long
#define E (n+1)
#define mk make_pair
using namespace std;
inline int read()
{
    int s=0, w=1; ri char ch=getchar();
    while(ch<'0'||ch>'9') { if(ch=='-') w=-1; ch=getchar(); }
    while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48), ch=getchar();
    return s*w;
}
signed main()
{
    int a,b;
    a=read(), b=read();
    printf("%lld %lld\n",(a+b)/2,a-(a+b)/2);
    return 0;
}