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

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

#define ll long long
#define db double
#define el "\n"
#define ld long double
#define rep(i,n) for(int i=0;i<n;i++)
#define rev(i,n) for(int i=n;i>=0;i--)
#define rep_a(i,a,n) for(int i=a;i<n;i++)
#define all(ds) ds.begin(), ds.end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
typedef vector< long long > vi;
typedef pair<long long, long long> ii;
typedef priority_queue <ll> pq;
#define o_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define graph vector<vi>

const ll mod = 1000000007;
const ll INF = (ll)1e18;
const ll MAXN = 1000006;

ll po(ll x, ll n ){ 
    ll ans=1;
     while(n>0){
         if(n&1) ans=(ans*x)%mod;
         x=(x*x)%mod;
         n/=2;
     }
     return ans;
}

bool cmp(ll &x, ll &y){
    return abs(x)>abs(y);
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
 
    int T=1;
    //cin >> T;
    while(T--){
        ll n,k;
        cin>>n>>k;
        ll a[n];
        rep(i,n) cin>>a[i];
        sort(a,a+n, cmp);
        ll f=0, pos=-1, neg=1;
        ll ans=1;
        ll cc=0;
        rep(i,k){
            ans*=abs(a[i]);
            if(a[i]<0){
                f=1-f;
                neg=a[i];
                cc++;
            }
            else pos=a[i];
            ans%=mod;
        }
        // rep(i,n) cout<<a[i]<<" ";
        // cout<<el;

        if(f==0) cout<<ans<<el;
        else{
            ii z1, z2, y;
            int f1=0, f2=0, g=0;
            if(pos!=-1){
                ll z=1;
                rep_a(j,k,n){
                    if(a[j]<0){
                        z=a[j];
                        break;
                    }
                }
                if(z<0){
                    z1 = mp(abs(z), pos);
                    f1=1;
                }
            }
            if(neg!=1){
                ll z=-1;
                rep_a(j,k,n){
                    if(a[j]>0){
                        z=a[j];
                        break;
                    }
                }
                if(z>0){
                    z2 = mp(z, abs(neg));
                    f2=1;
                }
            }
            if(f1 && f2){
                if(z1.ff*z2.ss > z1.ss*z2.ff){
                    y=z1;
                }
                else y=z2;
                g=1;
            }
            else if(f1){
                y=z1;
                g=1;
            }
            else if(f2){
                y=z2;
                g=1;
            }
            if(g){
                ans*=y.ff;
                ans%=mod;
                ans*=po(y.ss, mod-2);
                ans%=mod;
                f=0;
            }


            if(!f) cout<<ans<<el;
            else{
                
                    ans=1;
                    for(int j=n-1; j>n-1-k;j--){
                        ans*=abs(a[j]);
                        ans%=mod;
                    }
                    ans*=-1;
                    ans+=mod;
                    ans%=mod;
                    cout<<ans<<el;
                
            }

        }

    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
    return 0;
}

Measured memory_bytes: 5376