from _collections import deque
n, k = map(int,input().split())
a = deque(list(map(int,input().split())))
robot = deque([0] * n)
cnt = 0
zero = 0
while True:
    cnt += 1
    a.rotate(1)
    robot.rotate(1)
    robot[-1] = 0
    for i in range(n-2, -1, -1):
        if robot[i] and robot[i+1] == 0 and a[i+1] > 0:
            a[i+1] -= 1
            robot[i+1] = robot[i]
            robot[i] = 0
            if a[i+1] == 0:
                zero += 1
    robot[-1] = 0
    if a[0] > 0 and robot[0] == 0:
        robot[0] = 1
        a[0] -= 1
        if a[0] == 0:
            zero += 1
    if zero >= k:
        break
print(cnt)