#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define sz size()
#define SZ(x) int(x.size())
#define mp make_pair
#define all(v) (v).begin(), (v).end()
#define quix ios_base::sync_with_stdio(0);cin.tie(0);
#define binary(n, len) cout << bitset<len>(n) << '\n'
#define rr read
#define ww write
#ifndef ONLINE_JUDGE 
#include "/home/asif/Codes/Library/debug.h"
#endif

//IO

template<typename T>
inline void read(T& t){
  t = 0; char f = 0, ch = getchar();
  double d = 0.1;
  while(ch > '9' or ch < '0') f |= (ch == '-'), ch = getchar();
  while(ch <='9' and ch >= '0') t = t * 10 + ch - 48,ch = getchar();
  if(ch == '.') {
    ch = getchar();
    while(ch <= '9' && ch >= '0') t += d * (ch^48), d *= 0.1, ch = getchar();
  }
  t = ( f ? -t : t);
}
template<typename T, typename... Args>
inline void read(T& t, Args&... args){ read(t); read(args...);}

template<typename T>
void write(T t){ cout << t << '\n'; }
template <typename T, typename... Args>
void write(T t, Args... args) {
  cout << t << ' '; write(args...);
}

template<typename T>
void write(std::vector<T> &v){
  for(int i = 0; i < v.sz; i++)cout << v[i] << " \n" [i == SZ(v) - 1];
}

// Characters and Strings

bool isLetter(char c) { return (c >= 'A' and c <= 'Z') or (c >= 'a' and c <= 'Z');}
bool isUpperCase(char c){ return c >= 'A' and c <= 'Z'; }
bool isLowerCase(char c){ return c >= 'a' and c <= 'z';}
bool isDigit(char c){ return c >= '0' and c <= '9'; }
bool isVowel(char c){ return c == 'a' or c == 'e' or c == 'i' or c == 'o' or c == 'u'; }
bool isConsonant(char c){ return !isVowel(c); }

template<class T> 
string toString(T n){
  ostringstream ost;
  ost << n; ost.flush();
  return ost.str();
}

// Bit Hacks

ll setBit(ll mask, int p){ return (mask | (1 << p)); }
ll resetBit(ll mask, int p){ return (mask & ~(1 << p)); }
ll flipBit(ll mask, int p){ return (mask ^ (1 << p)); }
bool check(ll mask, int p){ return (mask & (1 << p)); }

int msb(long long N){ return N ? 63 - __builtin_clzll(N): -1; }
int lsb(long long N){ return __builtin_ffs(N) - 1;}
int countOn(ll mask){ return __builtin_popcountll(mask); }
int countOff(ll mask){ return msb(mask) - countOn(mask) + 1; }

// Math

ll nC2(ll n) { return (n * (n - 1)) / 2; }
ll nc3(ll n) { return (n * (n - 1) * (n - 2)) / 6; }

ll apsum(ll n, ll a = 1, ll d = 1){ return (n * (a + a + (n - 1) * d) ) / 2; }

ll lcm(ll a, ll b){ return (a / __gcd(a, b) ) * b; }

ll sqr(ll n){ return n * n; }
ll cub(ll n){ return n * n * n; }

template<typename A, typename P>
int bigMod(A a, P p, const int MOD){
  int ret = 1;
  while(p){
    if(p & 1)ret = (1LL * ret * a) % MOD;
    a = (1LL * a * a) % MOD;
    p >>= 1LL;
  }
  return ret;
}

template<typename T>
T toBase(T n, T base){
  T ret = 0LL;
  while(n){
    ret += n % base;
    ret *= 10LL;
    n /= base;
  }
  return ret;
}

template<class T> struct Fraction{T a, b; Fraction(T a = 0,T b = 1); string toString();};
template<class T> Fraction<T>::Fraction(T a,T b){T d=__gcd(a,b);a/=d;b/=d;if (b<0) a=-a,b=-b;this->a=a;this->b=b;}
template<class T> string Fraction<T>::toString(){ostringstream sout;sout<<a<<" / "<<b;return sout.str();}
template<class T> Fraction<T> operator+(Fraction<T> p,Fraction<T> q){return Fraction<T>(p.a*q.b+q.a*p.b,p.b*q.b);}
template<class T> Fraction<T> operator-(Fraction<T> p,Fraction<T> q){return Fraction<T>(p.a*q.b-q.a*p.b,p.b*q.b);}
template<class T> Fraction<T> operator*(Fraction<T> p,Fraction<T> q){return Fraction<T>(p.a*q.a,p.b*q.b);}
template<class T> Fraction<T> operator/(Fraction<T> p,Fraction<T> q){return Fraction<T>(p.a*q.b,p.b*q.a);}

