import sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = 10**10
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    n, k = LI()
    Q = [I() for _ in range(n)]

    def can_stack(p):
        s = 0
        truck_num = 1
        for i in Q:
            if s+i<=p:
                s += i
            else:
                truck_num += 1
                s = i
        return truck_num<=k

    ng = max(Q)-1
    ok = sum(Q)
    while abs(ok-ng)>1:
        m = (ng+ok)//2
        if can_stack(m):
            ok = m
        else:
            ng = m
    print(ok)

    # for i in range(20):
    #     print(i, can_stack(i))

if __name__ == '__main__':
    resolve() import sys sys input = lambda: sys.stdin.readline().rstrip() input lambda: sys.stdin.readline().rstrip() sys.stdin.readline().rstrip() sys.stdin.readline().rstrip sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline rstrip sys.setrecursionlimit(10**7) sys.setrecursionlimit sys setrecursionlimit 10**7 10 7 INF = 10**10 INF 10**10 10 10 def I(): return int(input()) I def F(): return float(input()) F def SS(): return input() SS int(x) for x in input().split() for x in input().split() x input().split() ().split () input split for x in input().split() int(x) int x def LI(): return [int(x) for x in input().split()] LI int(x)-1 for x in input().split() for x in input().split() x input().split() ().split () input split for x in input().split() int(x)-1 int(x) int x 1 def LI_(): return [int(x)-1 for x in input().split()] LI_ float(x) for x in input().split() for x in input().split() x input().split() ().split () input split for x in input().split() float(x) float x def LF(): return [float(x) for x in input().split()] LF def LSS(): return input().split() LSS def resolve():
    n, k = LI()
    Q = [I() for _ in range(n)]

    def can_stack(p):
        s = 0
        truck_num = 1
        for i in Q:
            if s+i<=p:
                s += i
            else:
                truck_num += 1
                s = i
        return truck_num<=k

    ng = max(Q)-1
    ok = sum(Q)
    while abs(ok-ng)>1:
        m = (ng+ok)//2
        if can_stack(m):
            ok = m
        else:
            ng = m
    print(ok)

    # for i in range(20):
    #     print(i, can_stack(i)) resolve n, k = LI() n LI() LI k I() for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) I() I Q = [I() for _ in range(n)] Q [I() for _ in range(n)] def can_stack(p):
        s = 0
        truck_num = 1
        for i in Q:
            if s+i<=p:
                s += i
            else:
                truck_num += 1
                s = i
        return truck_num<=k

     can_stack s = 0 s 0 truck_num = 1 truck_num 1 for i in Q:
            if s+i<=p:
                s += i
            else:
                truck_num += 1
                s = i
         i Q if s+i<=p:
                s += i
            else:
                truck_num += 1
                s = i
         s+i<=p s+i s i p s += i s i truck_num += 1 truck_num 1 s = i s i return truck_num<=k truck_num<=k truck_num k p p ng = max(Q)-1 ng max(Q)-1 max(Q) max Q 1 ok = sum(Q) ok sum(Q) sum Q while abs(ok-ng)>1:
        m = (ng+ok)//2
        if can_stack(m):
            ok = m
        else:
            ng = m
     abs(ok-ng)>1 abs(ok-ng) abs ok-ng ok ng 1 m = (ng+ok)//2 m (ng+ok)//2 ng+ok ng ok 2 if can_stack(m):
            ok = m
        else:
            ng = m
     can_stack(m) can_stack m ok = m ok m ng = m ng m print(ok) print ok if __name__ == '__main__':
    resolve() __name__ == '__main__' __name__ '__main__' resolve() resolve def I(): return int(input()) def I(): return int(input()) I def LI_(): return [int(x)-1 for x in input().split()] def LI_(): return [int(x)-1 for x in input().split()] LI_ def SS(): return input() def SS(): return input() SS def LI(): return [int(x) for x in input().split()] def LI(): return [int(x) for x in input().split()] LI def LF(): return [float(x) for x in input().split()] def LF(): return [float(x) for x in input().split()] LF def resolve():
    n, k = LI()
    Q = [I() for _ in range(n)]

    def can_stack(p):
        s = 0
        truck_num = 1
        for i in Q:
            if s+i<=p:
                s += i
            else:
                truck_num += 1
                s = i
        return truck_num<=k

    ng = max(Q)-1
    ok = sum(Q)
    while abs(ok-ng)>1:
        m = (ng+ok)//2
        if can_stack(m):
            ok = m
        else:
            ng = m
    print(ok)

    # for i in range(20):
    #     print(i, can_stack(i)) def resolve():
    n, k = LI()
    Q = [I() for _ in range(n)]

    def can_stack(p):
        s = 0
        truck_num = 1
        for i in Q:
            if s+i<=p:
                s += i
            else:
                truck_num += 1
                s = i
        return truck_num<=k

    ng = max(Q)-1
    ok = sum(Q)
    while abs(ok-ng)>1:
        m = (ng+ok)//2
        if can_stack(m):
            ok = m
        else:
            ng = m
    print(ok)

    # for i in range(20):
    #     print(i, can_stack(i)) resolve def F(): return float(input()) def F(): return float(input()) F input = lambda: sys.stdin.readline().rstrip() lambda: sys.stdin.readline().rstrip() input INF = 10**10 10**10 INF def LSS(): return input().split() def LSS(): return input().split() LSS
import sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = 10**10
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    n, k = LI()
    Q = [I() for _ in range(n)]

    def can_stack(p):
        s = 0
        truck_num = 1
        for i in Q:
            if s+i<=p:
                s += i
            else:
                truck_num += 1
                s = i
        return truck_num<=k

    ng = max(Q)-1
    ok = sum(Q)
    while abs(ok-ng)>1:
        m = (ng+ok)//2
        if can_stack(m):
            ok = m
        else:
            ng = m
    print(ok)

    # for i in range(20):
    #     print(i, can_stack(i))

if __name__ == '__main__':
    resolve()
