import java.util.Scanner; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); char[] s = sc.next().toCharArray(); sc.close(); int max = 0; int min = 9; for (int i = 0; i < s.length; i++) { max = Math.max(max, s[i] - '0'); min = Math.min(min, s[i] - '0'); } System.out.println(max - min); } }