function Main(input){
	input = input.split("\n");
	var mem = input[0].split(" ").map(Number);
	var arr = input[1].split(" ").map(Number);
	var na = [];
	for(var i=1;i<arr.length;i++){
		na.push(arr[i]-arr[i-1])
	}
	na.push(mem[0]-arr[arr.length-1]+arr[0]);
	console.log(mem[0]-Math.max.apply(null,na));
}Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());