import java.util.*;
 
public class Main {
	public static void main (String[] args) {
		Scanner in = new Scanner(System.in);
		
		int ollm = in.nextInt();
		int hous = in.nextInt();
		int fast = in.nextInt();
		int memo = fast;
		int second =  0;
		int last = 0;
		int now =  0;
		long sum = 0;
		long maxm = 0;
		
		for(int i = 0;i < hous -1;i++){
		   second = in.nextInt();
		   now = second - fast;
		   if(maxm < now){
		       maxm = now;
		   }
		    sum = sum + now;
		    fast = second;
		}
		
		last = ollm-(second - memo);
		sum = sum + last;
		if(maxm< last){
		    maxm = last;
		}
		
		System.out.println(sum - maxm);
      
	}
}
/tmp/hf-datasets-cache/medium/datasets/42704881117311-config-parquet-and-info-qiankunmu-Project_CodeNet-896c9d36/hub/datasets--qiankunmu--Project_CodeNet_Python800_and_Java250/snapshots/c899fde44a77ba1cc14973ed3de064e4ff3aadc7/Project_CodeNet_Java250.tar.gz