#include <bits/stdc++.h>
using namespace std;
#define ll                  long long
#define ld                  long double
#define pb                  push_back
#define mkp                 make_pair
#define f(i,l,h)            for(ll i=l;i<h;i++)
#define fr(i,h,l)           for(ll i=h;i>=l;i--)
#define mem(a,val)          memset(a,val,sizeof(a))
#define all(v)              (v).begin(),(v).end()
#define ff                  first
#define ss                  second
#define spc(x)              cout<<fixed<<setprecision((x));
#define deb(x)              cout<<#x<<" "<<x<<endl;
#define deba(x)             cout<<#x<<": "; for(auto u:x) cout<<u<<" ";  cout<<endl;
#define check               cout<<"hello"<<endl;
#define fastio              ios_base::sync_with_stdio(false);cin.tie(NULL)
const ld pi=3.141592653589793;
const ll mod=998244353;
const ll INF=(ll)(1e9+7);
typedef pair<ll,ll> pll;
typedef vector<ll> vll;

ll power(ll a,ll b){
    ll res=1;
	while(b){
	    if(b&1) res=(res*a);
	    a=(a*a);
	    b>>=1;
	}
	return res;
}

int main()
{
    //cout << "Hello world!" << endl;
    ll n,k;
    cin >> n >> k;

    pll arr[n+11];
    for(ll i=1;i <= n;i++) {
        ll a;cin >> a;
        arr[i].ff = abs(a);
        if(a < 0) arr[i].ss = 0;
        else arr[i].ss = 1;
    }

    ll cnt = 0;
    ll ans = 1;
    sort(arr+1,arr+n+1);
    for(int i=n;i > n-k;i--) {
        if(!arr[i].ss) cnt++;
    }

    if(cnt % 2) {
        ll n1 = INF,n2 = INF,n3 = INF,n4 = INF;
        for(ll i=n-k+1;i <= n;i++) {
            if(arr[i].ss == 0) {
                n1 = arr[i].ff;
                break;
            }
        }
        ll j;
        for(ll i=n-k+1;i <= n;i++) {
            if(arr[i].ss) {
                n4 = arr[i].ff;
                j = i;
                break;
            }
        }
        for(ll i=n-k;i > 0;--i) {
            if(arr[i].ss) {
                n2 = arr[i].ff;
                break;
            }
        }
        for(ll i=n-k;i > 0;--i) {
            if(!arr[i].ss) {
                n3 = arr[i].ff;
                break;
            }
        }
        if(n2 == INF && n3 == INF) {
            for(ll i=1;i <= n;i++) {
                if(arr[i].ss)ans =( ans * arr[i].ff) % INF;
                else ans = ( ans * -arr[i].ff) % INF;
            }
        }
        else if(n2 == INF && n4 == INF) {
            for(int i=1;i <= k;i++)
                ans =( ans * -arr[i].ff ) % INF;
        }
        else if(n2 != INF &&(n3 == INF || n4 == INF || n2*n4 >= n3*n1)) {
            --cnt;
            for(int i=n;i > n-k;i--) {
                if(arr[i].	ss == 0){
                    if(cnt) {
                        ans = ( ans * arr[i].ff) % INF;
                        --cnt;
                    }
                }else ans = ( ans * arr[i].ff) % INF;
            }
            ans = ( ans * n2 ) % INF;
        }else if(n3 != INF && n4 != INF) {
            for(ll i=n;i > n-k;i--) if(i != j) ans = ( ans * arr[i].ff) % INF;
            ans = ( ans * n3 ) % INF;
        }
    }else for(ll i=n;i > n-k;i--) ans = ( ans * arr[i].ff) % INF;

    if(ans < 0) cout << ans+INF << "\n";
    else cout << ans%INF << "\n";


    return 0;
}


Measured memory_bytes: 6716