#include"bits/stdc++.h"
using namespace std;
using ll=long long;
template<class T=ll>inline T in(istream&is=cin){T ret;is>>ret;return ret;}
template<class T>inline auto vec2(typename vector<T>::size_type h,typename vector<T>::size_type w,T v=T()){return vector<vector<T>>(h,vector<T>(w,v));}
template<class RandomAccessIterator>inline void psortb(RandomAccessIterator first,RandomAccessIterator last){using P=pair<decltype(first->first),decltype(first->second)>;sort(first,last,[](const P&p1,const P&p2){return p1.second<p2.second||(p1.second==p2.second&&p1.first<p2.first);});}

template<unsigned long long mod>
class basic_mod_int final{
private:
    unsigned long long num;
public:
    static basic_mod_int pow(basic_mod_int x,unsigned long long y)
    {
        return y==0?1:y%2==0?pow(x*x,y/2):x*pow(x,y-1);
    }
    basic_mod_int()=default;
    basic_mod_int(unsigned long long n):num(n%mod)
    {
    }
    explicit operator unsigned long long()const
    {
        return num;
    }
    bool operator==(const basic_mod_int&mi)const
    {
        return num==mi.num;
    }
    bool operator!=(const basic_mod_int&mi)const
    {
        return !operator==(mi);
    }
    basic_mod_int operator~()const
    {
        return pow(*this,mod-2);
    }
    basic_mod_int operator+(const basic_mod_int&mi)const
    {
        return num+mi.num;
    }
    basic_mod_int operator-(const basic_mod_int&mi)const
    {
        return num+mod-mi.num;
    }
    basic_mod_int operator*(const basic_mod_int&mi)const
    {
        return num*mi.num;
    }
    basic_mod_int operator/(const basic_mod_int&mi)const
    {
        return num*(~mi).num;
    }
    basic_mod_int&operator+=(const basic_mod_int&mi)
    {
        return*this=operator+(mi);
    }
    basic_mod_int&operator-=(const basic_mod_int&mi)
    {
        return*this=operator-(mi);
    }
    basic_mod_int&operator*=(const basic_mod_int&mi)
    {
        return*this=operator*(mi);
    }
    basic_mod_int&operator/=(const basic_mod_int&mi)
    {
        return*this=operator/(mi);
    }
};
constexpr auto mod=static_cast<unsigned long long>(1e9+7);
using mod_int=basic_mod_int<mod>;
int main()
{
    ll n=in(),k=in();
    vector<ll>a(n);
    for(ll i=0;i<n;++i)a[i]=in();
    sort(a.begin(),a.end(),[](ll foo,ll bar){return abs(foo)>abs(bar);});
    mod_int p=1;
    int sign=1;
    for(ll i=0;i<k;++i){
        p*=abs(a[i]);
        sign*=(a[i]==0?0:a[i]/abs(a[i]));
    }
    if(sign>=0){
        cout<<static_cast<unsigned long long>(p)<<endl;
    }else{
        ll d1=-1,d2=-1,d3=-1,d4=-1;
        for(ll i=k-1;i>=0;--i){
            if(a[i]<0){
                for(ll j=k;j<n;++j){
                    if(a[j]>=0){
                        d1=abs(a[i]);
                        d2=a[j];
                        break;
                    }
                }
                break;
            }
        }
        for(ll i=k-1;i>=0;--i){
            if(a[i]>0){
                for(ll j=k;j<n;++j){
                    if(a[j]<=0){
                        d3=a[i];
                        d4=abs(a[j]);
                        break;
                    }
                }
                break;
            }
        }
        if(d1!=-1&&d2!=-1&&d3!=-1&&d4!=-1){
            if(d2*d3>d4*d1){
                cout<<static_cast<unsigned long long>(p/d1*d2)<<endl;
            }else{
                cout<<static_cast<unsigned long long>(p/d3*d4)<<endl;
            }
        }else if(d1!=-1&&d2!=-1){
            cout<<static_cast<unsigned long long>(p/d1*d2)<<endl;
        }else if(d3!=-1&&d4!=-1){
            cout<<static_cast<unsigned long long>(p/d3*d4)<<endl;
        }else{
            p=1;
            for(ll i=0;i<k;++i)p*=abs(a[n-1-i]);
            cout<<mod-static_cast<unsigned long long>(p)<<endl;
        }
    }
}



Measured memory_bytes: 4804