#include #include using namespace std; using namespace atcoder; using ll = long long; using ull = unsigned long long; template bool chmax(T &a, const T &b) {if (a < b) {a = b; return 1;} return 0;} template bool chmin(T &a, const T &b) {if (b < a) {a = b; return 1;} return 0;} const int INF = INT_MAX / 2; const ll LINF = 1LL << 60; const vector dx = {-1, 0, 1, 0}, dy = {0, 1, 0, -1}; using mint = modint998244353; int main() { ios::sync_with_stdio(false); cin.tie(0); int l, n; cin >> l >> n; vector x; x.push_back(0); for (int i = 0; i < n; i++) { int val; cin >> val; x.push_back(val); } x.push_back(l); vector dp(n + 2, INF); dp[0] = 0; for (int i = 0; i <= n + 1; i++) { for (int j = 0; j <= i - 2; j++) { for (int k = j + 1; k <= i - 1; k++) { chmin(dp[i], abs(dp[j] + (x[k] - x[j]) - (x[i] - x[k]))); } } } cout << dp[n + 1] << '\n'; return 0; }