#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define mk make_pair
#define mt make_tuple
#define MOD 1000000007
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define vl vector <long long int>
#define pii pair <int,int>
#define pll pair <long long int, long long int>
#define vpii vector< pair<int,int> >
#define vpll vector < pair <long long int,long long int> >
#define boost ios::sync_with_stdio(false); cin.tie(0)
using namespace std;
const int inf = 1e9 + 5;
const ll inf64 = 1e18 + 5;

ll add(ll x, ll y) {ll res=x+y; return(res>=MOD?res-MOD:res);}
ll mul(ll x, ll y) {ll res=x*y; return(res>=MOD?res%MOD:res);}
ll sub(ll x, ll y) {ll res=x-y; return(res<0?res+MOD:res);}
ll lcm(ll x, ll y) {ll res=(x*y)/__gcd(x,y); return res;}
ll power(ll x, ll y) {ll res=1; x%=MOD; while(y){if(y&1)res=mul(res,x); y>>=1; x=mul(x,x);} return res;}

int main()
{
	boost;
	int n, k, i;
	cin >> n >> k;
	int arr[n];
	fo(i, 0, n)
	cin >> arr[i];
	
	int c0 = 0;
	for(int x : arr)
	c0 += (x == 0);
	
	vector <pii> v;
	for(int x : arr) {
		if(x < 0) v.pb({-x, -1});
		else if(x == 0) v.pb({x, 0});
		else v.pb({x, 1});
	}
	sort(all(v), greater <pii>());
	bool zero = 0;
	fo(i, 0, k) {
		if(v[i].s == 0) {
			zero = 1;
			break;
		}
	}
	if(zero) cout << 0;
	else {
		ll ans = 1;
		int cn = 0, cp = 0;
		fo(i, 0, k) {
			if(v[i].s == -1) 
			++cn;
			else if(v[i].s == 1)
			++cp;
			ans = mul(ans, v[i].f);
		}
		if(cn & 1) {
			// Scrap last -1 and find next +1
			int num = -1;
			bool pos = 0;
			fo(i, k, n) {
				if(v[i].s == 1) {
					num = v[i].f;
					break;
				}
			}
			
			// Scrap last +1 and find next -1
			int negt = -1;
			fo(i, k, n) {
				if(v[i].s == -1) {
					negt = v[i].f;
					break;
				}
			}
			
			int lastpos = -1, lastneg = -1;
			for(i = k - 1; i >= 0; i--) {
				if(v[i].s == -1 && lastneg == -1)
				lastneg = i;
				if(v[i].s == 1 && lastpos == -1)
				lastpos = i;
			}
			
			if(lastpos != -1 && lastneg != -1) {
				pos = true;
				if(num != -1 && negt != -1) {
					ll c1 = 1ll * num * v[lastpos].f;
					ll c2 = 1ll * negt * v[lastneg].f;
					if(c1 >= c2)
					ans = mul(ans, mul(num, power(v[lastneg].f, MOD - 2)));
					else
					ans = mul(ans, mul(negt, power(v[lastpos].f, MOD - 2)));
				}
				else if(num == -1 && negt != -1) ans = mul(ans, mul(negt, power(v[lastpos].f, MOD - 2)));
				else if(negt == -1 && num != -1) ans = mul(ans, mul(num, power(v[lastneg].f, MOD - 2)));
				else pos = false;
			}
			else if(lastpos == -1 && lastneg != -1) {
				pos = true;
				if(num != -1) ans = mul(ans, mul(num, power(v[lastneg].f, MOD - 2)));
				else pos = false;
			}
			else if(lastpos != -1 && lastneg == -1) {
				pos = true;
				if(negt != -1) ans = mul(ans, mul(negt, power(v[lastpos].f, MOD - 2)));
				else pos = false;
			}
			else pos = false;
			
			if(!pos) {
				if(c0) cout << 0;
				else {
					ans = 1;
					reverse(all(v));
					fo(i, 0, k) {
						ll val = v[i].f * v[i].s;
						ll x = (val % MOD + MOD) % MOD;
						ans = mul(ans, x);
					}
					cout << ans;
				}
			}
			else cout << ans;
		}
		else cout << ans;
	}
}


Measured memory_bytes: 6108