use std::io::{self, BufReader, Read};

// fn read_line() -> String {
//     let mut s = String::new();
//     std::io::stdin().read_line(&mut s).unwrap();
//     s
// }

// fn split_whitespace(line: String) -> Vec<u32> {
//     line.split_whitespace()
//         .map(|s| s.parse().unwrap())
//         .collect()
// }

// fn reader() -> Vec<usize> {
//     let mut buffer = String::new();
//     io::stdin().read_to_string(&mut buffer);

//     let st: Vec<&str> = buffer.lines().collect();

//     let s: Vec<&str> = st.get(1).unwrap().clone().split_terminator(" ").collect();

//     s.iter()
//         .map(|v| v.trim().parse::<usize>().unwrap())
//         .collect()
// }

// fn solver(mut hs: Vec<usize>) -> usize {
//     let mut v: Vec<usize> = vec![0; hs.len()];;

//     for i in 1..hs.len() {
//         if hs[i - 1] >= hs[i] {
//             v[i] = v[i - 1] + 1;
//         }
//     }

//     let max = v.iter().max().unwrap().clone();
//     println!("{}", max);
//     max
// }

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> IO<R, W> {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: ToString>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.to_string().as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}

fn eval_ds(ds: Vec<usize>) -> Vec<usize> {
    let mut v = Vec::new();
    for sl in ds.windows(2) {
        v.push(sl[1] - sl[0]);
    }
    v
}

fn main() {
    let mut sc = IO::new(std::io::stdin(), std::io::stdout());
    let p: usize = sc.read();
    let h_n: usize = sc.read();
    let mut ds: Vec<usize> = sc.vec(h_n);
    ds.sort();
    let last = ds.get(0).unwrap() + p;
    ds.push(last);

    let evld = eval_ds(ds);
    let max = evld.iter().max().unwrap();

    sc.write(p - max);
    // sc.write()
    // let hs = reader();

    // solver(hs);
}

#[test]
fn evls() {
    let v = vec![0, 5, 15, 20];

    let ds = eval_ds(v);
    println!("{:?}", ds);
    println!("foo");

    assert_eq!(1, 2);
}

// #[cfg(test)]
// mod tests {
//     use super::*;

//     #[test]
//     fn fst() {
//         assert_eq!(solver(vec![4, 4, 5, 6, 6, 5, 5]), 3);
//     }

//     #[test]
//     fn snd() {
//         assert_eq!(solver(vec![10, 4, 8, 7, 3]), 2);
//     }

//     #[test]
//     fn thrd() {
//         assert_eq!(solver(vec![1, 2, 3, 4]), 0);
//         assert_eq!(solver(vec![1, 2]), 0);
//     }
// }


Measured memory_bytes: 9848