N, K = map(int, input().split()) P = list(map(int, input().split())) d = [0]*N for i in range(N): d[i] = (P[i]+i) % N M = 40 step = [[0]*(M+1) for _ in range(N)] for i in range(N): step[i][0] = (d[i], int(d[i]<=i)) for i in range(1, M+1): for j in range(N): c, cy = step[j][i-1] c, cy2 = step[c][i-1] step[j][i] = (c, cy+cy2) for i in range(N): tmp = K c = i cys = 0 for j in range(M+1): if tmp % 2: c, cy = step[c][j] cys += cy tmp //= 2 print(c+1+cys*N)