### BUGGY CODE ###

nums=input().rstrip().split()
num=int(nums[0])
k=int(nums[1])
mains=input().rstrip().split()
mai=[]
for i in range(len(mains)):
    mai.append(int(mains[i]))
main=sorted(mai,key=abs,reverse=True)
result=1
def findplus_plus(x):
    for i in range(x,len(main)-1):
        if main[i]>=0:
            return main[i]
    return -1
def findplus_minus(x):
    for i in range(x,len(main)-1):
        if main[i]<0:
            return main[i]
    return 0
def findminus_plus(x):
    for i in range(x-1,-1,-1):
        if main[i]>=0:
            return main[i]
    return -1
def findminus_minus(x):
    for i in range(x-1,-1,-1):
        if main[i]<0:
            return main[i]
    return 0
    
if num==k:
    for i in main:
        result*=i
elif sorted(main)[len(sorted(main))-1]<0:
    if (k%2)==0:
        for i in range(k):
            result*=main[i]
    else:
        for i in range(len(main)-1,len(main)-1-k,-1):
            result*=main[i]
else:
    for i in range(k):
        result*=main[i]
    if result<0:
        if findplus_plus(k)==-1:
            result1=0
            result2=int(result*findplus_minus(k)//findminus_plus(k))
        else:
            result1=int(result*findplus_plus(k)//findminus_minus(k))
            if findplus_minus(k)==0 or findminus_plus(k)==-1:
                result2=0
            else:
                result2=int(result*findplus_minus(k)//findminus_plus(k))
        result=max(result1,result2)
print(result%(10**9+7))


### FIXED CODE ###

mod=10**9+7
num,k=map(int,input().rstrip().split())
mai=list(map(int, input().rstrip().split()))
main=sorted(mai,key=abs,reverse=True)
result=1
def findplus_plus(x):
    for i in range(x,len(main)):
        if main[i]>=0:
            return main[i]
    return ''
def findplus_minus(x):
    for i in range(x,len(main)):
        if main[i]<0:
            return main[i]
    return ''
def findminus_plus(x):
    for i in range(x-1,-1,-1):
        if main[i]>=0:
            return main[i]
    return ''
def findminus_minus(x):
    for i in range(x-1,-1,-1):
        if main[i]<0:
            return main[i]
    return ''

if num==k:
    for i in main:
        result*=i
        result%=mod
elif sorted(main)[len(sorted(main))-1]<0:
    if (k%2)==0:
        for i in range(k):
            result*=main[i]
            result%=mod
    else:
        for i in range(len(main)-1,len(main)-1-k,-1):
            result*=main[i]
            result%=mod

else:
    count=0
    for i in range(k):
        if main[i]<0:
            count+=1
        result*=main[i]
        result%=mod
    if (count%2)==1:
        minplus=findminus_plus(k)
        minminus=findminus_minus(k)
        maxplus=findplus_plus(k)
        maxminus=findplus_minus(k)
        if type(maxplus)==type(''):
            plusplus=-1
            minusminus=minminus*maxminus
        else:
            if type(maxminus)==type('') or type(minplus)==type(''):
                minusminus=-1
                plusplus=0
            else:
                minusminus=minminus*maxminus
                plusplus=minplus*maxplus
        if plusplus>minusminus:
            main.remove(minminus)
            result=1
            for i in range(k-1):
                result*=main[i]
                result%=mod
            result*=maxplus
        elif plusplus<=minusminus:
            main.remove(minplus)
            result=1
            for i in range(k-1):
                result*=main[i]
                result%=mod
            result*=maxminus
            
print(result%mod)