//#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<set>

/*
#include<boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/rational.hpp>
namespace mp = boost::multiprecision;
using Real = mp::number<mp::cpp_dec_float<1024>>;
using Bint = mp::cpp_int;
*/

using namespace std;

#define int long long
#define REP(i,s,e) for((i)=(s);(i)<(e);(i)++)
#define RREP(i,s,e) for((i)=((s)-1);(i)>=(e);(i)--)
#define FOR(i,n) for((i)=(0);(i)<(n);(i)++)
#define RFOR(i,n) for((i)=((n)-1);(i)>=(0);(i)--)
#define MOD 1000000007

signed main(){
    int N,K;
    vector<int> p,m,z;

    cin>>N>>K;
    for(int i=0;i<N;i++){
        int in;
        cin>>in;
        if(in>0) p.push_back(in);
        else if(in<0) m.push_back(in);
        else z.push_back(in);
    }

    int ans=1;
    sort(p.begin(),p.end());
    sort(m.begin(),m.end());

    //allplus
    if(m.size()==0){
        if(p.size()>=K){
            for(int i=0;i<K;i++){
                ans*=p[p.size()-1-i];
                ans%=MOD;
                while(ans<0) ans+=MOD;
            }
            ans%=MOD;
            while(ans<0) ans+=MOD;
            cout<<ans%MOD<<endl;
        }
        else{
            cout<<"0"<<endl;
        }
    }
    //allminus
    else if(p.size()==0){
        if(m.size()>=K){
            if(K%2==1){
                if(z.size()>0){
                    cout<<"0"<<endl;
                }
                else{
                    for(int i=0;i<K;i++){
                        ans*=m[m.size()-1-i];
                        ans%=MOD;
                        while(ans<0) ans+=MOD;
                    }
                    ans%=MOD;
                    while(ans<0) ans+=MOD;
                    cout<<ans%MOD<<endl;
                }
            }
            else{
                for(int i=0;i<K;i++){
                    ans*=m[i];
                    ans%=MOD;
                    while(ans<0) ans+=MOD;
                }
                ans%=MOD;
                while(ans<0) ans+=MOD;
                cout<<ans%MOD<<endl;
            }
        }
        else{
            cout<<"0"<<endl;
        }
    }
    //all
    else if(N==K){
        for(int i=0;i<p.size();i++){
            ans*=p[i];
            ans%=MOD;
            while(ans<0) ans+=MOD;
        }
        for(int i=0;i<m.size();i++){
            ans*=m[i];
            ans%=MOD;
            while(ans<0) ans+=MOD;
        }
        for(int i=0;i<z.size();i++){
            ans*=z[i];
            ans%=MOD;
            while(ans<0) ans+=MOD;
        }
        ans%=MOD;
        while(ans<0) ans+=MOD;
        cout<<ans%MOD<<endl;
    }
    //other
    else
    {
        if(p.size()+m.size()>=K){
            int ps=p.size()-1;
            int ms=0;
            int n=K;
            if(n%2==1){
                ans*=p[ps--];
                n--;
                ans%=MOD;
                while(ans<0) ans+=MOD;
            }
            while(n!=0){
                if(ps-1<0){
                    ans*=m[ms++];
                    ans%=MOD;
                    while(ans<0) ans+=MOD;
                    ans*=m[ms++];
                    ans%=MOD;
                    while(ans<0) ans+=MOD;
                }
                else if(ms+1>=m.size()){
                    ans*=p[ps--];
                    ans%=MOD;
                    while(ans<0) ans+=MOD;
                    ans*=p[ps--];
                    ans%=MOD;
                    while(ans<0) ans+=MOD;
                }
                else{
                    if(m[ms]*m[ms+1]>p[ps]*p[ps-1]){
                        ans*=m[ms++];
                        ans%=MOD;
                        while(ans<0) ans+=MOD;
                        ans*=m[ms++];
                        ans%=MOD;
                        while(ans<0) ans+=MOD;
                    }
                    else{
                        ans*=p[ps--];
                        ans%=MOD;
                        while(ans<0) ans+=MOD;
                        ans*=p[ps--];
                        ans%=MOD;
                        while(ans<0) ans+=MOD;
                    }
                }
                n-=2;
            }
            ans%=MOD;
            while(ans<0) ans+=MOD;
            cout<<ans%MOD<<endl;;
        }
        else{
           cout<<"0"<<endl;
        }
    }

}



Measured memory_bytes: 5132