Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

n,k = map(int,input().split())
a = list(map(int,input().split()))

for i in range(n):
    a[i] -= 1
    
visited = [0]
now = 0
flag = 0

for i in range(k):
    now = a[now]
    
    if now in set(visited):
        loop_start = now
        flag = 1
        break
        
    else:
        visited.append(now)
        
if flag == 1:
    loop = visited[visited.index(loop_start):]
    m = len(loop)
    
    now = loop[(k-(len(visited)-m))%m]
    
print(now + 1)

### FIXED CODE ###

n,k = map(int,input().split())
a = list(map(int,input().split()))

for i in range(n):
    a[i] -= 1
    
visited = [-1] * n
now = 0

for i in range(k):
    if visited[now] != -1:#訪れたことがあるか
        loop = i - visited[now]   #ループの大きさ
        k = (k-(i-loop)) % loop
        
        for _ in range(k):
            now = a[now]
        
        break
        
    visited[now] = i
    now = a[now] 
        
print(now + 1)
### BUGGY CODE ###

from collections import deque

n = int(input())
dll = deque()

for i in range(n):
    input_line = [str(s) for s in input().split()]
    if input_line[0][0] == "i":
        dll.appendleft(int(input_line[1]))
    elif input_line[0] == "delete":
        try:
            dll.remove(int(input_line[1]))
        except:
            pass
    elif input_line[0][6] == "F":
        dll.popleft()
    else:
        dll.pop()
        
print(*dll)

### FIXED CODE ###

from collections import deque
   
n = int(input())
dll = deque()
   
for i in range(n):
    input_line = input().split()
    if input_line[0] == "insert":
        dll.appendleft(input_line[1])
    elif input_line[0] == "delete":
        try:
            dll.remove(input_line[1])
        except:
            pass
    elif input_line[0] == "deleteFirst":
        dll.popleft()
    else:
        dll.pop()
           
print(*dll)
### BUGGY CODE ###

def popcount(x):
    return bin(x).count("1")

N,X = open(0).read().split()
N = int(N)
X = int(X, 2)
cache = {}

for i in range(0, N):
    x = X ^ (1 << (N - 1 - i))
    nums = []
    ans = 0
    while x != 0:
        if x in cache:
            ans += cache[x]
            break
        y = popcount(x)
        nums.append(x)
        x = x % y
        ans += 1
    for j, n in enumerate(nums):
        cache[n] = ans - j
    print(ans)

### FIXED CODE ###

def popcount(x):
    return bin(x).count("1")

N, X = open(0).read().split()
N = int(N)
XS = list(X)
X = int(X, 2)

p = popcount(X)
xi = X % (p + 1)
if p == 1:
    xd = 0
else:
    xd = X % (p - 1)

for i in range(N):
    if XS[i] == "1":
        if p == 1:
            print(0)
            continue
        else:
            k = pow(2, N - 1 - i, p - 1)
            x = (xd - k) % (p - 1)
    else:
        k = pow(2, N - 1 - i, p + 1)
        x = (xi + k) % (p + 1)
    ans = 1
    while x != 0:
        x %= popcount(x)
        ans += 1
    print(ans)
### BUGGY CODE ###

n = int(input())
ls = [int(elem) for elem in input().split()]
ls = sorted(ls)

res = 0
for i, elem in enumerate(ls[:-2]):
    for j, elem1 in enumerate(ls[i+1:]):
        for k, elem2 in enumerate(ls[i+j+2:]):
            if elem2 < (elem + elem1):
                res += 1
            else:
                break
print(res)

### FIXED CODE ###

import bisect

n = int(input())
ls = [int(elem) for elem in input().split()]
ls = sorted(ls)

cnt = 0
for i in range(n-2):
    for j in range(i+1, n-1):
        k = bisect.bisect_left(ls, ls[i] + ls[j])
        k -= 1
        cnt += k - j
print(cnt)
### BUGGY CODE ###

import queue
h,w=map(int,input().split())
maze=[]
def func(n):
    if n=="#":
        return -1
    else:
        return 0


for i in range(h):
    row=input()
    maze.append(row)
