#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPLL(i, n) for (ll i = 0; i < (ll)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;

// ABC173 E - Multiplication 4
// 2020.07.07
ll MOD = 1e9+7;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, K; cin >> N >> K;
  vector<ll> A(N);
  vector<ll> m;
  vector<ll> p;
  ll ans = 1;
  REP(i, N){
    ll tmp; cin >> tmp;
    ans = (ans*tmp)%MOD;
    if(tmp < 0){
      m.push_back((-1)*tmp);
    }else{
      p.push_back(tmp);
    }
  }

  if(m.size() > 0) sort(m.begin(), m.end(), greater<ll>());
  if(p.size() > 0) sort(p.begin(), p.end(), greater<ll>());

  int mi = -1;
  int pi = -1;

  if(N == K){
    if(ans < 0) ans = (MOD+ans)%MOD;
    cout << ans << endl;
    return 0;
  }else if(p.size() == 0 && K%2 == 1){
    ans = 1;
    int idx = m.size();
    REP(i, K){
      ans = (ans*(-1)*m[idx-1-i])%MOD;
    }
    if(ans < 0) ans = (MOD+ans)%MOD;
    cout << ans << endl;
    return 0;
  }else{
    ans = 1;
    REP(i, K){
      if(mi == m.size()-1){
        ans = (ans*p[pi+1])%MOD;
        pi++;
      }else if(pi == p.size()-1){
        ans = (ans*(-1)*m[mi+1])%MOD;
        mi++;
      }else{
        if(p[pi+1] >= m[mi+1]){
          ans = (ans*p[pi+1])%MOD;
          pi++;
        }else{
          ans = (ans*(-1)*m[mi+1])%MOD;
          mi++;
        }
      }
    }
  }
  
  if(ans >= 0){
    if(ans < 0) ans = (MOD+ans)%MOD;
    cout << ans << endl;
    return 0;
  }else{
    if(mi == m.size()-1){
      mi--;
      pi++;
      ans = 1;
      REP(i, mi+1){
        ans = (ans*(-1)*m[i])%MOD;
      }
      REP(i, pi+1){
        ans = (ans*p[i])%MOD;
      }
      if(ans < 0) ans = (MOD+ans)%MOD;
      cout << ans << endl;
      return 0;
    }else if(pi == p.size()-1){
      pi--;
      mi++;
      ans = 1;
      REP(i, mi+1){
        ans = (ans*(-1)*m[i])%MOD;
      }
      REP(i, pi+1){
        ans = (ans*p[i])%MOD;
      }
      if(ans < 0) ans = (MOD+ans)%MOD;
      cout << ans << endl;
      return 0;
    }else if(pi == -1){
      mi--;
      pi++;
      ans = 1;
      REP(i, mi+1){
        ans = (ans*(-1)*m[i])%MOD;
      }
      REP(i, pi+1){
        ans = (ans*p[i])%MOD;
      }
      if(ans < 0) ans = (MOD+ans)%MOD;
      cout << ans << endl;
      return 0;
    }else if(mi == -1){
      pi--;
      mi++;
      ans = 1;
      REP(i, mi+1){
        ans = (ans*(-1)*m[i])%MOD;
      }
      REP(i, pi+1){
        ans = (ans*p[i])%MOD;
      }
      if(ans < 0) ans = (MOD+ans)%MOD;
      cout << ans << endl;
      return 0;
    }else{
      if(m[mi+1]*m[mi] >= p[pi+1]*p[pi]){
        pi--;
        mi++;
        ans = 1;
        REP(i, mi+1){
          ans = (ans*(-1)*m[i])%MOD;
        }
        REP(i, pi+1){
          ans = (ans*p[i])%MOD;
        }
        if(ans < 0) ans = (MOD+ans)%MOD;
        cout << ans << endl;
        return 0;
      }else{
        pi++;
        mi--;
        ans = 1;
        REP(i, mi+1){
          ans = (ans*(-1)*m[i])%MOD;
        }
        REP(i, pi+1){
          ans = (ans*p[i])%MOD;
        }
        if(ans < 0) ans = (MOD+ans)%MOD;
        cout << ans << endl;
        return 0;
      }
    }
  }
}

Measured memory_bytes: 6804