# -*- coding:utf-8 -*-
import sys


def allcation(truck, baggage, limit):
    t = 1
    cap = 0
    for weight in baggage:
        if weight <= limit:
            if cap + weight <= limit:
                cap += weight
            else:
                cap = weight
                t += 1

            if t > truck:
                return False
        else:
            return False
    return True


def bin_search(truck, baggage):
    small = 0
    big = 10000 * 100000
    minimum = 0
    while small < big:
        mid = (small + big) >> 1
        if allcation(truck, baggage, mid):
            big = mid
            minimum = mid
        else:
            small = mid + 1

    return minimum


if __name__ == "__main__":
    n = [int(val) for val in input().split()]
    lst = [int(val) for val in sys.stdin.read().splitlines()]
    print(bin_search(n[1], lst)) import sys sys def allcation(truck, baggage, limit):
    t = 1
    cap = 0
    for weight in baggage:
        if weight <= limit:
            if cap + weight <= limit:
                cap += weight
            else:
                cap = weight
                t += 1

            if t > truck:
                return False
        else:
            return False
    return True allcation t = 1 t 1 cap = 0 cap 0 for weight in baggage:
        if weight <= limit:
            if cap + weight <= limit:
                cap += weight
            else:
                cap = weight
                t += 1

            if t > truck:
                return False
        else:
            return False
     weight baggage if weight <= limit:
            if cap + weight <= limit:
                cap += weight
            else:
                cap = weight
                t += 1

            if t > truck:
                return False
        else:
            return False
     weight <= limit weight limit if cap + weight <= limit:
                cap += weight
            else:
                cap = weight
                t += 1

             cap + weight <= limit cap + weight cap weight limit cap += weight cap weight cap = weight cap weight t += 1 t 1 if t > truck:
                return False
         t > truck t truck return False False return False False return True True truck truck baggage baggage limit limit def bin_search(truck, baggage):
    small = 0
    big = 10000 * 100000
    minimum = 0
    while small < big:
        mid = (small + big) >> 1
        if allcation(truck, baggage, mid):
            big = mid
            minimum = mid
        else:
            small = mid + 1

    return minimum bin_search small = 0 small 0 big = 10000 * 100000 big 10000 * 100000 10000 100000 minimum = 0 minimum 0 while small < big:
        mid = (small + big) >> 1
        if allcation(truck, baggage, mid):
            big = mid
            minimum = mid
        else:
            small = mid + 1

     small < big small big mid = (small + big) >> 1 mid (small + big) >> 1 small + big small big 1 if allcation(truck, baggage, mid):
            big = mid
            minimum = mid
        else:
            small = mid + 1

     allcation(truck, baggage, mid) allcation truck baggage mid big = mid big mid minimum = mid minimum mid small = mid + 1 small mid + 1 mid 1 return minimum minimum truck truck baggage baggage if __name__ == "__main__":
    n = [int(val) for val in input().split()]
    lst = [int(val) for val in sys.stdin.read().splitlines()]
    print(bin_search(n[1], lst)) __name__ == "__main__" __name__ "__main__" int(val) for val in input().split() for val in input().split() val input().split() ().split () input split for val in input().split() int(val) int val n = [int(val) for val in input().split()] n [int(val) for val in input().split()] int(val) for val in sys.stdin.read().splitlines() for val in sys.stdin.read().splitlines() val sys.stdin.read().splitlines() sys.stdin.read().splitlines sys.stdin.read() sys.stdin.read sys.stdin sys stdin read splitlines for val in sys.stdin.read().splitlines() int(val) int val lst = [int(val) for val in sys.stdin.read().splitlines()] lst [int(val) for val in sys.stdin.read().splitlines()] print(bin_search(n[1], lst)) print bin_search(n[1], lst) bin_search n[1] n 1 lst n = [int(val) for val in input().split()] [int(val) for val in input().split()] n def allcation(truck, baggage, limit):
    t = 1
    cap = 0
    for weight in baggage:
        if weight <= limit:
            if cap + weight <= limit:
                cap += weight
            else:
                cap = weight
                t += 1

            if t > truck:
                return False
        else:
            return False
    return True def allcation(truck, baggage, limit):
    t = 1
    cap = 0
    for weight in baggage:
        if weight <= limit:
            if cap + weight <= limit:
                cap += weight
            else:
                cap = weight
                t += 1

            if t > truck:
                return False
        else:
            return False
    return True allcation lst = [int(val) for val in sys.stdin.read().splitlines()] [int(val) for val in sys.stdin.read().splitlines()] lst def bin_search(truck, baggage):
    small = 0
    big = 10000 * 100000
    minimum = 0
    while small < big:
        mid = (small + big) >> 1
        if allcation(truck, baggage, mid):
            big = mid
            minimum = mid
        else:
            small = mid + 1

    return minimum def bin_search(truck, baggage):
    small = 0
    big = 10000 * 100000
    minimum = 0
    while small < big:
        mid = (small + big) >> 1
        if allcation(truck, baggage, mid):
            big = mid
            minimum = mid
        else:
            small = mid + 1

    return minimum bin_search
# -*- coding:utf-8 -*-
import sys


def allcation(truck, baggage, limit):
    t = 1
    cap = 0
    for weight in baggage:
        if weight <= limit:
            if cap + weight <= limit:
                cap += weight
            else:
                cap = weight
                t += 1

            if t > truck:
                return False
        else:
            return False
    return True


def bin_search(truck, baggage):
    small = 0
    big = 10000 * 100000
    minimum = 0
    while small < big:
        mid = (small + big) >> 1
        if allcation(truck, baggage, mid):
            big = mid
            minimum = mid
        else:
            small = mid + 1

    return minimum


if __name__ == "__main__":
    n = [int(val) for val in input().split()]
    lst = [int(val) for val in sys.stdin.read().splitlines()]
    print(bin_search(n[1], lst))