/*
* Maximize a-b
*/
#include <stdio.h>
#include <stdlib.h>
int maximize(int number); /* 9876543210 */
int minimize(int number); /* 1023456789 */
int get_count_of_digits(int num);
int cmp(const void *a, const void *b);
void itoa(int number, int length, int arr[]);
int atoi_(int s[], int length);
void reverse(int s[], int length);
int main()
{
int a,b;
int result_a, result_b;
scanf("%d\n%d", &a, &b);
result_a = (a<0) ? minimize(a) : maximize(a);
result_b = (b<0) ? maximize(b) : minimize(b);
printf("%d\n", result_a - result_b);
return 0;
}
int minimize(int number){
int sign,zeros = 0, flag = 0, j = 0;
int length = get_count_of_digits(number);
int string[length], result[length], res;
if ((sign = number) < 0)
number = -number;
if (number == 0)
return 0;
itoa(number, length, string);
qsort(string, length, sizeof(int), cmp);
for (int i = 0; i < length; i++){
if (string[i] != 0){
flag = 1;
result[j++] = string[i];
}
if (string[i] == 0 && flag == 0)
zeros++;
else if (flag == 1 && zeros){
while (zeros-- > 0)
result[j++] = 0;
}
}
res = atoi_(result, length);
if (sign < 0)
res = -res;
return res;
}
int maximize(int number){
int sign,zeros = 0, flag = 0, j = 0;
int length = get_count_of_digits(number);
int string[length], result;
if ((sign = number) < 0)
number = -number;
if (number == 0)
return 0;
itoa(number, length, string);
qsort(string, length, sizeof(int), cmp);
reverse(string, length);
result = atoi_(string, length);
if (sign < 0)
result = -result;
return result;
}
int cmp(const void *a, const void *b) {
return *(int*)a - *(int*)b;
}
int get_count_of_digits(int num){
int count = (num == 0) ? 1 : 0;
while (num){
count++;
num /= 10;
}
return count;
}
void itoa(int n, int length, int arr[]){
int i = 0;
do {
arr[i++] = n % 10;
} while ((n/=10) > 0);
arr[i] = '\0';
reverse(arr, length);
}
void reverse(int s[], int length)
{
int i, j;
int c;
for (i = 0, j = length-1; i<j; i++, j--) {
c = s[i];
s[i] = s[j];
s[j] = c;
}
}
int atoi_(int s[], int length){
int n = 0;
for (int i = 0; i<length;i++){
n *= 10;
n += s[i];
}
return n;
}