#include<cstdio>
#include<cmath>
#include<algorithm>
long long a[200005], b[200005];
double aa[200005], bb[200005];
const long long mod = 1e9+7;

long long power(long long a,long long b){
    long long res = 1;
    while(b){
        if(b&1) res = res*a%mod;
        a = a*a%mod;
        b /= 2;
    }
    return res;
}

long long inv(long long u){ return power(u,mod-2); }

int max(int a,int b){ return a>b?a:b; }

int min(int a,int b){ return a>b?b:a; }

long long trickSolve(int n,int m,int k){
    for(int i = 1; i <= n; i++) aa[i] = log(a[n-i+1]);
    for(int i = 1; i <= m; i++) bb[i] =log(b[m-i+1]);
    int l = max(0,k-m);
    if(l%2) l++;
    int r = k-l;
    double maxn = 0, find = l;
    for(int i = 1; i <= l; i++) maxn += aa[i];
    for(int i = 1; i <= r; i++) maxn += bb[i];
    double cur = maxn;
    for(int i = l+2; i <= min(k,n); i += 2){
        r -= 2;
        if(r<0) break;
        cur -= bb[r+1]+bb[r+2];
        cur += aa[i-1]+aa[i];
        if(cur>maxn){
            find = i;
        }
    }
    long long ans = 1;
    int left = k-find;
    for(int i = 1; i <= find; i++) ans = ans*a[n-i+1]%mod;
    for(int i = 1; i <= left; i++) ans = ans*b[m-i+1]%mod;
    return ans;
}

/*
7 5
-8 -8 9 9 -7 -7 1
*/

int main(){
    int n,k;
    scanf("%d%d",&n,&k);
    int sizeA = 0, sizeB = 0;
    for(int i = 1; i <= n; i++){
        long long u;
        scanf("%lld",&u);
        if(u<0) a[++sizeA] = -u;
        else b[++sizeB] = u;
    }
    std::sort(a+1,a+1+sizeA);
    std::sort(b+1,b+1+sizeB);
    long long sign = mod-1;
    if(k==n){
        long long ans = 1;
        for(int i = 1; i <= sizeA; i++) ans = ans*a[i]%mod;
        for(int i = 1; i <= sizeB; i++) ans = ans*b[i]%mod;
        if(sizeA%2) ans = ans*sign%mod;
        printf("%lld\n",ans);
        return 0;
    }
    if(k%2==0){
        int p0 = sizeA, p1 = sizeB;
        long long ans = 1;
        while(k!=0){
            k -= 2;
            if(p0>=2 && p1>=2){
                if(a[p0]*a[p0-1]>=b[p1]*b[p1-1]){
                    ans = ans*a[p0]%mod*a[p0-1]%mod;
                    p0 -= 2;
                }
                else{
                    ans = ans*b[p1]%mod*b[p1-1]%mod;
                    p1 -= 2;
                }
            }
            else if(p0>=2){
                ans = ans*a[p0]%mod*a[p0-1]%mod;
                p0 -= 2;
            }
            else{
                ans = ans*b[p1]%mod*b[p1-1]%mod;
                p1 -= 2;
            }
        }
        printf("%lld\n",ans);
    }
    else{
        if(sizeB==0){
            long long ans = 1;
            for(int i = 1; i <= k; i++) ans = ans*a[i]%mod;
            ans = ans*sign%mod;
            printf("%lld\n",ans);
        }
        else{
            int org = k;
            int p0 = sizeA, p1 = sizeB;
            long long ans = 1;
            while(k>=2){
                k -= 2;
                if(p0>=2 && p1>=2){
                    if(a[p0]*a[p0-1]>=b[p1]*b[p1-1]){
                        ans = ans*a[p0]%mod*a[p0-1]%mod;
                        p0 -= 2;
                    }
                    else{
                        ans = ans*b[p1]%mod*b[p1-1]%mod;
                        p1 -= 2;
                    }
                }
                else if(p0>=2){
                    ans = ans*a[p0]%mod*a[p0-1]%mod;
                    p0 -= 2;
                }
                else{
                    ans = ans*b[p1]%mod*b[p1-1]%mod;
                    p1 -= 2;
                }
            }
            if(p0==0 || sizeB==1) ans = ans*b[p1]%mod;
            else{
                ans = trickSolve(sizeA,sizeB,org);
                /*long long valueA = a[p0]*a[p0-1];
                long long valueB = b[p1]*b[p1+1];
                if(valueB>=valueA) ans = ans*b[p1]%mod;
                else{
                    ans = ans*inv(b[p1+1]);
                    ans = ans*a[p0]%mod*a[p0-1]%mod;
                }*/
            }
            printf("%lld\n",ans);
        }
    }
    return 0;
}


Measured memory_bytes: 5408