class Check():
    def __init__(self, N, number_of_truck,baggage):
        self.N = N
        self.number_of_truck = number_of_truck
        self.baggage = baggage

    def check(self, mid):
        baggage_num = 0
        for j in range(self.number_of_truck):
            baggage_sum = 0
            while(baggage_sum + self.baggage[baggage_num] <= mid):
                baggage_sum += self.baggage[baggage_num]
                baggage_num += 1
                if baggage_num == self.N:
                    return baggage_num
        return baggage_num

    def binary_search(self):
        left = 0
        right = 1000000000
        while(left + 1 < right):
            mid = int((left + right) / 2)
            ok = self.check(mid)
            if ok == self.N:
                right = mid
            else :
                left = mid
        return right

def main():
    N,number_of_truck = [int(i) for i in input().split()]
    baggage = list()
    for i in range(N):
        i = int(input())
        baggage.append(i)
    ok = Check(N,number_of_truck,baggage)
    print(ok.binary_search())

if __name__ == "__main__":
    main() class Check():
    def __init__(self, N, number_of_truck,baggage):
        self.N = N
        self.number_of_truck = number_of_truck
        self.baggage = baggage

    def check(self, mid):
        baggage_num = 0
        for j in range(self.number_of_truck):
            baggage_sum = 0
            while(baggage_sum + self.baggage[baggage_num] <= mid):
                baggage_sum += self.baggage[baggage_num]
                baggage_num += 1
                if baggage_num == self.N:
                    return baggage_num
        return baggage_num

    def binary_search(self):
        left = 0
        right = 1000000000
        while(left + 1 < right):
            mid = int((left + right) / 2)
            ok = self.check(mid)
            if ok == self.N:
                right = mid
            else :
                left = mid
        return right Check def __init__(self, N, number_of_truck,baggage):
        self.N = N
        self.number_of_truck = number_of_truck
        self.baggage = baggage

     __init__ self.N = N self.N self N N self.number_of_truck = number_of_truck self.number_of_truck self number_of_truck number_of_truck self.baggage = baggage self.baggage self baggage baggage self self N N number_of_truck number_of_truck baggage baggage def check(self, mid):
        baggage_num = 0
        for j in range(self.number_of_truck):
            baggage_sum = 0
            while(baggage_sum + self.baggage[baggage_num] <= mid):
                baggage_sum += self.baggage[baggage_num]
                baggage_num += 1
                if baggage_num == self.N:
                    return baggage_num
        return baggage_num

     check baggage_num = 0 baggage_num 0 for j in range(self.number_of_truck):
            baggage_sum = 0
            while(baggage_sum + self.baggage[baggage_num] <= mid):
                baggage_sum += self.baggage[baggage_num]
                baggage_num += 1
                if baggage_num == self.N:
                    return baggage_num
         j range(self.number_of_truck) range self.number_of_truck self number_of_truck baggage_sum = 0 baggage_sum 0 while(baggage_sum + self.baggage[baggage_num] <= mid):
                baggage_sum += self.baggage[baggage_num]
                baggage_num += 1
                if baggage_num == self.N:
                    return baggage_num
         baggage_sum + self.baggage[baggage_num] <= mid baggage_sum + self.baggage[baggage_num] baggage_sum self.baggage[baggage_num] self.baggage self baggage baggage_num mid baggage_sum += self.baggage[baggage_num] baggage_sum self.baggage[baggage_num] self.baggage self baggage baggage_num baggage_num += 1 baggage_num 1 if baggage_num == self.N:
                    return baggage_num
         baggage_num == self.N baggage_num self.N self N return baggage_num baggage_num return baggage_num baggage_num self self mid mid def binary_search(self):
        left = 0
        right = 1000000000
        while(left + 1 < right):
            mid = int((left + right) / 2)
            ok = self.check(mid)
            if ok == self.N:
                right = mid
            else :
                left = mid
        return right binary_search left = 0 left 0 right = 1000000000 right 1000000000 while(left + 1 < right):
            mid = int((left + right) / 2)
            ok = self.check(mid)
            if ok == self.N:
                right = mid
            else :
                left = mid
         left + 1 < right left + 1 left 1 right mid = int((left + right) / 2) mid int((left + right) / 2) int (left + right) / 2 left + right left right 2 ok = self.check(mid) ok self.check(mid) self.check self check mid if ok == self.N:
                right = mid
            else :
                left = mid
         ok == self.N ok self.N self N right = mid right mid left = mid left mid return right right self self def main():
    N,number_of_truck = [int(i) for i in input().split()]
    baggage = list()
    for i in range(N):
        i = int(input())
        baggage.append(i)
    ok = Check(N,number_of_truck,baggage)
    print(ok.binary_search()) main int(i) for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() int(i) int i N,number_of_truck = [int(i) for i in input().split()] N [int(i) for i in input().split()] number_of_truck baggage = list() baggage list() list for i in range(N):
        i = int(input())
        baggage.append(i)
     i range(N) range N i = int(input()) i int(input()) int input() input baggage.append(i) baggage.append baggage append i ok = Check(N,number_of_truck,baggage) ok Check(N,number_of_truck,baggage) Check N number_of_truck baggage print(ok.binary_search()) print ok.binary_search() ok.binary_search ok binary_search if __name__ == "__main__":
    main() __name__ == "__main__" __name__ "__main__" main() main def main():
    N,number_of_truck = [int(i) for i in input().split()]
    baggage = list()
    for i in range(N):
        i = int(input())
        baggage.append(i)
    ok = Check(N,number_of_truck,baggage)
    print(ok.binary_search()) def main():
    N,number_of_truck = [int(i) for i in input().split()]
    baggage = list()
    for i in range(N):
        i = int(input())
        baggage.append(i)
    ok = Check(N,number_of_truck,baggage)
    print(ok.binary_search()) main class Check():
    def __init__(self, N, number_of_truck,baggage):
        self.N = N
        self.number_of_truck = number_of_truck
        self.baggage = baggage

    def check(self, mid):
        baggage_num = 0
        for j in range(self.number_of_truck):
            baggage_sum = 0
            while(baggage_sum + self.baggage[baggage_num] <= mid):
                baggage_sum += self.baggage[baggage_num]
                baggage_num += 1
                if baggage_num == self.N:
                    return baggage_num
        return baggage_num

    def binary_search(self):
        left = 0
        right = 1000000000
        while(left + 1 < right):
            mid = int((left + right) / 2)
            ok = self.check(mid)
            if ok == self.N:
                right = mid
            else :
                left = mid
        return right class Check():
    def __init__(self, N, number_of_truck,baggage):
        self.N = N
        self.number_of_truck = number_of_truck
        self.baggage = baggage

    def check(self, mid):
        baggage_num = 0
        for j in range(self.number_of_truck):
            baggage_sum = 0
            while(baggage_sum + self.baggage[baggage_num] <= mid):
                baggage_sum += self.baggage[baggage_num]
                baggage_num += 1
                if baggage_num == self.N:
                    return baggage_num
        return baggage_num

    def binary_search(self):
        left = 0
        right = 1000000000
        while(left + 1 < right):
            mid = int((left + right) / 2)
            ok = self.check(mid)
            if ok == self.N:
                right = mid
            else :
                left = mid
        return right Check
class Check():
    def __init__(self, N, number_of_truck,baggage):
        self.N = N
        self.number_of_truck = number_of_truck
        self.baggage = baggage

    def check(self, mid):
        baggage_num = 0
        for j in range(self.number_of_truck):
            baggage_sum = 0
            while(baggage_sum + self.baggage[baggage_num] <= mid):
                baggage_sum += self.baggage[baggage_num]
                baggage_num += 1
                if baggage_num == self.N:
                    return baggage_num
        return baggage_num

    def binary_search(self):
        left = 0
        right = 1000000000
        while(left + 1 < right):
            mid = int((left + right) / 2)
            ok = self.check(mid)
            if ok == self.N:
                right = mid
            else :
                left = mid
        return right

def main():
    N,number_of_truck = [int(i) for i in input().split()]
    baggage = list()
    for i in range(N):
        i = int(input())
        baggage.append(i)
    ok = Check(N,number_of_truck,baggage)
    print(ok.binary_search())

if __name__ == "__main__":
    main()
