#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());

const int M = (int) 1e9 + 7;

int add(int a, int b) {
  a += b;
  if (a >= M) {
    return a - M;
  }
  if (a < 0) {
    return a + M;
  }
  return a;
}

int mul(int a, int b) {
  return a * (ll) b % M;
}

const int N = (int) 2e5 + 7;
vector<int> pz;
vector<int> ng;
int czr, cpz, cng, e[N];

bool cmp_1(int x, int y) {
  return abs(x) < abs(y);
}

vector<int> bet(vector<int> a, vector<int> b) {
  if (a.empty()) {
    return b;
  }
  if (b.empty()) {
    return a;
  }
  set<int> sa, sb;
  for (auto &i : a) {
    sa.insert(i);
  }
  for (auto &i : b) {
    sb.insert(i);
  }
  set<int> com;
  for (auto &i : sa) {
    if (sb.count(i)) {
      com.insert(i);
    }
  }
  ll pa = 1, pb = 1;
  for (auto &i : a) {
    if (com.count(i) == 0) {
      pa *= abs(e[i]);
    }
  }
  for (auto &i : b) {
    if (com.count(i) == 0) {
      pb *= abs(e[i]);
    }
  }
  if (pa > pb) {
    return a;
  } else {
    return b;
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    e[i] = x;
    if (x == 0) {
      czr++;
      continue;
    }
    if (x > 0) {
      pz.push_back(i);
      continue;
    }
    if (x < 0) {
      ng.push_back(i);
      continue;
    }
  }
  cpz = (int) pz.size();
  cng = (int) ng.size();
  if (cpz + cng < k) {
    cout << "0\n";
    return 0;
  }
  /// can it be positive => can i take even number of negatives?
  bool can = 0;
  for (int cnt = 0; cnt <= cng && cnt <= k; cnt += 2) {
    if (k - cnt <= cpz) {
      can = 1;
      break;
    }
  }
  if (can == 0) {
    if (czr > 0) {
      cout << "0\n";
      return 0;
    }
    sort(e + 1, e + n + 1, cmp_1);
    int sol = 1;
    for (int i = 1; i <= k; i++) {
      if (e[i] > 0) {
        sol = mul(sol, e[i]);
      } else {
        sol = mul(sol, add(0, -e[i]));
      }
    }
    cout << add(0, -sol) << "\n";
    return 0;
  }
  sort(e + 1, e + n + 1, cmp_1);
  reverse(e + 1, e + n + 1);
  vector<int> ids;
  int neg = 0;
  for (int i = 1; (int) ids.size() < k; i++) {
    if (e[i] == 0) {
      continue;
    }
    if (e[i] > 0) {
      ids.push_back(i);
    } else {
      ids.push_back(i);
      neg++;
    }
  }
  if (neg % 2 == 0) {
    int sol = 1;
    for (auto &i : ids) {
      if (e[i] > 0) {
        sol = mul(sol, e[i]);
      } else {
        sol = mul(sol, add(0, -e[i]));
      }
    }
    cout << sol << "\n";
    return 0;
  }
  vector<int> ans;
  /// delete last neg
  int lng = -1;
  for (auto &i : ids) {
    if (e[i] < 0) {
      lng = i;
    }
  }
  if (lng != -1) {
    vector<int> cur;
    for (auto &i : ids) {
      if (i != lng) {
        cur.push_back(i);
      }
    }
    for (int j = ids.back() + 1; j <= n; j++) {
      if (e[j] > 0) {
        cur.push_back(j);
        break;
      }
    }
    if ((int) cur.size() == k) {
      ans = bet(ans, cur);
    }
  }
  /// delete last poz
  int lpz = -1;
  for (auto &i : ids) {
    if (e[i] > 0) {
      lpz = i;
    }
  }
  if (lpz != -1) {
    vector<int> cur;
    for (auto &i : ids) {
      if (i != lpz) {
        cur.push_back(i);
      }
    }
    for (int j = ids.back() + 1; j <= n; j++) {
      if (e[j] < 0) {
        cur.push_back(j);
        break;
      }
    }
    if ((int) cur.size() == k) {
      ans = bet(ans, cur);
    }
  }
  int sol = 1;
  for (auto &i : ans) {
    if (e[i] > 0) {
      sol = mul(sol, e[i]);
    } else {
      sol = mul(sol, add(0, -e[i]));
    }
  }
  cout << sol << "\n";
  return 0;
}


Measured memory_bytes: 36764