/**
 *              "Bismillahir Rahmanir Rahim"
 *                 _                       _            __
 *   _ __ ___   __| |_   _  __ _ _ __ ___ (_)_ __      / /
 *  | '_ ` _ \ / _` | | | |/ _` | '_ ` _ \| | '_ \    / /
 *  | | | | | | (_| | |_| | (_| | | | | | | | | | |  / /
 *  |_| |_| |_|\__,_|\__, |\__,_|_| |_| |_|_|_| |_| /_/
 *                   |___/
 *                 _                       _        ___   ___ _____
 *   _ __ ___   __| |_   _  __ _ _ __ ___ (_)_ __  / _ \ / _ \___  |
 *  | '_ ` _ \ / _` | | | |/ _` | '_ ` _ \| | '_ \| | | | | | | / /
 *  | | | | | | (_| | |_| | (_| | | | | | | | | | | |_| | |_| |/ /
 *  |_| |_| |_|\__,_|\__, |\__,_|_| |_| |_|_|_| |_|\___/ \___//_/
 *                   |___/
 *   
 *   email:      mdyamin007@yahoo.com
 *   website:    mdyamin007.github.io
 *   facebook:   fb.com/mdyamin007
 *   linkedIn:   linkedin.com/in/mdyamin
 *   created:    06.06.2020
 * 
**/

#include <bits/stdc++.h>
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define int long long
#define double long double
#define pb push_back
#define mp make_pair
#define PI acos(-1)
#define ff first
#define ss second
#define sf scanf
#define pf printf
#define sf1(a) sf("%lld", &a)
#define sf2(a,b) sf("%lld %lld", &a, &b)
#define sf3(a,b,c) sf("%lld %lld %lld", &a, &b, &c)
#define sf4(a,b,c,d) sf("%lld %lld %lld %lld", &a, &b, &c, &d)
#define sf5(a,b,c,d,e) sf("%lld %lld %lld %lld %lld", &a, &b, &c, &d, &e)
#define FOR(i, j, k, in) for (int i=j ; i<k ; i+=in)
#define RFOR(i, j, k, in) for (int i=j ; i>=k ; i-=in)
#define REP(i, j) FOR(i, 0, j, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define RESET(a, b) memset(a, (b), sizeof(a))
#define lb lower_bound
#define ub upper_bound
#define newline pf("\n")
#define endl '\n'
#define sfd(n) sf("%lf", &n)
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define SIZE(v) (int)v.size()
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define on(n,i) (n|=(1<<i))
#define isOn(n,i) (n&(1<<i))
#define off(n,i) (n = isOn(n,i) ? n ^ (1<<i) : n)
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) ((a*b)/gcd(a,b))
#define watch(a) cout << (#a) << " is " << (a) << '\n'
#define watch2(a,b) cout << (#a) << " is " << (a) << " and " << (#b) << " is " << (b) << '\n'
#define MIN3(a,b,c) MIN(a, MIN(b,c))
#define MAX3(a,b,c) MAX(a, MAX(b,c))
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

using namespace std;

typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<vi> vvi;
typedef map<int,int> mpii;
typedef set<int> seti;
typedef multiset<int> mseti;

template <class T>  inline void smax(T &x,T &y){ x = max((x),(y)); y = min((x),(y));}
template <class T>  inline void smin(T &x,T &y){ x = min((x), (y)); y = max((x),(y));}

const int INF = 0x3f3f3f3f3f3f;
const int MOD = 1e9 + 7;

int fx[] = {-1, 1, 0, 0};
int fy[] = {0, 0, -1, 1};

/************************************/

int mod(int n) {
  return (n % MOD + MOD) % MOD;
}

int mul(int a,int b) {
  return mod(mod(a) * mod(b));
}

void Solution() {
  int n, k;
  sf2(n,k);
  vi a(n);
  vi pos, neg;
  REP(i,n) {
    sf1(a[i]);
    if(a[i] > 0) pos.pb(a[i]);
    else neg.pb(a[i]);
  }
  if(pos.size()) {
    int ans = 1;
    sort(ALL(pos),greater<int>());
    SORT(neg);
    if(k & 1) {
      ans = pos[0];
      pos.erase(pos.begin());
      k--;
    }
    vi res;
    for(int i = 0;i + 1 < SIZE(pos);i += 2) {
      res.pb(pos[i]*pos[i+1]);
    }
    for(int i = 0;i + 1 < SIZE(neg);i += 2)
      res.pb(neg[i]*neg[i+1]);
    if(SIZE(pos) & 1 and SIZE(neg) & 1)
      res.pb(neg[SIZE(neg)-1]*pos[SIZE(pos)-1]);
    sort(ALL(res),greater<int>());
    REP(i,k/2)
      ans = mul(ans,res[i]);
    pf("%lld\n", ans);
  }else {
    SORT(neg);
    if(k & 1) REVERSE(neg);
    int ans = 1;
    REP(i,k) ans = mul(ans,neg[i]);
    pf("%lld\n", ans);
  }
}


int32_t main() {
    //FAST_IO
    /*#ifndef ONLINE_JUDGE
	freopen("in.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	#endif*/

    int tc = 1;
	//sf1(tc);
    //cin >> tc;

    FOR(tn,1,tc+1,1) {
        //pf("Case %lld:", tn);
        Solution();  
	}

    return 0;
}

Measured memory_bytes: 8236