#include<bits/stdc++.h>
using namespace std;

// macros
#define int long long 
#define ll long long 
#define TIME clock() * 1.0 / CLOCKS_PER_SEC
#define all(c) c.begin(), c.end()
#define PB push_back
#define MP make_pair
#define bitcount __builtin_popcount
#define watch(x) cerr<< (#x) << " is " << (x) <<"\n";
#define sz(x) ((int)((x).size()))
#define UNIQUE(c) (c).resize(unique(all(c)) - (c).begin())
#define pii2ll(p) ((ll)(p).first<<32 | (p).second)

string to_string(const string& s) {
  return '"' + s + '"';
}
 
string to_string(const char* s) {
  return to_string((string) s);
}
 
string to_string(bool b) {
  return (b ? "1" : "0");
}
 
string to_string(vector<bool> v) {
	bool first = true;
	string res = "{";
	for (int i = 0; i < static_cast<int>(v.size()); i++) {
		if (!first) {
			res += ", ";
		}
		first = false;
		res += to_string(v[i]);
	}
	res += "}";
	return res;
}
 
template <size_t N>
string to_string(bitset<N> v) {
	string res = "";
	for (size_t i = 0; i < N; i++) {
		res += static_cast<char>('0' + v[i]);
	}
	return res;
}
 
template <typename A>
string to_string(A v) {
	bool first = true;
	string res = "{";
	for (const auto &x : v) {
		if (!first) {
			res += ", ";
		}
		first = false;
		res += to_string(x);
	}
	res += "}";
	return res;
}
 
template <typename A, typename B>
string to_string(pair<A, B> p) {
	return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
	return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
    return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
 
void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
 
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

using vi = vector<int>;
using vvi = vector<vi >;
using pii = pair<int, int>;

template <typename T1, typename T2>
inline auto mini(T1 a, T2 b) { return (a < b ? a : b); }
template<typename T, typename... Args>
inline auto mini(T a, Args... args) { return mini(a, mini(args...)); }
template <typename T1, typename T2>
inline auto maxi(T1 a, T2 b) { return (a > b ? a : b); }
template<typename T, typename... Args>
inline auto maxi(T a, Args... args) { return maxi(a, maxi(args...)); }
template<typename T>
T gcd(T a, T b) { if(a==0 or b==0) return a+b; return gcd(b, a%b) ; }
template<typename T>
T lcm(T a, T b) { if(a==0 or b==0) return 0; return a/gcd(a, b)*b; }

// random number generation
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); // use mt19937_64 for 64 bit

// constants
const long double eps = LDBL_EPSILON;
const int inf = 1e16;
const int modn = 1e9+7;
const int maxn = 2e5+3;

inline int add(int a, int b) { int ret=((ll)a+b)%modn; if(ret<0) ret+=modn; return ret; }
inline int mul(int a, int b) { int ret=((ll)a*b)%modn; if(ret<0) ret+=modn; return ret; }
template<typename... Args>
inline int add(int a, Args... args) { return add(a, add(args...)); }
template<typename... Args>
inline int mul(int a, Args... args) { return mul(a, mul(args...)); }
inline int addm(int a, int b, int MOD) { int ret=((ll)a+b)%MOD; if(ret<0) ret+=MOD; return ret; }
inline int mulm(int a, int b, int MOD) { int ret=((ll)a*b)%MOD; if(ret<0) ret+=MOD; return ret; }
inline int addm(int a, int b, int c, int MOD) { return addm(a, addm(b, c, MOD), MOD); }
inline int mulm(int a, int b, int c, int MOD) { return mulm(a, mulm(b, c, MOD), MOD); }
int po(int a, int b) {int res=1; for(; b>0; a=mul(a,a), b>>=1) if(b&1) res=mul(res,a); return res; }
inline int inv(int a) {return po(a, modn-2);}

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // Your code here
	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	vector<array<int, 2> > arr;
	for(int i = 0; i < n; i++) {
		cin >> a[i];
		arr.push_back(array<int, 2>{abs(a[i]), (a[i] >=0 ? 1 : -1)});
	}
	sort(arr.rbegin(), arr.rend());
	int cnt = 0;
	int ans = 1;
	for(int i = 0; i < k; i++) {
		ans = mul(ans, arr[i][0]);
		cnt += (arr[i][1] == -1);
	}
	if(cnt % 2 == 0) {
		cout << ans << "\n";
		return 0;
	}
	int num1 = -1, den1 = -1, num2 = -1, den2 = -1;
	for(int i = k; i < n; i++) {
		if(arr[i][1] == 1) {
			num1 = max(num1, arr[i][0]);
		}
		if(arr[i][1] == -1) {
			num2 = max(num2, arr[i][0]);
		}
	}
	for(int i = 0; i < k; i++) {
		if(arr[i][1] == -1) {
			if(den1 == -1) {
				den1 = arr[i][0];
			}
			else {
				den1 = min(den1, arr[i][0]);
			}
		}
		if(arr[i][1] == 1) {
			if(den2 == -1) {
				den2 = arr[i][0];
			}
			else {
				den2 = min(den2, arr[i][0]);
			}
		}
	}
	bool chk1 = (num1 != -1 and den1 != -1);
	bool chk2 = (num2 != -1 and den2 != -1);
	if(chk1 and chk2) {
		if(num1 * den2 > num2 * den1) {
			ans = mul(ans, num1, inv(den1));
		}
		else {
			ans = mul(ans, num2, inv(den2));
		}
	}
	else if(chk1) {
		ans = mul(ans, num1, inv(den1));
	}
	else if(chk2) {
		ans = mul(ans, num2, inv(den2));
	}
	else {
		ans = 1;
		for(int i = n - 1; i >= n - k; i--) {
			ans = mul(ans, arr[i][0]);
		}
		ans = (-ans + modn) % modn;
	}
	cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 9016