#include <bits/stdc++.h>

#define int long long

using namespace std;

const int MOD = 1e9+7;
#ifdef LOCAL
#include "/media/brayand/BrayanD/debugger.h"
#else
template<typename... Args>
void db(Args... args){}
#endif

int qpow(int a, int b)
{
	int res = 1;
	while(b)
	{
		if(b&1)res = res*a%MOD;
		a = a*a%MOD;
		b /= 2;
	}
	return res;
}

int inv(int x)
{
	return qpow(x,MOD-2);
}

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int N, K;
    cin >> N >> K;

    vector<int> pos;
    vector<int> ceros;
    vector<int> neg;

    vector<pair<int,int>> vect;

    for(int i = 0 ; i < N ; i++)
    {
    	int n;
    	cin >> n;

    	if(n > 0)pos.push_back(n),vect.push_back({abs(n),1});
    	if(n == 0)ceros.push_back(n),vect.push_back({abs(n),0});
    	if(n < 0)neg.push_back(n),vect.push_back({abs(n),-1});
    }

    sort(vect.rbegin(),vect.rend());

    int sign = 1;

    for(int i = 0 ; i < K ; i++)
    {
    	sign *= vect[i].second;
    }

    if(sign >= 0)
    {
    	int res = 1;

    	for(int i = 0 ; i < K ; i++)
    	{
    		res = res*vect[i].first%MOD;
    	}

    	cout << res << '\n';
    }
    else
    {
    	int menpos = 2e18;
    	int menneg = 2e18;

    	int maypos = -2e18;
    	int mayneg = -2e18;

    	for(int i = 0 ; i < K ; i++)
    	{
    		if(vect[i].second == 1)menpos = min(menpos,vect[i].first);
    		if(vect[i].second == -1)menneg = min(menneg,vect[i].first);
    	}

    	for(int i = K ; i < N ; i++)
    	{
    		if(vect[i].second >= 0)maypos = max(maypos,vect[i].first);
    		if(vect[i].second == -1)mayneg = max(mayneg,vect[i].first);
    	}

        db(menneg);
        db(menpos);
        db(mayneg);
        db(maypos);

    	if(menneg != 2e18 && maypos != -2e18 && menpos != 2e18 && mayneg != -2e18)
    	{
    	db(1);
    		if(mayneg*menneg <= menpos*maypos)
    		{
    			int res = 1;
				for(int i = 0 ; i < K ; i++)
				{
					res = res*vect[i].first%MOD;
				}
				cout << (res*inv(menneg)%MOD)*maypos%MOD << '\n';
    		}
    		else
    		{
    			int res = 1;
	    		for(int i = 0 ; i < K ; i++)
	    		{
	    			res = res*vect[i].first%MOD;
	    		}
	    		cout << (res*inv(menpos)%MOD)*mayneg%MOD << '\n';
    		}
    	}
    	else if(mayneg == -2e18 && maypos == -2e18)
    	{
    	db(2);
    		int res = 1;
    		for(int i = 0 ; i < K ; i++)
    		{
    			res = res*vect[i].first%MOD;
    		}
    		cout << (MOD-res)%MOD << '\n';
    	}
    	else if(menneg != 2e18 && maypos != -2e18)
    	{
    	db(3);
    		int res = 1;
    		for(int i = 0 ; i < K ; i++)
    		{
    			res = res*vect[i].first%MOD;
    		}
    		cout << (res*inv(menneg)%MOD)*maypos%MOD << '\n';
    	}

    	else if(menpos != 2e18 && mayneg != -2e18)
    	{
    	db(4);
    		int res = 1;
    		for(int i = 0 ; i < K ; i++)
    		{
    			res = res*vect[i].first%MOD;
    		}
    		cout << (res*inv(menpos)%MOD)*mayneg%MOD << '\n';
    	}
    	else if(neg.size() == N)
    	{
    	db(5);
    		sort(neg.rbegin(),neg.rend());

    		int res = 1;

    		for(int i = 0 ; i < K ; i++)
    		{
    			int temp = neg[i];

    			temp = (temp+MOD)%MOD;
    			res = res*temp%MOD;
    		}

    		cout << res << '\n';
    	}

    }

    return 0;
}


Measured memory_bytes: 9368