import java.io.*; import java.util.*; import java.util.function.*; import java.util.stream.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int length = sc.nextInt(); int n = sc.nextInt(); int[] positions = new int[n]; for (int i = 0; i < n; i++) { positions[i] = sc.nextInt(); } int base = Math.abs(length - positions[n - 1] - positions[0]); Set current = new HashSet<>(); current.add(0); for (int i = 0; i < n - 1; i++) { int x = positions[i + 1] - positions[i]; Set next = new HashSet<>(); for (int y : current) { next.add(x + y); next.add(Math.abs(y - x)); } current = next; } int ans = Integer.MAX_VALUE; for (int x : current) { ans = Math.min(ans, Math.abs(base - x)); } System.out.println(ans); } } class Scanner { BufferedReader br; StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); public Scanner() { try { br = new BufferedReader(new InputStreamReader(System.in)); } catch (Exception e) { } } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } public String next() { try { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } } catch (Exception e) { e.printStackTrace(); } finally { return st.nextToken(); } } }