/*input
4 2
1 2 -3 -4

*/
 
/*
                                                    ______________
                                                          |       )
                                                          |   )   /
                                                          |______/
                                                    |     |      \
                                                    |     |   )   \
                                                    |_____|_______)
 
*/
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <iomanip>
#include <fstream>
#include <stack>

using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef pair<ll , ll> PLL;
typedef long double ld;
 
#define pb push_back
#define all(c) c.begin(),c.end()
#define allr(c) c.rbegin(),c.rend()
int mod = 1000000007;
const int inf = 1034567891;
const ll LL_INF = 1234567890123456789ll;
#define PI 3.14159265
#define endl '\n'
#define F first
#define S second
#define debug(x) cout << #x << " = " << x << endl;
#define TRACE
 
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
 
#define out(container) for (auto it : container) cout << it << " "; cout << endl;
 
 
template < typename T > T GCD(T a, T b)            { ll t; while(a) { t = a; a = b % a; b = t; } return b; }
template < typename T > string toString(T a)       { return to_string(a); }
template < typename T > void toInt(string s, T &x) { stringstream str(s); str >> x;}
inline int add(int x, int y){ x += y; if(x >= mod) x -= mod; return x;}
inline int sub(int x, int y){ x -= y; if(x < 0) x += mod; return x;}
inline int mul(int x, int y){ return (x * 1ll * y) % mod;}
inline int powr(int a, ll b){
  int x = 1 % mod;
  while(b){
    if(b & 1) x = mul(x, a);
    a = mul(a, a);
    b >>= 1;
  }
  return x;
}
inline int inv(int a){ return powr(a, mod - 2);}

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  
  int n, k;
  cin >> n >> k;
  vector<long long> vec1, vec2;
  int v;
  for (int i = 0; i < n; i++) {
    cin >> v;
    if (v < 0)
      vec1.push_back(v);
    else
      vec2.push_back(v);
  }  

  sort(all(vec1));
  sort(allr(vec2));

  if (n == k) {
    int ans = 1;
    for (auto it : vec1) {
      ans = mul(ans, it);
      if (ans < 0)
        ans += mod;
    }
    for (auto it : vec2) {
      ans = mul(ans, it);
      if (ans < 0)
        ans += mod;
    }
    cout << ans << endl;
    return 0;
  }
 

  int ans = 1;

  if (k & 1) {
    if (vec1.size() == n) {
      while (k) {
        ans = mul(ans, vec1.back());
        k--;
        vec1.pop_back();
        if (ans < 0)
          ans += mod;
      }
      cout << ans << endl;
      return 0;
    }
    ans = vec2[0];
    vec2.erase(vec2.begin());
  }

  int ind = 0, i = 0;
  for (i = 0; k >= 2 && i + 1 < vec2.size(); ) {
    ll x = vec2[i] * vec2[i + 1];
    if (ind + 1 >= vec1.size()) {
      ans = mul(ans, x % mod);
      k -= 2;
      i += 2;
    } else {
      ll y = vec1[ind] * vec1[ind + 1];
      if (x >= y) {
        ans = mul(ans, x % mod);
        k -= 2;
        i += 2;
      } else {
        ans = mul(ans, y % mod);
        k -= 2;
        ind += 2;
      }
    }
    if (ans < 0)
      ans += mod;
  }
  if (k >= 2) {
    while (k >= 2 && ind + 1 < vec1.size()) {
      ll y = vec1[ind] * vec1[ind + 1];
      ans = mul(ans, y % mod);
      k -= 2;
      ind += 2;
      if (ans < 0)
        ans += mod;
    }
  }
  
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 5608