#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
    int n,k;cin>>n>>k;
    vl a(n);
    vll b(n);
    rep(i,n){
        cin>>a[i];
        b[i].F=abs(a[i]);
        if(a[i]<0){
            b[i].S=-1;
        }
        else b[i].S=1;
    }
    sort(all(b));
    reverse(all(b));
    ll ans=1;
    int cnt=0;
    rep(i,k){
        ans*=b[i].F;
        ans%=MOD;
        if(b[i].S==-1){
            cnt++;
        }
    }
    if(cnt%2==0){
        cout<<ans<<endl;
    }
    else{
        int h=-1;
        ll ans1=ans;
        for(int i=k-1;i>=0;--i){
            if(b[i].S==-1){
                h=i;
                ans1*=modInverse(b[h].F);
                ans1%=MOD;
                break;
            }
        }
        ld A=-1,B=-1;
        if(h!=-1){
        bool c=false;
        for(int i=k;i<n;++i){
            if(b[i].S==1){
                ans1*=b[i].F;
                ans1%=MOD;
                A=(ld)b[i].F/b[h].F;
                c=true;
                break;
            }
        }
        if(!c)h=-1;
        }
        ll ans2=ans;
        int s=-1;
        for(int i=k-1;i>=0;--i){
            if(b[i].S==1){
                s=i;
                ans2*=modInverse(b[s].F);
                ans2%=MOD;
                break;
            }
        }
        if(s!=-1){
            bool c=false;
            for(int i=k;i<n;++i){
                if(b[i].S==-1){
                    ans2*=b[i].F;
                    ans2%=MOD;
                    B=(ld)b[i].F/b[s].F;
                    c=true;
                    break;
                }
            }
            if(!c)s=-1;
        }
        if(s==-1&&h==-1){
            ll ans3=1;
            reverse(all(b));
            rep(i,k){ans3*=b[i].F;ans3%=MOD;}
            ans3*=-1;
            while(ans3<0)ans3+=MOD;
            cout<<ans3%MOD<<endl;
        }
        else{
        if(A<B)cout<<ans2<<endl;
        else cout<<ans1<<endl;}
    }
}


Measured memory_bytes: 8012