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

using ll = long long;
static const ll MOD = 1e9 + 7;

// 繰り返し自乗法(x^nをmで割った余り) O(logn)
ll power(ll x, ll n, ll m) {
  ll res = 1;
  if (n > 0) {
    res = power(x, n / 2, m);
    if (n % 2 == 0) res = (res * res) % m;
    else res = (((res * res) % m) * x) % m;
  }
  return res;
}

ll modinv(ll x, ll m) {
  return power(x, m - 2, m);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  ll n, k;
  cin >> n >> k;
  
  vector<ll> a(n), neg, pos;
  ll zero = 0;
  for (ll i = 0; i < n; i++) {
    cin >> a.at(i);
    if (a.at(i) < 0) neg.emplace_back(a.at(i));
    else if (a.at(i) > 0) pos.emplace_back(a.at(i));
    else zero++;
  }
  
  // always zero
  if (n - zero < k) {
    cout << 0 << '\n';
    return 0;
  }
  
  sort(pos.rbegin(), pos.rend());
  sort(neg.begin(), neg.end());
  
  if (n - zero == k) {
    ll ans = 1;
    for (ll i = 0; i < pos.size(); i++) {
      ans *= pos.at(i);
      ans %= MOD;
    }
    for (ll i = 0; i < neg.size(); i++) {
      ans *= abs(neg.at(i));
      ans %= MOD;
    }
    if (neg.size() % 2 == 1) {
      if (zero > 0) {
        cout << 0 << '\n';
        return 0;
      }
      else {
        ans = ans * (-1) + MOD;
        ans %= MOD;
        cout << ans << '\n';
        return 0;
      }
    }
    else {
      cout << ans << '\n';
      return 0;
    }
  }
  
  if (neg.size() == 0) {
    ll ans = 1;
    for (ll i = 0; i < k; i++) {
      ans *= pos.at(i);
      ans %= MOD;
    }
    cout << ans << '\n';
    return 0;
  }
  
  if (pos.size() == 0 && k % 2 == 1) { // answer is negative number or zero
    if (zero > 0) {
      cout << 0 << '\n';
      return 0;
    }
    // accumulate absolute value
    ll ans = 1;
    sort(neg.rbegin(), neg.rend());
    for (ll i = 0; i < k; i++) {
      ans *= abs(neg.at(i));
      ans %= MOD;
    }
    ans = ans * (-1) + MOD;
    ans %= MOD;
    cout << ans << '\n';
    return 0;
  }
  else if (pos.size() == 0 && k % 2 == 0) {
    ll ans = 1;
    for (ll i = 0; i < k; i++) {
      ans *= abs(neg.at(i));
      ans %= MOD;
    }
    cout << ans << '\n';
    return 0;
  }
  else { // answer is positive number
    sort(pos.rbegin(), pos.rend());
    sort(neg.begin(), neg.end());
    pos.emplace_back(0); // sentinel
    neg.emplace_back(0); // sentinel
    ll posit = 0, negit = 0;
    ll ans = 1;
    for (ll i = 0; i < k; i++) {
      if (pos.at(posit) >= abs(neg.at(negit))) {
        ans *= pos.at(posit);
        ans %= MOD;
        posit++;
      }
      else {
        ans *= abs(neg.at(negit));
        ans %= MOD;
        negit++;
      }
    }
    
    if (negit % 2 == 0) {
      cout << ans << '\n';
      return 0;
    }
    
    if (pos.at(posit) == 0 && neg.at(negit) == 0) {
      if (zero > 0) {
        cout << 0 << '\n';
        return 0;
      }
      else {
        //cout << ans << endl;
        ans *= (-1);
        ans += MOD;
        ans %= MOD;
        cout << ans << '\n';
        return 0;
      }
    }
    else if (pos.at(posit) == 0) {
      posit--;
      ans *= modinv(pos.at(posit), MOD);
      ans %= MOD;
      ans *= abs(neg.at(negit));
      ans %= MOD;
      negit++;
    }
    else if (neg.at(negit) == 0) {
      negit--;
      ans *= modinv(abs(neg.at(negit)), MOD);
      ans %= MOD;
      ans *= pos.at(posit);
      ans %= MOD;
      posit++;
    }
    else {
      if (posit == 0) {
        negit--;
        ans *= modinv(abs(neg.at(negit)), MOD);
        ans %= MOD;
        ans *= pos.at(posit);
        ans %= MOD;
        posit++;
      }
      else if (negit == 0) {
        posit--;
        ans *= modinv(pos.at(posit), MOD);
        ans %= MOD;
        ans *= abs(neg.at(negit));
        ans %= MOD;
        negit++;
      }
      else if (pos.at(posit - 1) * pos.at(posit) <= abs(neg.at(negit - 1)) * abs(neg.at(negit))) {
        posit--;
        ans *= modinv(pos.at(posit), MOD);
        ans %= MOD;
        ans *= abs(neg.at(negit));
        ans %= MOD;
        negit++;
      }
      else {
        negit--;
        ans *= modinv(abs(neg.at(negit)), MOD);
        ans %= MOD;
        ans *= pos.at(posit);
        ans %= MOD;
        posit++;
      }
    }
    
    cout << ans << '\n';
    return 0;
  }
}

Measured memory_bytes: 6880