def main():
    def check(p):
        # 積めた荷物の数
        i = 0
        # トラックの数だけ試行
        for _ in range(k):
            # 現在のトラックの重量
            s = 0
            while s + w[i] <= p:
                # 積める場合は積んで次の荷物へ
                # 積めない場合は次のトラックへ
                s += w[i]
                i += 1
                if i == n:
                    return n
        return i

    def solve():
        left, right = 0, 100000 * 10000 + 1
        while left < right:
            mid = (left + right) // 2
            if n <= check(mid):
                right = mid
            else:
                left = mid + 1
        return left

    n, k = [int(i) for i in input().split()]
    w = [int(input()) for _ in range(n)]
    ans = solve()
    print(ans)


if __name__ == '__main__':
    main()
 def main():
    def check(p):
        # 積めた荷物の数
        i = 0
        # トラックの数だけ試行
        for _ in range(k):
            # 現在のトラックの重量
            s = 0
            while s + w[i] <= p:
                # 積める場合は積んで次の荷物へ
                # 積めない場合は次のトラックへ
                s += w[i]
                i += 1
                if i == n:
                    return n
        return i

    def solve():
        left, right = 0, 100000 * 10000 + 1
        while left < right:
            mid = (left + right) // 2
            if n <= check(mid):
                right = mid
            else:
                left = mid + 1
        return left

    n, k = [int(i) for i in input().split()]
    w = [int(input()) for _ in range(n)]
    ans = solve()
    print(ans) main def check(p):
        # 積めた荷物の数
        i = 0
        # トラックの数だけ試行
        for _ in range(k):
            # 現在のトラックの重量
            s = 0
            while s + w[i] <= p:
                # 積める場合は積んで次の荷物へ
                # 積めない場合は次のトラックへ
                s += w[i]
                i += 1
                if i == n:
                    return n
        return i

     check i = 0 i 0 for _ in range(k):
            # 現在のトラックの重量
            s = 0
            while s + w[i] <= p:
                # 積める場合は積んで次の荷物へ
                # 積めない場合は次のトラックへ
                s += w[i]
                i += 1
                if i == n:
                    return n
         _ range(k) range k s = 0 s 0 while s + w[i] <= p:
                # 積める場合は積んで次の荷物へ
                # 積めない場合は次のトラックへ
                s += w[i]
                i += 1
                if i == n:
                    return n
         s + w[i] <= p s + w[i] s w[i] w i p s += w[i] s w[i] w i i += 1 i 1 if i == n:
                    return n
         i == n i n return n n return i i p p def solve():
        left, right = 0, 100000 * 10000 + 1
        while left < right:
            mid = (left + right) // 2
            if n <= check(mid):
                right = mid
            else:
                left = mid + 1
        return left

     solve left, right = 0, 100000 * 10000 + 1 left 0 right 100000 * 10000 + 1 100000 * 10000 100000 10000 1 while left < right:
            mid = (left + right) // 2
            if n <= check(mid):
                right = mid
            else:
                left = mid + 1
         left < right left right mid = (left + right) // 2 mid (left + right) // 2 left + right left right 2 if n <= check(mid):
                right = mid
            else:
                left = mid + 1
         n <= check(mid) n check(mid) check mid right = mid right mid left = mid + 1 left mid + 1 mid 1 return left left 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, k = [int(i) for i in input().split()] n [int(i) for i in input().split()] k int(input()) for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) int(input()) int input() input w = [int(input()) for _ in range(n)] w [int(input()) for _ in range(n)] ans = solve() ans solve() solve print(ans) print ans if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def main():
    def check(p):
        # 積めた荷物の数
        i = 0
        # トラックの数だけ試行
        for _ in range(k):
            # 現在のトラックの重量
            s = 0
            while s + w[i] <= p:
                # 積める場合は積んで次の荷物へ
                # 積めない場合は次のトラックへ
                s += w[i]
                i += 1
                if i == n:
                    return n
        return i

    def solve():
        left, right = 0, 100000 * 10000 + 1
        while left < right:
            mid = (left + right) // 2
            if n <= check(mid):
                right = mid
            else:
                left = mid + 1
        return left

    n, k = [int(i) for i in input().split()]
    w = [int(input()) for _ in range(n)]
    ans = solve()
    print(ans) def main():
    def check(p):
        # 積めた荷物の数
        i = 0
        # トラックの数だけ試行
        for _ in range(k):
            # 現在のトラックの重量
            s = 0
            while s + w[i] <= p:
                # 積める場合は積んで次の荷物へ
                # 積めない場合は次のトラックへ
                s += w[i]
                i += 1
                if i == n:
                    return n
        return i

    def solve():
        left, right = 0, 100000 * 10000 + 1
        while left < right:
            mid = (left + right) // 2
            if n <= check(mid):
                right = mid
            else:
                left = mid + 1
        return left

    n, k = [int(i) for i in input().split()]
    w = [int(input()) for _ in range(n)]
    ans = solve()
    print(ans) main
def main():
    def check(p):
        # 積めた荷物の数
        i = 0
        # トラックの数だけ試行
        for _ in range(k):
            # 現在のトラックの重量
            s = 0
            while s + w[i] <= p:
                # 積める場合は積んで次の荷物へ
                # 積めない場合は次のトラックへ
                s += w[i]
                i += 1
                if i == n:
                    return n
        return i

    def solve():
        left, right = 0, 100000 * 10000 + 1
        while left < right:
            mid = (left + right) // 2
            if n <= check(mid):
                right = mid
            else:
                left = mid + 1
        return left

    n, k = [int(i) for i in input().split()]
    w = [int(input()) for _ in range(n)]
    ans = solve()
    print(ans)


if __name__ == '__main__':
    main()

