#include <bits/stdc++.h>
const int N = 2e5 + 54;
int k, n, a[N], ans;
int main() {
	scanf("%d%d%d", &k, &n, &a[1]);
	for (int i = 2; i <= n; ++i) scanf("%d", &a[i]), ans = std::max(ans, a[i] - a[i - 1]);
	ans = std::max(ans, a[1] + k - a[n]);
	printf("%d\n", k - ans);
}
