// Problem : E - Multiplication 4
// Contest : AtCoder - AtCoder Beginner Contest 173
// URL : https://atcoder.jp/contests/abc173/tasks/abc173_e
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#define int long long
#define fastio                      \
  ios_base::sync_with_stdio(false); \
  cin.tie(0);                       \
  cout.tie(0);
#define sz(a) (int)((a).size())
#define pb push_back
#define mp make_pair
#define db1(x) cout << #x << "=" << x << endl
#define db2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z)                                                       \
  cout << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z \
       << endl
#define dbp(x) \
  cout << #x << "= {" << (x.first) << ", " << (x.second) << "}" << endl;
#define dbv(v)                         \
  {                                    \
    cout << #v << " : ";               \
    for (auto x : v) cout << x << ' '; \
    cout << endl;                      \
  }
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define rep2(i, a, b) for (int i = a; i >= b; i--)
#define die(x) return cout << x << '\n', 0;

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

bool comp(int n1, int n2) { return llabs(n1) > llabs(n2); }
bool comp2(int n1, int n2) { return llabs(n1) < llabs(n2); }
const int MOD = 1e9 + 7;
ll modulo(ll a, ll b) {
  ll n = MOD;
  ll x = 1, y = a;
  while (b > 0) {
    if (b % 2 == 1) {
      x = (x * y) % n;  // multiplying with base
    }
    y = (y * y) % n;  // squaring the base
    b /= 2;
  }
  return x % n;
}
int32_t main() {
  fastio;
  // freopen("random_pm00.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
  int testcases;
  testcases = 1;
  // cin>>testcases;

  while (testcases--) {
    int n, k;
    cin >> n >> k;
    vector<int> vec(n);
    int neg = 0, pos = 0;
    rep(i, 0, n - 1) {
      cin >> vec[i];
      if (vec[i] > 0)
        pos++;
      else if (vec[i] < 0)
        neg++;
    }

    // db3(n, neg, pos);
    int ans = 0;
    bool flag = false;
    for (int i = 0; i <= pos; i++) {
      int noob = k - i;
      if (noob >= 0 && noob % 2 == 0 && noob <= neg) {
        flag = true;
      }
    }
    // db1(flag);
    if (flag) {
      ans = 1;
      sort(vec.begin(), vec.end(), comp);
      int temp = 1, temp2 = 1;
      int nc = 0;
      int i = 0;
      // dbv(vec);
      for (; i < k; i++) {
        ans = (ans * ((MOD + vec[i]) % MOD)) % MOD;
        // db1(ans);
        if (vec[i] < 0) {
          nc++;
          temp = vec[i];
        } else {
          temp2 = vec[i];
        }
      }
      // db1(nc);
      int j = i;
      int m1 = 1, m2 = 1, p = 1, q = 1;
      if (nc % 2 == 1) {
        for (; i < n; i++) {
          if (vec[i] > 0) {
            m1 = (((m1 * ((vec[i] + MOD) % MOD)) % MOD) + MOD) % MOD;
            p = llabs(vec[i]);
            int inv = ((modulo((MOD + temp) % MOD, MOD - 2) + MOD) % MOD);
            // db1(inv);
            m1 = (m1 * ((modulo((MOD + temp) % MOD, MOD - 2) + MOD) % MOD)) %
                 MOD;
            // db3(m1, p, temp);
            break;
          }
        }
        i = j;

        for (; i < n; i++) {
          if (vec[i] < 0) {
            m2 = (((m2 * ((vec[i] + MOD) % MOD)) % MOD) + MOD) % MOD;
            q = llabs(vec[i]);
            int inv = ((modulo((MOD + temp2) % MOD, MOD - 2) + MOD) % MOD);
            // db1(inv);
            m2 = (m2 * ((modulo((MOD + temp2) % MOD, MOD - 2) + MOD) % MOD)) %
                 MOD;
            // db3(m2, q, temp2);
            break;
          }
        }
        // db2(p, temp2);
        // db2(q, temp);
        // db2(p * llabs(temp2), q * llabs(temp));
        if (temp2 == 1 || p * llabs(temp2) > q * llabs(temp)) {
          // cout << "taking pos\n";
          ans = (ans * m1) % MOD;
        } else {
          // cout << "taking neg\n";
          ans = (ans * m2) % MOD;
        }
      }

      die(ans);
    } else if (neg + pos != n) {
      die(0);
    } else if (neg + pos >= k) {
      ans = 1;
      sort(vec.begin(), vec.end(), comp2);
      // dbv(vec);
      int i = 0;
      for (int c = 0; c < k; c++, i++) {
        ans = (ans * vec[i]) % MOD;
      }
      die((ans + MOD) % MOD);
    }
  }

  return 0;
}


Measured memory_bytes: 4784