#include<iostream>
using namespace std;
int main()
{
int n,x,y,z;
cin >> n;
x= n/100; // stotine
y = n/10%10; // desetice
z = n%10; // jedinice
if(x>y) swap(x,y); // sortiranje
if(y>z) swap(y,z); // tri cifre
if(x>y) swap(x,y); // z, y, x u nerastucem poretku
int najveciBroj = z*100 + y*10 + x;
if(x==0) swap(x,y); // ako je broj sa jednom cifrom 0
if(x==0) swap(x,z); // ako je broj sa 2 cifre nula
int najmanjiBroj = x*100 + y*10 + z; // najmanji trocifren broj xyz
cout << najveciBroj – najmanjiBroj << endl;
return 0;
}