#print(maze)
root=[[-1 for i in range(h*w)] for i in range(h*w)]
for i in range(h):
    for j in range(w):
       # print(maze[i][j])
        if maze[i][j]==".":
            now=w*i+j
            hidari=w*i+j-1
            migi=w*i+j+1
            ue=w*(i-1)+j
            sita=w*(i+1)+j
            if j>0:
                if maze[i][j-1]!="#":
                    root[now][hidari]=0
            if i+1<h:
                if maze[i+1][j]!="#":
                    root[now][sita]=0
            if j+1<w:
                if maze[i][j+1]!="#":
                    root[now][migi]=0
            if 0<i:
                if maze[i-1][j]!="#":
                    root[now][ue]=0
        else:
            now=w*i+j
            now=w*i+j
            hidari=w*i+j-1
            migi=w*i+j+1
            ue=w*(i-1)+j
            sita=w*(i+1)+j
            if j>0:
                root[now][hidari]=-1
            if i+1<h:
                root[now][sita]=-1
            if j+1<w:
                root[now][migi]=-1
            if 0<i:
                root[now][ue]=-1
#print(root)
max=0
for start in range(h*w):
    for goal in range(h*w):
        
        if start==goal:
            continue
        dist=[-1]*(h*w)
        now=start
        dist[start]=0
        visted=[0]*(h*w)
        toVis=queue.Queue()
        visted[now]=1
        for i in range(h*w):
            if root[now][i]!=-1:
                toVis.put(i)
                dist[i]=dist[now]+1
        while toVis.empty()!=True and now!=goal:
            now=toVis.get()
            
            visted[now]=1
            for i in range(h*w):
                if root[now][i]!=-1 and visted[i]!=1:
                    toVis.put(i)
                    dist[i]=dist[now]+1
        #print("s:",start,"g:",goal,"len",dist[goal])
        if max<dist[goal]:
            max=dist[goal]
print(max)
        




### FIXED CODE ###

h,w=map(int,input().split())
n=h*w
inf=10**6
field=[]
for i in range(h):
    field.append(input())
dist=[[inf]*n for i in range(n)]
for i in range(h):
    for j in range(w):
        if field[i][j]=="#":continue
        if j+1<w and field[i][j+1]!="#":
            dist[i*w+j][i*w+j+1]=1
            dist[i*w+j+1][i*w+j]=1
        if i+1<h and field[i+1][j]!="#":
            dist[i*w+j][(i+1)*w+j]=1
            dist[(i+1)*w+j][i*w+j]=1
for i in range(n):
    for j in range(n):
        for k in range(n):
            dist[j][k]=min(dist[j][k],dist[j][i]+dist[i][k])
ans=0
for i in range(n):
    for j in range(n):
        if i==j:
            continue
        if dist[i][j]==inf:
            continue
        ans=max(ans,dist[i][j])
print(ans)
### BUGGY CODE ###

n=int(input())

point=0
for c in range(1,n):
  a=1
  while n-c>=a:
    if (n-c)%a==0:
      point+=1
    a+=1
    
print(point)

### FIXED CODE ###

n = int(input())
ans = 0
for a in range(1, n):
  ans += (n - 1) // a
print(ans)
### BUGGY CODE ###

N = int(input())
A = [int(k) for k in input().split(' ')]

from collections import Counter 
import math 

res = [] # solution for each key in A
res_list = {} # solution for each value in A

# counter ver
A_c = Counter(A)
l = len(A_c)

def ncr(j):
  return math.factorial(j) // math.factorial(2) // math.factorial(j - 2) if j >= 2 else 0

# store ncr for each value 
combs = {k: ncr(v) for k, v in A_c.items()}

s = sum(combs.values())
  
for m in A_c.keys():
  res_list[m] = s - combs[m] + ncr(A_c[m] - 1)

for k in range(N):
  res.append(res_list[A[k]])
print('\n'.join([str(s) for s in res]))

### FIXED CODE ###

N = int(input())
A = [int(k) for k in input().split(' ')]

from collections import Counter 
import math 

res = [] # solution for each key in A
res_list = {} # solution for each value in A

# counter ver
A_c = Counter(A)
l = len(A_c)

def ncr(j):
  return int(j * (j-1) / 2) if j >= 2 else 0

# store ncr for each value 
combs = {k: ncr(v) for k, v in A_c.items()}

s = sum(combs.values())
  
for m in A_c.keys():
  res_list[m] = s - combs[m] + ncr(A_c[m] - 1)

