#include <bits/stdc++.h>
using namespace std;
int m, n, a[110000];
int low, high, mid, dp[110000];
bool vis[110000];
bool check(int T) {
  int i, j, s, p, q, u, v;
  for (j = 0; j < 2; j++) {
    dp[0] = a[0] + T + 1;
    u = 0;
    for (i = 1; i < n; i++) {
      if (a[i] > dp[i - 1] + T) break;
      if (j == 1 && i == 1)
        dp[i] = dp[i - 1];
      else {
        if (a[i] > dp[i - 1]) {
          v = i - 1;
          if (j == 1 && i - 1 == 1) v--;
          while (dp[u] + T < a[i]) u++;
          if (u != v)
            dp[i] = max(a[v] + T + 1, a[i] + 1);
          else
            dp[i] = a[i] + 1;
        } else
          dp[i] = a[i] + T + 1;
      }
    }
    if (i < n) continue;
    if ((j == 0 && dp[n - 1] >= a[0] + m) ||
        (j == 1 && dp[n - 1] >= min(a[0], a[1] - T) + m))
      return true;
  }
  for (j = 0; j < 2; j++) {
    dp[n] = a[0] + m - T - 1;
    u = n;
    for (i = n - 1; i > 0; i--) {
      if (a[i] < dp[i + 1] - T) break;
      if (j == 1 && i == n - 1)
        dp[i] = dp[i + 1];
      else {
        if (a[i] < dp[i + 1]) {
          v = i + 1;
          if (j == 1 && v == n - 1) v++;
          while (dp[u] - T > a[i]) u--;
          if (u != v)
            dp[i] = min(a[v] - T - 1, a[i] - 1);
          else
            dp[i] = a[i] - 1;
        } else
          dp[i] = a[i] - T - 1;
      }
    }
    if (i > 0) continue;
    if ((j == 0 && dp[1] <= a[0]) ||
        (j == 1 && dp[1] <= max(a[0], a[n - 1] + T - m)))
      return true;
  }
  return false;
}
int main() {
  int i, j, s, p, q;
  scanf("%d%d", &m, &n);
  if (n == 1) {
    printf("%d\n", m - 1);
    return 0;
  }
  for (i = 0; i < n; i++) scanf("%d", &a[i]);
  sort(a, a + n);
  low = 0;
  high = m - 1;
  while (low <= high) {
    mid = (low + high) >> 1;
    if (check(mid))
      high = mid - 1;
    else
      low = mid + 1;
  }
  cout << low << endl;
  return 0;
}
