#include <bits/stdc++.h>
 
using namespace std;
 
#define f0r(a, b) for (long long a = 0; a < (b); a++)
#define f1r(a, b, c) for (long long a = (b); a < (c); a++)
#define f0rd(a, b) for (long long a = (b); a >= 0; a--)
#define f1rd(a, b, c) for (long long a = (b); a >= (c); a--)
#define ms(arr, v) memset(arr, v, sizeof(arr))
#define pb push_back
#define mp make_pair
#define f first
#define s second
using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vpl = vector<pll>;
 
void fio() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); 
  cout.tie(0);
}
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const long double pi = 3.14159265358979323846;

const ll mod = 1000000007;

namespace modop {
	ll madd(ll a, ll b) {
	  return (a + b) % mod;
	}
	ll msub(ll a, ll b) {
	  return (((a - b) % mod) + mod) % mod;
	}
	ll mmul(ll a, ll b) {
	  return ((a % mod) * (b % mod)) % mod;
	}
	ll mpow(ll base, ll exp) {
	  ll res = 1;
	  while (exp) {
		if (exp % 2 == 1){
			res = (res * base) % mod;
		}
		exp >>= 1;
		base = (base * base) % mod;
	  }
	  return res;
	}
	ll minv(ll base) {
	  return mpow(base, mod - 2);
	}
	ll mdiv(ll a, ll b) {
	  return mmul(a, minv(b));
	}
}

using namespace modop;

// gfg... bruh
ll maxProductSubarrayOfSizeK(ll A[], ll n, ll k) 
{ 
    // sorting given input array 
    sort(A, A + n); 
  
    // variable to store final product of all element 
    // of sub-sequence of size k 
    ll product = 1; 
  
    // CASE I 
    // If max element is 0 and 
    // k is odd then max product will be 0 
    if (A[n - 1] == 0 && (k & 1)) 
        return 0; 
  
    // CASE II 
    // If all elements are negative and 
    // k is odd then max product will be 
    // product of rightmost-subarray of size k 
    if (A[n - 1] <= 0 && (k & 1)) { 
        for (int i = n - 1; i >= n - k; i--) 
            product = (product * A[i]) % mod; 
        return product; 
    } 
  
    // else 
    // i is current left pointer index 
    int i = 0; 
  
    // j is current right pointer index 
    int j = n - 1; 
  
    // CASE III 
    // if k is odd and rightmost element in 
    // sorted array is positive then it 
    // must come in subsequence 
    // Multiplying A[j] with product and 
    // correspondingly changing j 
    if (k & 1) { 
        product = (product * A[j]) % mod; 
        j--; 
        k--; 
    } 
  
    // CASE IV 
    // Now k is even 
    // Now we deal with pairs 
    // Each time a pair is multiplied to product 
    // ie.. two elements are added to subsequence each time 
    // Effectively k becomes half 
    // Hence, k >>= 1 means k /= 2 
    k >>= 1; 
  
    // Now finding k corresponding pairs 
    // to get maximum possible value of product 
    for (int itr = 0; itr < k; itr++) { 
  
        // product from left pointers 
        ll left_product = A[i] * A[i + 1]; 
  
        // product from right pointers 
        ll right_product = A[j] * A[j - 1]; 
  
        // Taking the max product from two choices 
        // Correspondingly changing the pointer's position 
        if (left_product > right_product) { 
          left_product %= mod;
            product = (product * left_product) % mod; 
            i += 2; 
        } 
        else { 
          right_product %= mod;
            product = (product * right_product) % mod; 
            j -= 2; 
        } 
    } 
  
    // Finally return product 
    return product; 
} 

void solve() {
  ll n, k; cin >> n >> k;
  ll a[n]; f0r(i, n) cin >> a[i];
  ll p = maxProductSubarrayOfSizeK(a, n, k);
  p %= mod;
  p = (p + mod) % mod;
  cout << p << '\n';
}
 
int main() {
  fio();
  
  int T = 1;
  // cin >> T;
  while (T--) solve();
} 

Measured memory_bytes: 5216