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

#define fastio                  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define input_output            freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); 

#define ll                      long long
#define read1(x)                 cin>>x
#define read2(x,y)               cin>>x>>y
#define print(x)				cout<<x<<endl
#define pii                     pair<int, int>
#define pli                     pair<ll, int>
#define pil                     pair<int, ll>
#define pll                     pair<ll, ll>
#define vi                      vector<int>
#define vll                     vector<ll>
#define vb                      vector<bool>
#define vd                      vector<double>
#define vs                      vector<string>
#define ff                      first
#define ss                      second
#define pb                      push_back
#define ppb                     pop_back
#define pf                      push_front
#define ppf                     pop_front
#define vpii                    vector<pii>
#define umap                    unordered_map
#define uset                    unordered_set
#define clr(a,b)                memset(a,b,sizeof a)
#define all(ds)                 ds.begin(), ds.end()
#define rev(ds)                 ds.rbegin(), ds.rend()
#define asc(A)                  sort(A.begin(), A.end())
#define dsc(A)                  sort(A.begin(), A.end(), greater<ll>())
#define gcd(x,y)                __gcd(x,y)
#define clr(a,b)                memset(a,b,sizeof a)
#define fr(i, n)                for(int i=0; i<n;++i)
#define fr1(i, n)               for(int i=1; i<=n; ++i)
#define rfr(i, n)               for(int i=n-1; i>=0; --i)
#define printVector(v)          for(int i= 0;i<v.size();i++) {cout<<v[i]<<" ";} cout<<endl;
#define precise(x)              cout<<fixed<<setprecision(x)
#define inf                     10000000000000

 

ll lcm(ll a, ll b) {return (a*b)/__gcd(a, b); }
ll power(ll x, ll y, ll m) { if(!y) return 1; ll p=power(x, y>>1, m)%m; p=p*p%m; return (y&1)?(x*p)%m:p;}
ll modInverse(ll a, ll m){ return power(a, m-2, m); }
bool isPrime(ll num){bool flag=true;for(ll i =2;i<=num/2;i++){if(num%i==0) {flag=false; break;} }return flag;}
ll sumofdigits(ll n){ll c=0;while(n>0){c++;n/=10;}return c;}
bool sortinrev(const pair<int,int>&a,const pair<int,int>&b) {return a.first > b.first; }
bool sortbysec(const pair<int,int> &a, const pair<int,int> &b) {return a.second < b.second; }

//const double PI= 2*acos(0.0);
const long long MOD= 1000000007;
ll mod(ll x){
    return (x%MOD+MOD)%MOD;
}
ll mul(ll a, ll b){
    return mod(mod(a)*mod(b));
}
void solve(){
    int n, k; cin>>n>>k;
    vector<ll> pos, neg;
    fr(i,n){
        int x; cin>>x; 
        if(x > 0)pos.pb(x);
        else neg.pb(x);
    }
    ll product = 1;

    // if all of them are neg
    if(pos.size() == 0){
        asc(neg);
        if(k&1)reverse(all(neg));
        fr(i,k){
            product = mul(product, neg[i]);
        }
        print(product);
        return;
    }

    // if there are both pos and neg  or only pos
    if(k&1){
        asc(pos);
        product = mul(product, pos.back());
        pos.pop_back();
        k--;
    }
    // now k is even, pick 2 from each pos and neg consecutively
    dsc(pos);
    asc(neg);
    vector<ll> ans;
    // print(pos.size());
    for(int i = 0; i+1 < (int)pos.size(); i+=2){
        ll prod = (pos[i] * pos[i+1]);
        ans.pb(prod);
    }
    for(ll i = 0; i+1 < (int)neg.size(); i+=2){
        ll prod = (neg[i] *neg[i+1]);
        ans.pb(prod);
    }
    if((int)pos.size()&1 && (int)neg.size()&1){
        ans.pb((pos.back() * neg.back()));
    }
    dsc(ans);
    ll i = 0;
    fr(i, (k/2)){
        product = mul(product, ans[i]);
    }
    print(product);
    return;
}

int main()
{
#ifndef ONLINE_JUDGE  
    input_output  
#else   
    fastio
#endif

    int t =1 ;
    // cin>>t;
    while(t--){
        solve();
    }

    return 0;
}


Measured memory_bytes: 6556