#include <iostream>
#include <vector>
#include <algorithm>
 
using namespace std;
typedef long long ll;
 
const int M = 1000000007;
 
int main()
{
    int n,k; cin>>n>>k;
 
    vector<ll> v(n);
    for(int i=0;i<n;++i) cin>>v[i];
 
    ll prod=1;
 
    sort(v.begin(),v.end());
 
    if(v[n-1]==0 && (k&1))
    {
        prod=0;
    }
    else if(v[n-1]<0 && (k&1))
    {
        for(int i=n-1;i>=n-k;--i) prod=((prod%M)*(v[i]%M))%M;
    }
    else{ 
        int i=0,j=n-1;
        if(v[n-1]>0 and k&1){ 
            prod = (prod*v[j])%M;
            k--;
            j--;
        }
    
    k=(k/2);
    for(int it=0;it<k;++it)
    {
        ll left_prod = v[i]*v[i+1];
        ll right_prod = v[j]*v[j-1];
 
        if(left_prod > right_prod)
        {
            prod = ((prod%M)*(left_prod%M))%M;
            i+=2;
        }
        else{
            prod = ((prod%M)*(right_prod%M))%M;
            j-=2;
        }
    }
    }
    prod = (prod + M)%M;
    cout<<prod;
}