#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
int ans, n, m;
int a[maxn], f[maxn], A[maxn];
inline int read() {
  int x = 0;
  char ch = getchar();
  bool flag = 0;
  while (ch < '0' || ch > '9') {
    if (ch == '-') flag = 1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
    x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
  if (flag)
    return -x;
  else
    return x;
}
bool judge(int x) {
  f[1] = 0;
  for (int i = 2; i <= n; i++) {
    f[i] = f[i - 1];
    if (f[i - 1] >= A[i] - 1)
      f[i] = A[i] + x;
    else if (f[i - 1] >= A[i] - x - 1)
      f[i] = max(f[i], A[i]);
    if (i > 2 && f[i - 2] >= A[i] - x - 1) f[i] = max(f[i], A[i - 1] + x);
  }
  if (f[n] >= m - 1 || f[n] + x - A[1] >= m - 1) return 1;
  f[2] = max(x, A[2]);
  for (int i = 3; i <= n; i++) {
    f[i] = f[i - 1];
    if (f[i - 1] >= A[i] - 1)
      f[i] = A[i] + x;
    else if (f[i - 1] >= A[i] - x - 1)
      f[i] = max(f[i], A[i]);
    if (i > 2 && f[i - 2] >= A[i] - x - 1) f[i] = max(f[i], A[i - 1] + x);
  }
  if (f[n] >= m - 1 || f[n] + x - A[2] >= m - 1) return 1;
  return 0;
}
int main() {
  m = read(), n = read();
  if (n == 1) {
    printf("%d", m - 1);
    return 0;
  }
  for (int i = 1; i <= n; i++) a[i] = read(), a[i + n] = a[i] + m;
  sort(a + 1, a + n + n + 1);
  int maxl = 0;
  for (int i = 1; i <= n; i++) maxl = max(maxl, a[i + 1] - a[i] - 1);
  for (int i = 1; i <= n; i++)
    if (maxl == a[i + 1] - a[i] - 1) {
      for (int j = 1; j <= n; j++) A[j] = a[i + j];
      for (int j = n; j >= 1; j--) A[j] -= A[1];
      break;
    }
  int l = 1, r = maxl;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (judge(mid))
      ans = mid, r = mid - 1;
    else
      l = mid + 1;
  }
  printf("%d\n", ans);
  return 0;
}
