N, K = map(int, input().split()) A = list(map(int, input().split())) A2 = A[:] N2 = N * 2 N4 = N2 * 2 A2 += [i + N2 for i in A] A2 += [i + N4 for i in A] damin = N * 2 for i in range(K): if damin > A2[i + 1] - A2[i]: damin = A2[i + 1] - A2[i] damini = i start = A2[damini] + 1 end = A2[damini + 1] def check(x): for i in range(start, end, 2): now = i f = True for j in range(damini + 1, damini + K + 1): if now + x >= A2[j + 1]: f = False break now = max(now + x, A2[j] + 1) if f: return True return False lb = 1 ub = N // K + 1 while ub - lb > 1: mid = (ub + lb) // 2 if check(2 * mid): lb = mid else: ub = mid print(2 * lb)