line = [input() for i in range(2)]

status = line[0].split()
fruits = line[1].split()

i = 1
total = 0
for fruit in fruits:
    i += 1
    total += int(fruit)
    if int(status[1]) < i:
        break
print(total)
