function Main(input) {
    // 1行目がinput[0], 2行目がinput[1], …に入る
    var S = input.split('\n');
    var K = S[0].split(' ')[0];
    var N = S[0].split(' ')[1];
    var A = S[1].split(' ');
    var count = 0;
    for (var i = 0; i < N; i++) {
        var sa = A[i] - A[i + 1];
        if (Math.abs(sa) > count) {
            count = Math.abs(sa);
        }
    }
    if (K - (A[N - 1] - A[0]) > count) {
        count = K - (A[N - 1] - A[0]);        
    }
    console.log(K - count);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));