function Main(n, str) {
    var arr = parseInt(str.split(''));
    for(i = 0; i < n; i++){
        var max = Math.max(max, arr[i]);
        var min = Math.min(min, arr[i]);
    }
    console.log(max - min);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));