void main() {
  problem();
}

void problem() {
  const N = scan!int;
  const K = scan!int;
  auto A = scan!long(N).sort().sort!((a, b) => a.abs > b.abs).array;

  long solve() {
    if (K == N) return A.reduce!((r, a) => r.mulmod(a));
    if (A.all!(a => a < 0) && K % 2 == 1) return A[N-K..N].reduce!((r, a) => r.mulmod(a));

    auto aPlus = A.filter!(a => a >= 0).array;
    auto aMinus = A.filter!(a => a < 0).array;

    long plus, minus;
    long ans = 1;
    while(minus + plus != K) {
      if (aMinus.length - minus < 2) {
        ans = ans.mulmod(aPlus[plus++]);
        continue;
      }
      if (aPlus.length - plus < 2) {
        ans = ans.mulmod(aMinus[minus++]).mulmod(aMinus[minus++]);
        continue;
      }

      [ans, plus, minus].deb;

      auto minusTest = aMinus[minus] * aMinus[minus + 1];
      auto plusTest = aPlus[plus] * aPlus[plus + 1];

      if (minusTest >= plusTest) {
        ans = ans.mulmod(aMinus[minus++]).mulmod(aMinus[minus++]);
      } else {
        ans = ans.mulmod(aPlus[plus++]).mulmod(aPlus[plus++]);
      }
    }

    return ans;
  }

  solve().writeln;
}

// ----------------------------------------------

import std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric;
T[][] combinations(T)(T[] s, in int m) {   if (!m) return [[]];   if (s.empty) return [];   return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }
string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T scan(T)(){ return scan.to!T; }
T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; }
void deb(T ...)(T t){ debug writeln(t); }
alias Point = Tuple!(long, "x", long, "y");

enum MOD = 10^^9 + 7;
long mulmod(long a, long b) { auto m = a * b; return m < 0 ? MOD + (m % MOD) : m % MOD; }

// -----------------------------------------------
