#include <bits/stdc++.h>

#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long
#define map unordered_map
#define set unordered_set
#define pll pair<ll, ll>
#define vll vector<ll>
#define mll map<ll, ll>

using namespace std;

const ll MOD = 1000000007LL;
const ll INF = (1LL << 60LL);

ll N, K;

ll adopt_list[200005];

bool found_extra(vector<pair<ll, ll>> &list, bool rev, ll index, ll &out_index1,
                 ll &out_index2) {
  // マイナスをひとつ除く
  out_index1 = -1;
  out_index2 = -1;

  pll found_minus;
  for (ll i = index + 1; i < N; i++) {
    pll p = list[i];

    if (!rev) {
      if (p.second < 0) {
        // adopt_list[i] = 0;
        out_index1 = i;
        break;
      }
    } else {
      if (p.second >= 0) {
        // adopt_list[i] = 0;
        out_index1 = i;
        break;
      }
    }
  }

  // プラスをひとつ足す
  for (ll i = index; i >= 0; i--) {
    pll p = list[i];

    if (!rev) {
      if (p.second >= 0) {
        // adopt_list[i] = 1;
        out_index2 = i;
        break;
      }
    } else {
      if (p.second < 0) {
        // adopt_list[i] = 1;
        out_index2 = i;
        break;
      }
    }
  }

  return (out_index1 >= 0 && out_index2 >= 0);
}

int main() {
  vector<pair<ll, ll>> list;

  fill_n(adopt_list, 200005, 0);

  scanf("%lld %lld", &N, &K);

  ll sum = 1;

  bool minus_only = true;

  for (ll i = 0; i < N; i++) {
    ll v;
    scanf("%lld", &v);
    list.emplace_back(make_pair(abs(v), v));

    sum = sum * v % MOD;

    if (v >= 0) {
      minus_only = false;
    }
  }
  sum = (sum + MOD) % MOD;

  // 全部
  if (N == K) {
    cout << sum << endl;
    return 0;
  }

  bool minus = false;
  if (minus_only && K % 2 == 1) {
    minus = true;
  }

  if (!minus) {
    sort(list.begin(), list.end());
  } else {
    sort(list.rbegin(), list.rend());
  }

  ll index = list.size();
  index--;

  // ll ans = 1;
  ll k = K;

  bool now_plus = true;
  for (;;) {
    if (index < 0) {
      break;
    }
    if (k == 0) {
      break;
    }

    pll p = list[index];
    // cout << "p.second:" << p.second << endl;
    adopt_list[index] = 1;

    // ans = (ans * (p.second % MOD)) % MOD;
    index -= 1;
    k -= 1;

    if (p.second < 0) {
      now_plus = !now_plus;
    }
  }

  if (!now_plus && !minus) {
    // 最後のひとつの調整
    ll index1a, index1b;
    bool ok1 = found_extra(list, false, index, index1a, index1b);

    ll index2a, index2b;
    bool ok2 = found_extra(list, true, index, index2a, index2b);

    ll index_a = -1;
    ll index_b = -1;
    if (ok1 && ok2) {
      ll val1 = list[index1a].first * list[index1b].first;
      ll val2 = list[index2a].first * list[index2b].first;

      index_a = index1a;
      index_b = index1b;

      long double v1 = list[index1b].first;
      v1 /= list[index1a].first;
      long double v2 = list[index2b].first;
      v2 /= list[index2a].first;

      if (v1 > v2) {
        index_a = index1a;
        index_b = index1b;
      } else {
        index_a = index2a;
        index_b = index2b;
      }

    } else if (ok1) {
      index_a = index1a;
      index_b = index1b;
    } else if (ok2) {
      index_a = index2a;
      index_b = index2b;
    } else {
    }

    if (index_a >= 0 && index_b >= 0) {
      adopt_list[index_a] = 0;
      adopt_list[index_b] = 1;
    }
  }

  // 計算
  ll count = 0;
  ll minus_count = 0;
  ll ans = 1;
  for (ll i = 0; i < N; i++) {
    if (adopt_list[i]) {
      ans = (ans * (list[i].second)) % MOD;
      ans = (ans + MOD) % MOD;
      if (list[i].second < 0) {
        minus_count++;
      }
      count++;
    }
  }
  // cout << "count:" << count << endl;
  // cout << "minus_count:" << minus_count << endl;
  cout << ans << endl;
}


Measured memory_bytes: 9012