#include <bits/stdc++.h>
using namespace std;
inline void read(int &x) {
  x = 0;
  int f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  x *= f;
}
inline void judge() {
  freopen("in.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
}
const int maxn = 200005;
int n, m, M, p, s, a[maxn], b[maxn], f[maxn];
const int inf = 1 << 30;
inline bool check(int x) {
  f[1] = 1;
  f[0] = -inf;
  for (int i = (2); i <= (n); i++) {
    f[i] = -inf;
    if (f[i - 1] >= a[i] - 1) f[i] = a[i] + x;
    if (f[i - 1] >= a[i] - x - 1) f[i] = max(f[i], a[i]);
    if (f[i - 2] >= a[i] - x - 1) f[i] = max(f[i], a[i - 1] + x);
  }
  if (f[n] >= m - x) return 1;
  if (a[2] - a[1] - 1 > x + x) return 0;
  f[1] = x + 1;
  f[2] = max(a[2], f[1]);
  for (int i = (3); i <= (n); i++) {
    f[i] = -inf;
    if (f[i - 1] >= a[i] - 1) f[i] = a[i] + x;
    if (f[i - 1] >= a[i] - x - 1) f[i] = max(f[i], a[i]);
    if (f[i - 2] >= a[i] - x - 1) f[i] = max(f[i], a[i - 1] + x);
  }
  if (f[n] >= min(m, m + a[2] - x - 1)) return 1;
  return 0;
}
int main() {
  read(m);
  read(n);
  for (int i = (1); i <= (n); i++) read(a[i]), b[i] = a[i];
  for (int i = (n + 1); i <= (n << 1); i++) b[i] = b[i - n] + m;
  if (n == 1) {
    cout << m - 1;
    return 0;
  }
  M = a[1] - a[n] + m;
  p = 1;
  for (int i = (2); i <= (n); i++) {
    if (a[i] - a[i - 1] > M) {
      M = a[i] - a[i - 1];
      p = i;
    }
  }
  M--;
  s = a[1] = 1;
  for (int i = (2); i <= (n); i++) {
    p++;
    s += b[p] - b[p - 1];
    a[i] = s;
  }
  int l = 0, r = M, ans;
  while (l <= r) {
    int md = (l + r) >> 1;
    if (check(md))
      ans = md, r = md - 1;
    else
      l = md + 1;
  }
  cout << ans;
}
