N,K = map(int,input().split())
pots = list(map(int,input().split()))
debug = False
# spiral
width = 1
height = 1
remain = N-1
while remain >= height:
remain -= height
if width == height:
height += 1
else:
width += 1
board1 = [[0]*width for _ in range(height)]
dirs = [[-1,0],[0,1],[1,0],[0,-1]]
turns = 0
while True:
# 최소에 1 추가
min_fish = min(pots)
for i in range(len(pots)):
if pots[i] == min_fish:
pots[i] += 1
# 첫 번째 배열
board1 = [[0]*height for _ in range(width)]
x,y = width-1,0
head = 0
for fish in reversed(pots[:N-remain]):
board1[x][y] = fish
dx,dy = dirs[head]
if not (0<=x+dx<width and 0<=y+dy<height) or board1[x+dx][y+dy]!=0:
head = (head+1)%4
dx,dy = dirs[head]
x,y = x+dx, y+dy
if debug:
print('board1')
print(*board1, sep='\n')
# 첫 번째 정리
new_board1 = [[0]*height for _ in range(width)]
new_remain1 = [0]*(remain+1)
for i in range(width):
for j in range(height):
dir_list = []
if i!=width-1:
dir_list.append([1,0])
if j!=height-1:
dir_list.append([0,1])
for di,dj in dir_list:
d = board1[i][j]-board1[i+di][j+dj]
d = abs(d)//5 if d>=0 else -(abs(d)//5)
new_board1[i][j] -= d
new_board1[i+di][j+dj] += d
for i in range(remain):
d = pots[-remain-1+i]-pots[-remain+i]
d = abs(d)//5 if d>=0 else -(abs(d)//5)
new_remain1[i] -= d
new_remain1[i+1] += d
if debug:
print('board1 - after')
print(*board1, sep='\n')
# 숫자 정리
for i in range(width):
for j in range(height):
board1[i][j] += new_board1[i][j]
pots[i*height+j] = board1[i][j]
board1[-1][0] += new_remain1[0]
pots[(width-1)*height] = board1[-1][0]
for i in range(remain):
pots[i-remain] += new_remain1[i+1]
if debug:
print("first", pots)
# 두 번째 배열
board2 = [[0]*(N//4) for _ in range(4)]
board2[0] = pots[N//2+N//4-1:N//2-1:-1]
board2[1] = pots[N//4:N//2]
board2[2] = pots[N//4-1::-1]
board2[3] = pots[N//2+N//4:]
# 두 번째 정리
new_board2 = [[0]*(N//4) for _ in range(4)]
for i in range(4):
for j in range(N//4):
dir_list = []
if i!=3:
dir_list.append([1,0])
if j!=N//4-1:
dir_list.append([0,1])
for di,dj in dir_list:
d = board2[i][j]-board2[i+di][j+dj]
d = abs(d)//5 if d>=0 else -(abs(d)//5)
new_board2[i][j] -= d
new_board2[i+di][j+dj] += d
# 숫자 정리
for i in range(4):
for j in range(N//4):
pots[4*j+(3-i)] = board2[i][j] + new_board2[i][j]
if debug:
print("second", pots)
turns += 1
if max(pots) - min(pots) <= K:
print(turns)
exit()