for k in range(N):
  res.append(res_list[A[k]])
print('\n'.join([str(s) for s in res]))
### BUGGY CODE ###

k = int(input())
# a,bの最大公約数


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


gcdl = [[0]*k*2 for _ in range(k*2)]
for a in range(1, k+1):
    for b in range(1, k+1):
        gcdl[a][b] = gcd(a, b)

ansl = [[[-1]*k*2 for _ in range(k*2)] for _ in range(k*2)]
ans = 0
for a in range(1, k+1):
    for b in range(1, k+1):
        for c in range(1, k+1):
            if ansl[a][b][c] == -1:
                t = gcd(c, gcdl[a][b])
                ansl[a][b][c] = t
                ansl[a][c][b] = t
                ansl[b][a][c] = t
                ansl[b][c][a] = t
                ansl[c][b][a] = t
                ansl[c][a][b] = t
            else:
                t = ansl[a][b][c]
            ans += t
print(ans)


### FIXED CODE ###

k = int(input())
# a,bの最大公約数


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


gcdl = [[0]*k*2 for _ in range(k*2)]
for a in range(1, k+1):
    for b in range(1, k+1):
        gcdl[a][b] = gcd(a, b)

ansl = [[[-1]*k*2 for _ in range(k*2)] for _ in range(k*2)]
ans = 0
for a in range(1, k+1):
    for b in range(1, k+1):
        for c in range(1, k+1):
            if ansl[a][b][c] == -1:
                t = gcd(c, gcdl[a][b])
                ansl[a][b][c] = t
                ansl[a][c][b] = t
                ansl[b][a][c] = t
                ansl[b][c][a] = t
                ansl[c][b][a] = t
                ansl[c][a][b] = t
            else:
                t = ansl[a][b][c]
            ans += t
print(ans)
### BUGGY CODE ###

def main():
    from collections import deque
    import sys
    readline = sys.stdin.buffer.readline

    h, w = map(int, readline().split())
    c = list(map(int, readline().split()))
    d = list(map(int, readline().split()))
    s = ['#'*(w+4)]*2 + ['#'*2 + readline().rstrip().decode('utf-8') + '#'*2 for _ in range(h)] + ['#'*(w+4)]*2

    c = [i-1+2 for i in c]
    d = [i-1+2 for i in d]

    t0 = [(0, 1), (0, -1), (1, 0), (-1, 0)]
    t1 = []
    for i in range(-2, 3):
        for j in range(-2, 3):
            t1.append((i, j))
    for i in t0:
        t1.remove(i)
    t1.remove((0, 0))

    check = [[-1]*(w+4) for _ in range(h+4)]
    q = deque()
    q.appendleft((c[0], c[1], 0))

    while q:
        y, x, b = q.pop()
        if y == d[0] and x == d[1]:
            print(b)
            exit()
        if check[y][x] == -1:
            check[y][x] = b
            for dy, dx in t0:
                ydy, xdx = y+dy, x+dx
                if s[ydy][xdx] == '.' and check[ydy][xdx] == -1:
                    q.append((ydy, xdx, b))
            for dy, dx in t1:
                ydy, xdx = y+dy, x+dx
                if s[ydy][xdx] == '.' and check[ydy][xdx] == -1:
                    q.appendleft((ydy, xdx, b+1))
    print(-1)

main()

### FIXED CODE ###

from collections import deque

h, w = map(int, input().split())
c = list(map(int, input().split()))
d = list(map(int, input().split()))
s = [list(input()) for _ in range(h)]

c = [i-1 for i in c]
d = [i-1 for i in d]

t0 = [(0, 1), (0, -1), (1, 0), (-1, 0)]
t1 = []
for i in range(-2, 3):
    for j in range(-2, 3):
        t1.append((i, j))
for i in t0:
    t1.remove(i)
t1.remove((0, 0))

check = [[-1]*w for _ in range(h)]
q = deque()
q.appendleft((c[0], c[1], 0))

while q:
    y, x, b = q.pop()
    if x == d[1] and y == d[0]:
        print(b)
        exit()
    if check[y][x] == -1:
        check[y][x] = b
        for dy, dx in t0:
            ydy, xdx = y+dy, x+dx
            if (0 <= xdx < w) and (0 <= ydy < h):
                if s[ydy][xdx] == '.' and check[ydy][xdx] == -1:
                    q.append((ydy, xdx, b))
        for dy, dx in t1:
            ydy, xdx = y+dy, x+dx
            if (0 <= xdx < w) and (0 <= ydy < h):
                if s[ydy][xdx] == '.' and check[ydy][xdx] == -1:
                    q.appendleft((ydy, xdx, b+1))
