#include <iostream>
#include <vector>
#include <chrono>
#include <random>
#include <algorithm>

std::mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count());

int main() {
	std::ios_base::sync_with_stdio(false); std::cin.tie(NULL);
	long long l;
	int n;
	std::cin >> l >> n;
	std::vector<long long> a(n + 1, 0);
	for(int i = 1; i <= n; i++) {
		std::cin >> a[i];
	}
	std::sort(a.begin(), a.end());
	std::vector<long long> sum(n + 1, 0);
	for(int i = 1; i <= n; i++) {
		sum[i] = sum[i-1] + a[i];
	}
	long long ans = 0;
	// solve getting left first
	for(int i = 1; i <= n; i++) {
		int le = std::min(i, n - i + 1);
		int ri = le - 1;
		//std::cout << "(" << le << ", " << ri << ")\n";
		ans = std::max(ans, 2 * (sum[i] - sum[i-le]) + 2 * (l * ri - sum[i+ri] + sum[i]) - a[i]);
		//std::cout << "1, " << i << " got " << ans << "\n";
	}
	// solve balanced
	for(int i = 1; i < n; i++) {
		int le = std::min(i, n - i);
		int ri = le;
		//std::cout << "got (" << le << ", " << ri << ")\n";
		//std::cout << "2 * " << (sum[i] - sum[i-le]) << " + 2 * (" << (l * ri) - (sum[i+ri] - sum[i]) << ") - (" << a[i] << ", " << l - a[i+ri] << ")\n";
		ans = std::max(ans, 2 * (sum[i] - sum[i-le]) + 2 * (l * ri - sum[i+ri] + sum[i]) - std::min(a[i], l - a[i+1]));
		//std::cout << "2, " << i << " got " << ans << "\n";
	}
	for(int i = 1; i <= n; i++) {
		a[i] = l - a[i];
	}
	std::sort(a.begin(), a.end());
	for(int i = 1; i <= n; i++) {
		sum[i] = sum[i-1] + a[i];
	}
	// solve getting left first
	for(int i = 1; i <= n; i++) {
		int le = std::min(i, n - i + 1);
		int ri = le - 1;
		ans = std::max(ans, 2 * (sum[i] - sum[i-le]) + 2 * (l * ri - sum[i+ri] + sum[i]) - a[i]);
		//std::cout << "3, " << i << " got " << ans << "\n";
	}
	// solve balanced
	for(int i = 1; i < n; i++) {
		int le = std::min(i, n - i);
		int ri = le;
		ans = std::max(ans, 2 * (sum[i] - sum[i-le]) + 2 * (l * ri - sum[i+ri] + sum[i]) - std::min(a[i], l - a[i+1]));
		//std::cout << "4, " << i << " got " << ans << "\n";
	}
	/*// solve getting left, right
	{
		int left = 1;
		int right = n;
		int on = 0;
		long long cur = 0;
		bool getLeft = true;
		while(left <= right) {
			std::cout << "on " << getLeft << ", [" << left << ", " << right << "] with " << cur << '\n';
			if(getLeft) {
				// get best answer continuing to other side
				ans = std::max(ans, cur + (a[on] - a[left] + l) % l);
				if(left)
				cur += (l - a[on]) % l;
				cur += a[left++];
				on = left-1;
			} else {
				// get best answer continuing
				ans = std::max(ans, cur + a[right] - a[on]);
				cur += a[on];
				cur += l - a[right--];
				on = right+1;
			}
			std::cout << "ans is now " << ans << "\n";
			getLeft = !getLeft;
		}
		ans = std::max(ans, cur);
	}
	// solve getting right, left
	{
		int left = 1;
		int right = n;
		int on = 0;
		long long cur = 0;
		bool getLeft = false;
		while(left <= right) {
			std::cout << "on " << getLeft << ", [" << left << ", " << right << "] with " << cur << '\n';
			if(getLeft) {
				// get best answer continuing to other side
				ans = std::max(ans, cur + (a[on] - a[left] + l) % l);
				cur += (l - a[on]) % l;
				cur += a[left++];
				on = left-1;
			} else {
				// get best answer continuing
				ans = std::max(ans, cur + a[right] - a[on]);
				cur += a[on];
				cur += l - a[right--];
				on = right+1;
			}
			std::cout << "ans is now " << ans << "\n";
			getLeft = !getLeft;
		}
		ans = std::max(ans, cur);
	}*/
	std::cout << ans << '\n';
}

Measured memory_bytes: 3456