#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
long long n, m, a[N], p[N], f[N], l, r, ans;
inline long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + (ch ^ 48);
    ch = getchar();
  }
  return x * f;
}
inline void init() {
  int now = 1;
  for (int i = 2; i <= n; i++)
    if (a[i + 1] - a[i] > a[now + 1] - a[now]) now = i;
  r = a[now + 1] - a[now] - 1;
  for (int i = 1; i <= n; i++) p[i] = a[i + now];
  long long tmp = p[1];
  for (int i = 1; i <= n; i++) p[i] -= tmp;
}
inline bool check(long long x) {
  f[1] = 0;
  for (int i = 2; i <= n; i++) {
    f[i] = f[i - 1];
    if (f[i - 1] >= p[i] - 1) f[i] = max(f[i], p[i] + x);
    if (f[i - 1] >= p[i] - x - 1) f[i] = max(f[i], p[i]);
    if (i > 2 && f[i - 2] >= p[i] - x - 1) f[i] = max(f[i], p[i - 1] + x);
  }
  if (f[n] >= m - x - 1) return 1;
  f[2] = max(p[2], x);
  for (int i = 3; i <= n; i++) {
    f[i] = f[i - 1];
    if (f[i - 1] >= p[i] - 1) f[i] = max(f[i], p[i] + x);
    if (f[i - 1] >= p[i] - x - 1) f[i] = max(f[i], p[i]);
    if (f[i - 2] >= p[i] - x - 1) f[i] = max(f[i], p[i - 1] + x);
  }
  if (f[n] >= min(m - 1, m + p[2] - x - 1)) return 1;
  return 0;
}
int main() {
  m = read();
  n = read();
  for (int i = 1; i <= n; i++) {
    a[i] = read();
    a[i + n] = a[i] + m;
  }
  if (n == 1) {
    printf("%lld\n", m - 1);
    return 0;
  }
  init();
  while (l <= r) {
    long long mid = (l + r) >> 1;
    if (check(mid))
      ans = mid, r = mid - 1;
    else
      l = mid + 1;
  }
  printf("%lld\n", ans);
  return 0;
}
