N, K = map(int, input().split()) A = [(int(x) - 1) // 2 for x in input().split()] A.append(A[0] + N) def check2(x, y, last): pos = -y for i in range(K): if (i < K - 1 or last) and pos + x >= A[i + 1]: return False pos = max(A[i], pos + x) return True def check(x): d = A[K] - A[K - 1] ng = 0 ok = d + 1 while ok - ng > 1: mid = (ok + ng) // 2 if check2(x, mid, False): ok = mid else: ng = mid return ok <= d and check2(x, ok, True) ok = 1 ng = 10 ** 18 while ng - ok > 1: mid = (ok + ng) // 2 if check(mid): ok = mid else: ng = mid print(ok * 2)