#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define endl '\n'
#define pb push_back
#define PI 3.14159265
int M = 1000000007;
int32_t main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, k;
  cin >> n >> k;
  vector<int> pos;
  vector<int> neg;
  int zero = 0;
  int a[n];
  for (int i = 0; i < n; ++i)
  {
    int x;
    cin >> x;
    a[i] = x;
    if (x > 0)
    {
      pos.pb(x);
    }
    else if (x < 0)
      neg.pb(-1 * x);
    else
      zero++;
  }
  if (k == n)
  {
    int ans = 1;
    for (int i = 0; i < n; ++i)
    {
      a[i] += M;
      a[i] %= M;
      ans *= a[i];
      ans %= M;
    }
    cout << ans;
    exit(0);
  }
  if (k % 2 == 0)
  {
    sort(pos.begin(), pos.end());
    sort(neg.begin(), neg.end());
    int cnt = 0;
    if (pos.size() / 2 + neg.size() / 2 < k / 2)
    {
      cout << "0";
      exit(0);
    }
    int ans = 1;
    while (cnt != k)
    {
      int t1 = 0;
      bool flag1 = 0;
      bool flag2 = 0;
      int l1, sl1;
      if (pos.size() >= 2)
      {
        flag1 = 1;
        l1 = pos.back();
        pos.pop_back();
        sl1 = pos.back();
        pos.pop_back();
        t1 = l1 * sl1;
      }
      int t2 = 0;
      int l2, sl2;
      if (neg.size() >= 2)
      {
        flag2 = 1;
        l2 = neg.back();
        neg.pop_back();
        sl2 = neg.back();
        neg.pop_back();
        t2 = l2 * sl2;
      }
      if (t1 >= t2)
      {
        t1 %= M;
        ans *= t1;
        ans %= M;
        if (flag2 == 1)
        {
          neg.push_back(sl2);
          neg.push_back(l2);
        }
      }
      else
      {
        t2 %= M;
        ans *= t2;
        ans %= M;
        if (flag1 == 1)
        {
          pos.push_back(sl1);
          pos.push_back(l1);
        }
      }
      cnt += 2;
    }
    cout << ans;
  }
  else
  {
    if (pos.size())
    {
      sort(pos.begin(), pos.end());
      int ans = pos.back();
      pos.pop_back();
      k--;
      sort(neg.begin(), neg.end());
      int cnt = 0;
      if (pos.size() / 2 + neg.size() / 2 < k / 2)
      {
        cout << "0";
        exit(0);
      }
      while (cnt != k)
      {
        int t1 = 0;
        bool flag1 = 0;
        bool flag2 = 0;
        int l1, sl1;
        if (pos.size() >= 2)
        {
          flag1 = 1;
          l1 = pos.back();
          pos.pop_back();
          sl1 = pos.back();
          pos.pop_back();
          t1 = l1 * sl1;
        }
        int t2 = 0;
        int l2, sl2;
        if (neg.size() >= 2)
        {
          flag2 = 1;
          l2 = neg.back();
          neg.pop_back();
          sl2 = neg.back();
          neg.pop_back();
          t2 = l2 * sl2;
        }
        if (t1 >= t2)
        {
          t1 %= M;
          ans *= t1;
          ans %= M;
          if (flag2 == 1)
          {
            neg.push_back(sl2);
            neg.push_back(l2);
          }
        }
        else
        {
          t2 %= M;
          ans *= t2;
          ans %= M;
          if (flag1 == 1)
          {
            pos.push_back(sl1);
            pos.push_back(l1);
          }
        }
        cnt += 2;
      }
      cout << ans;
    }
    else
    {
      if (zero)
      {
        cout << "0";
        exit(0);
      }
      else
      {
        int ans = 1;
        sort(neg.begin(), neg.end());
        for (int i = 0; i < k; ++i)
        {
          ans *= (-1 * neg[i]);
          ans += M;
          ans %= M;
        }
        cout << ans;
      }
    }
  }


}


Measured memory_bytes: 6800