print(-1)
### BUGGY CODE ###

n = int(input())
L = sorted(list(map(int, input().split())))
def isOK(target,a,b):
  return target < a+b

def bin_search(a,b):
  left = 1
  right = n
  while abs(right-left)>1:
    mid = (left+right)//2
    if isOK(L[mid],a,b):
      left = mid
    else:
      right = mid
  return left
ans = 0
for i in range(n-2):
  for j in range(i+1,n):
    a,b = L[i],L[j]
    ans += max(0, bin_search(a,b) - j)
      
print(ans)



### FIXED CODE ###

n = int(input())
L = sorted(list(map(int, input().split())))
def isOK(target,a,b):
  return target < a+b

def bin_search(a,b):
  left = 1
  right = n
  while abs(right-left)>1:
    mid = (left+right)//2
    if isOK(L[mid],a,b):
      left = mid
    else:
      right = mid
  return left
ans = 0
for i in range(n-2):
  for j in range(i+1,n):
    a,b = L[i],L[j]
    ans += max(0, bin_search(a,b) - j)
      
print(ans)
### BUGGY CODE ###

n,k = map(int,input().split())
h = [int(i) for i in input().split()]
inf = 10**9
dp = [inf] * n
dp[0] = 0

for i in range(n-1):
    for j in range(1,k+1):
        if i+j < n:
            dp[i+j] = min(dp[i+j], dp[i] + abs(h[i] - h[i+j])) 

print(dp[n-1])


### FIXED CODE ###

n,k = map(int,input().split())
h = [int(i) for i in input().split()]
inf = 10**9
dp = [inf] * n
dp[0] = 0

for i in range(n-1):
    for j in range(1,k+1):
        if i+j < n:
            dp[i+j] = min(dp[i+j], dp[i] + abs(h[i] - h[i+j])) 

print(dp[n-1])
### BUGGY CODE ###

n = int(input())
s = []
for i in range(n):
    s.append(input())

b = [False] * n
ans = 0
count = 1

def ana(s1, s2):
    b = [False] * len(s1)
    for i in range(len(s1)):
        for j in range(len(s2)):
            if b[j]:
                continue
            if s1[i] == s2[j]:
                b[j] = True
    for i in range(len(s1)):
        if not b[i]:
            return False
    return True

for i in range(n):
    if b[i]:
        continue
    for j in range(i + 1, n):
        if ana(s[i], s[j]):
            count += 1
            b[j] = True
    ans += count * (count - 1) / 2
    count = 1
    b[i] = True

print(int(ans))


### FIXED CODE ###

n = int(input())
s = []
for i in range(n):
    s.append(''.join(sorted(list(input()))))
s.sort()

ans = 0
count = 1
s_pre = s[0]

for i in range(1, n):
    if s_pre == s[i]:
        count += 1
    else:
        ans += int(count * (count - 1) / 2)
        s_pre = s[i]
        count = 1

ans += int(count * (count - 1) / 2)
print(int(ans))
### BUGGY CODE ###

import sys, os, math, bisect, itertools, collections, heapq, queue, copy, array

# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
# from decimal import Decimal
# from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N, K = il()
    A = il()

    tmp = 0
    for k in range(K, N + 1):
        B = A[k - K:k]
        ret = 1
        for b in B:
            ret *= b

        if tmp != 0 and tmp < ret:
            print('Yes')
        elif tmp != 0 and tmp >= ret:
            print('No')

        tmp = ret


if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys, os, math, bisect, itertools, collections, heapq, queue, copy, array

# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
# from decimal import Decimal
# from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N, K = il()
    A = il()

    for k in range(K, N):
        if A[k - K] < A[k]:
            print('Yes')
        else:
            print('No')


if __name__ == '__main__':
    main()
### BUGGY CODE ###



