#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef double dd;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
typedef pair<int, ll> il;
typedef pair<ll , ll> lli;
typedef vector<ii> vii;
typedef vector<il> vil;
typedef vector<li> vli;
typedef vector<lli> vlli;
typedef pair < ll , pair < ll , ll > > cm;

#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define in insert
#define f0(b) for(int i=0;i<(b);i++)
#define f00(b) for(int j=0;j<(b);j++)
#define f1(b) for(int i=1;i<=(b);i++)
#define f11(b) for(int j=1;j<=(b);j++)
#define f2(a,b) for(int i=(a);i<=(b);i++)
#define f22(a,b) for(int j=(a);j<=(b);j++)
#define sf(a) scanf("%lld",&a)
#define sff(a,b) scanf("%lld %lld", &a , &b)
#define pf(a) printf("%lld\n",a)
#define pff(a,b) printf("%lld %lld\n", a , b)
#define PI 3.14159265359
#define bug printf("**!\n")
#define mem(a , b) memset(a, b ,sizeof(a))
#define front_zero(n) __builtin_clzll(n)
#define back_zero(n) __builtin_ctzll(n)
#define total_one(n) __builtin_popcountll(n)
#define clean cout.flush()

const ll mod = (ll)1e9+7;
const ll maxn = (ll)2e5+5;
const int nnn = 1048590;
const int inf = numeric_limits<int>::max()-1;
//const ll INF = numeric_limits<ll>::max()-1;
const ll INF = 1e18;

ll dx[]={0,1,0,-1};
ll dy[]={1,0,-1,0};
ll dxx[]={0,1,0,-1,1,1,-1,-1};
ll dyy[]={1,0,-1,0,1,-1,1,-1};


void solve(){
	
	ll n;
	vector < ll > a, b;
	ll c,k;
	cin >> n >> k;
	f1(n){
		cin >> c;
		if(c >= 0) a.pb(c);
		else b.pb(-c);
	}
	sort(a.begin() , a.end());
	sort(b.begin() , b.end());
	
	if(n == k){
		ll ans = 1;
		for(auto u : a) ans *= u , ans%=mod;
		for(auto u : b){
			ans *= -u;
			ans %=mod;
			if(ans < 0) ans += mod;
		}
		cout << ans;
		return;
	}
	if(b.size() == 0){
		
		sort(a.begin(), a.end() , greater < ll > ());
		ll ans = 1;
		for(ll i = 0 ; i < k; i++){
			ans *= a[i];
			ans %= mod;
		}
		cout << ans;
		return;
	}
	if(a.size() == 0){
		if(k%2 == 0 )sort(b.begin(), b.end() , greater < ll > ());
		ll ans = 1;
		for(ll i = 0 ; i < k; i++){
			ans *= -b[i];
			ans %= mod;
			if(ans < 0) ans += mod;
		}
		cout << ans;
		return;
	}
		ll ans = 1;
		if(k&1){
			k--;
			ans *= a.back();
			a.pop_back();
		}
		for(ll i = 1; i <= k/2; i++){
			if(a.size() <= 1){
				ans *= b.back();
				b.pop_back();
				ans %= mod;
				ans *= b.back();
				b.pop_back();
				ans %= mod;
			}else if(b.size() <= 1){
				ans *= a.back();
				a.pop_back();
				ans %= mod;
				ans *= a.back();
				a.pop_back();
				ans %= mod;
			}else{
				ll n1 = a.size()-1;
				ll n2 = b.size()-1;
				if( (a[n1]*a[n1-1]) >= (b[n2]*b[n2-1]) ){
				ans *= a.back();
				a.pop_back();
				ans %= mod;
				ans *= a.back();
				a.pop_back();
				ans %= mod;
				}else{
				ans *= b.back();
				b.pop_back();
				ans %= mod;
				ans *= b.back();
				b.pop_back();
				ans %= mod;
				}
			}
		}
		cout << ans;
	
	return;
}


int main(int argc, char *argv[]) {
   
   ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
    ll T;
    T=1;
    //cin >> T;
    //scanf("%lld",&T);
    ll CT = 0;
    //work();
    while(T--){
    	//cout << "Case " << ++CT <<": " ;
    //	printf("Case %lld: \n",++CT);
		solve();
	}
    
    return 0;
}

Measured memory_bytes: 5452