// Misc

ll rand(ll l, ll r) { //[l, r]
  #ifdef LOCAL
  static mt19937_64 gen;
  #else
  static mt19937_64 gen(chrono::steady_clock::now().time_since_epoch().count());
  #endif
  return uniform_int_distribution<ll>(l, r)(gen);
}

template<typename T>
ll sumv(std::vector<T> &v){ return std::accumulate(all(v), 0); }

template<typename T>
T minv(std::vector<T> &v){ return *std::min_element(all(v)); }

template<typename T>
T maxv(std::vector<T> &v){ return *std::max_element(all(v)); }

template<typename T>
void make_unique(std::vector<T> &v){ sort(all(v)); v.resize(unique(all(v)) - v.begin()); }

template<typename T>
int lowerBound(std::vector<T> &v, T x){ return v.back() < x ? -1 : lower_bound(all(v), x) - v.begin(); }

template<typename T>
int upperBound(std::vector<T> &v, T x){ return v.back() <= x ? -1 : upper_bound(all(v), x) - v.begin(); }

double startTime;
void showCurrentTime() { printf("%.6lf\n", ((double)clock() - startTime) / CLOCKS_PER_SEC); }

/*-------------------------------------------------------------------------------------------------------*/

const double EPS = 1e-9;
const double PI = acos(-1.0);
const int N = 1e5 + 5;
const int MOD = 1e9 + 7;
const int dx[] = {1, -1, 0, 0, -1, -1, 1, 1};
const int dy[] = {0, 0, 1, -1, -1, 1, -1, 1};

/*-------------------------------------------------------------------------------------------------------*/

int main() {

  int n, k, x, zero = 0;
  cin >> n >> k; std::vector<ll> pos, neg;
  for(int i = 0; i < n; i++) {
    cin >> x;
    if(x == 0) zero++;
    else if(x > 0) pos.pb(x);
    else neg.pb(-x);
  }
  sort(all(pos), greater<ll>());
  sort(all(neg), greater<ll>());

  if(n == neg.sz and k & 1){
    ll ans = 1LL;
    for(int i = n - 1; i >= 0 and k; i--){
      ans = (-1LL * ans * neg[i]) % MOD;
      k--;
    }
    if(ans < 0) ans += MOD;
    ww(ans); return 0;
  }
  // ww(k, pos.sz, neg.sz, zero);

  stack<int> pos_st, neg_st;
  int pi = 0, ni = 0;
  int sign = 1;
  ll ans = 1LL;
  while(pi < pos.sz and ni < neg.sz){
    if(pos[pi] > neg[ni]){
      pos_st.push(pos[pi]);
      ans = (ans * pos[pi]) % MOD;
      pi++;
    }
    else {
      neg_st.push(neg[ni]);
      ans = (ans * neg[ni]) % MOD;
      ni++; 
      sign *= -1;
    }
    k--;
    if(k == 0) break;
  }
  while(pi < pos.sz and k){
    ans = (ans * pos[pi]) % MOD;
    pos_st.push(pos[pi]);
    pi++;
    k--;

  }
  while(ni < neg.sz and k){
    ans = (ans * neg[ni]) % MOD;
    sign *= -1;
    neg_st.push(neg[ni]);
    ni++;
    k--;
  }
  // ww(k, ans, sign, pi, ni);
  if(k){
    ww(0); return 0;
  }

  if(sign == 1){
    ww(ans);
  }
  else {
    if(ni == neg.sz and pi == pos.sz) {
      if(zero) ans = 0;
    }
    else {
      ll pos_top = 0, neg_top = 0, new_pos = 0, new_neg = 0;
      if(pos_st.sz) pos_top = pos_st.top();
      if(neg_st.sz) neg_top = neg_st.top();
      if(pi < pos.sz) new_pos = pos[pi];
      if(ni < neg.sz) new_neg = neg[ni];

      assert(neg_top * new_neg > 0 or pos_top * new_pos > 0);

      // negtop * new_neg | postop * new_pos
      if(pos_top and neg_top * new_neg > pos_top * new_pos){
        ans = ans * bigMod(pos_top, MOD - 2, MOD);
        ans %= MOD;
        ans *= new_neg;
        ans %= MOD;
        sign *= -1;
      }
      else {
        ans = ans * bigMod(neg_top, MOD - 2, MOD);
        ans %= MOD;
        ans *= new_pos;
        ans %= MOD;
        sign *= -1;
      }
    }
    if(sign == -1){
      ans *= -1;
      ans += MOD;
    }
    ww(ans);
  }
  return 0;
}

Measured memory_bytes: 5572