def main():
    import sys
    input = sys.stdin.readline
    
    H,W=map(int, input().split())
    S=[]
    
    import queue
    q=queue.Queue()
    
    for i in range(H):
        S.append(list(input()))
    
    for i in range(H):
        for j in range(W):
            if S[i][j]=="#":
                q.put((i,j))
    
    dx=[0,0,1,-1]
    dy=[1,-1,0,0]
    dis=[[0]*W for _ in range(H)]
    
    while not q.empty():
        ii,jj=q.get()
        d=dis[ii][jj]
        for k in range(4):
            nxt_i=ii+dx[k]
            nxt_j=jj+dy[k]
            
            if 0<=nxt_i<=H-1:
                if 0<=nxt_j<=W-1:
                    if S[nxt_i][nxt_j]==".":
                        q.put((nxt_i,nxt_j))
                        S[nxt_i][nxt_j]="#"
                        dis[nxt_i][nxt_j]=d+1
    print(d)

                
    
            

main()


### FIXED CODE ###

from collections import deque

H, W = map(int, input().split())
A = [list(input()) for _ in range(H)]

black_idx = []
for h in range(H):
    for w in range(W):
        if A[h][w] == "#":
            black_idx.append([h,w])

distance = [[float("inf")]*W for _ in range(H)]
for b in black_idx:
    distance[b[0]][b[1]] = 0

d = deque(black_idx)
ans = 0

while d:
    y, x = d.popleft()
    for new_y, new_x in ([y+1, x], [y, x+1], [y-1, x], [y, x-1]):
        if 0 <= new_y <= H-1 and 0 <= new_x <= W-1 and distance[y][x] + 1 < distance[new_y][new_x]:
            distance[new_y][new_x] = distance[y][x] + 1
            ans = max(ans, distance[y][x] + 1)
            d.append([new_y, new_x])

print(ans)
### BUGGY CODE ###

# -*- coding: utf-8 -*-
n=int(input())
for val in range(1,n+1):
  ans=0
  if val<100:
    x=val
  else:
    x=100
  for i in range(1,x+1):
    for j in range(1,i+1):
      for k in range(1,j+1):
        sumg=(i+j)**2+(j+k)**2+(k+i)**2
        if sumg==2*val:
          if i==j and j==k:
            ans+=1
          elif i!=j and j!=k and k!=i:
            ans+=6
          else:
            ans+=3
  print(ans)

### FIXED CODE ###

# -*- coding: utf-8 -*-
n=int(input())
ans=[0 for i in range(10500)]
for i in range(1,105):
  for j in range(1,i+1):
    for k in range(1,j+1):
      sumg=(i+j)**2+(j+k)**2+(k+i)**2
      if sumg<21000:
        if i==j and j==k:
          ans[int(sumg/2)]+=1
        elif i!=j and j!=k and k!=i:
          ans[int(sumg/2)]+=6
        else:
          ans[int(sumg/2)]+=3
for i in range(n):
  print(ans[i+1])
### BUGGY CODE ###

global cnt
cnt=0

def merge(A,left,mid,right):
    global cnt
    n1=mid-left
    n2=right-mid
    L=[0 for i in range(n1+1)]
    R=[0 for i in range(n2+1)]

    for i in range(n1):
        L[i]=A[left+i]
    for j in range(n2):
        R[j]=A[mid+j]
    L[n1]=float("inf")
    R[n2]=float("inf")
    i=0
    j=0
    for k in range(left,right):
        if L[i]<=R[j]:
            A[k]=L[i]
            i=i+1
            cnt+=1
        else:
            A[k]=R[j]
            j=j+1
            cnt+=1

def mergeSort(A,left,right):
    if left+1<right:
        mid=(int)((left+right)/2)
        mergeSort(A,left,mid)
        mergeSort(A,mid,right)
        merge(A,left,mid,right)

n=int(input())
S=list(map(int,input().split()))


mergeSort(S,0,n)
print(*S)
print(cnt)



### FIXED CODE ###

global cnt
cnt=0

def merge(A,left,mid,right):
    L=A[left:mid]
    R=A[mid:right]
    L.append(float("inf"))
    R.append(float("inf"))
    
    i=0
    j=0
    for k in range(left,right):
        global cnt
        cnt+=1
        if L[i]<=R[j]:
            A[k]=L[i]
            i=i+1
        else:
            A[k]=R[j]
            j=j+1

