import Foundation

let kn = readLine()!.componentsSeparatedByString(" ").map({ Int($0)!})
let k = kn[0]
let n = kn[1]

var inputA = readLine()!.componentsSeparatedByString(" ").map({ Int($0)!})
var minus:[Int] = inputA.map({
    if $0 > 10 {
        return $0 - 20
    } else {
        return $0
    }
})
let plusAns = inputA.maxElement()!-inputA.minElement()!
let minusAns = minus.maxElement()!-minus.minElement()!
print(min(plusAns, minusAns))