def mergeSort(A,left,right):
    if left+1<right:
        mid=(int)((left+right)/2)
        mergeSort(A,left,mid)
        mergeSort(A,mid,right)
        merge(A,left,mid,right)

n=int(input())
S=list(map(int,input().split()))

mergeSort(S,0,n)
print(*S)
print(cnt)
### BUGGY CODE ###

from collections import Counter
def main():
    n = int(input())
    a = Counter(map(int, input().split()))
    dic = {}

    def exp(i,j,k):
        if i + j + k == 0:
            return 0
        key = '{}-{}-{}'.format(i,j,k)
        if key in dic:
            return dic[key]
        ans = n
        if i > 0:
            ans += i * exp(i-1,j,k)
        if j > 0:
            ans += j * exp(i+1,j-1,k)
        if k > 0:
            ans += k * exp(i,j+1,k-1)
        ans /= (i+j+k)
        dic[key] = ans
        return ans

    ans = exp(a[1],a[2],a[3])
    print(ans)

if __name__ == '__main__':
    main()

### FIXED CODE ###

from collections import Counter
import sys
input = sys.stdin.buffer.readline

def main():
    n = int(input())
    a = Counter(map(int, input().split()))
    dp = [[[.0] * (n+1) for _ in range(n+1)] for _ in range(n+1)]
    for k in range(a[3]+1):
        for j in range(a[2]+a[3]-k+1):
            for i in range(n-j-k+1):
                if i + j + k == 0:
                    continue
                tmp = n
                if i > 0:
                    tmp += i * dp[i-1][j][k]
                if j > 0:
                    tmp += j * dp[i+1][j-1][k]
                if k > 0:
                    tmp += k * dp[i][j+1][k-1]
                dp[i][j][k] = tmp / (i+j+k)
    print(dp[a[1]][a[2]][a[3]])

if __name__ == '__main__':
    main()
### BUGGY CODE ###

import sys
from collections import defaultdict
from heapq import *

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")

def main():
    to = defaultdict(list)
    n, m = map(int, input().split())
    for _ in range(m):
        l, r, c = map(int, input().split())
        l, r = l - 1, r - 1
        to[l].append([r, c])
    costs = [-1] * n
    hp = []
    heappush(hp, [0, 0])
    while hp:
        #print(hp)
        c, u = heappop(hp)
        if u == n - 1:
            print(c)
            #print(costs)
            exit()
        if costs[u] != -1: continue
        costs[u] = c
        for v, dc in to[u]:
            if costs[v] != -1: continue
            heappush(hp, [c + dc, v])
            for w in range(v - 1, u, -1):
                if costs[w] != -1: continue
                heappush(hp, [c + dc, w])

    print(-1)

main()


### FIXED CODE ###

import sys
from collections import defaultdict
from heapq import *

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")

def main():
    to = defaultdict(list)
    n, m = map(int, input().split())
    for _ in range(m):
        l, r, c = map(int, input().split())
        l, r = l - 1, r - 1
        to[l].append([r, c])
    costs = [-1] * n
    hp = []
    heappush(hp, [0, 0])
    while hp:
        # print(hp)
        c, u = heappop(hp)
        if u == n - 1:
            print(c)
            # print(costs)
            exit()
        if costs[u] != -1: continue
        costs[u] = c
        for v, dc in to[u]:
            if costs[v] != -1: continue
            heappush(hp, [c + dc, v])
        for v in range(u - 1, 0, -1):
            if costs[v] != -1: break
            heappush(hp, [c, v])
    print(-1)

main()
### BUGGY CODE ###

from decimal import Decimal

n, k = map(int, input().split())
a = list(map(Decimal, input().split()))

for i in range(n):
  a[i] = [(-1) * a[i], (-1) * a[i], 1]

import heapq
heapq.heapify(a)

for _ in range(k):
  i = heapq.heappop(a)
  i[2] += 1
  i[0] = i[1] / i[2]
  heapq.heappush(a, i)

from math import ceil
print(ceil((-1) * heapq.heappop(a)[0]))

### FIXED CODE ###

n, k = map(int, input().split())
a = list(map(int, input().split()))

# binary search
left = 1
right = 10 ** 9

while left < right:
    center = (left + right) // 2

    total = 0
    for i in a:
        if i % center == 0:
            i -= 1
        total += i//center
    
    if total > k:
        left = center + 1
    else:
        right = center

print(left)