//From https://www.codechef.com/problems/MMPROD

#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<utility>
#include<set>
#include<stack>
#include<list>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<cmath>
#include<cctype>


#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define ren(i,a,b) for(int i=a;i>=b;i--)
#define ff first
#define ss second
#define pll pair<long long int,long long int>
#define pii pair<int,int>
#define vll vector<long long int>
#define vii vector<int>
#define gi(n) scanf("%d",&n)
#define gll(n) scanf("%lld",&n)
#define gstr(n) scanf("%s",n)
#define gl(n) cin >> n
#define oi(n) printf("%d",n)
#define oll(n) printf("%lld",n)
#define ostr(n) printf("%s",n)
#define ol(n) cout << n
#define os cout<<" "
#define on cout<<"\n"
#define o2(a,b) cout<<a<<" "<<b
#define all(n) n.begin(),n.end()
#define present(s,x) (s.find(x) != s.end())
#define cpresent(s,x) (find(all(s),x) != s.end())
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
typedef vector<vector<ll> > mat;

ll mod=1e9+7;


int main()
{ios_base::sync_with_stdio(false);
cin.tie(0);
int n,k;
cin>>n>>k;
vll a(n);
bool zero=0;
rep(i,0,n-1)cin>>a[i],zero|=(a[i]==0);
sort(all(a),[&](ll a,ll b){return abs(b) > abs(a);}
);

int sgn=0;
ll prod=1;

ll sn = 1;
vector<ll> nums;
ll gneg = -1e9-1, gpos = 1e9+1;
for(int i = 0, id = n-1; i < k; ++i, id--) {
    if (a[id] < 0) sn *= -1;
    nums.push_back(a[id]);
    if (a[id] < 0)
        gneg = max(gneg, a[id]);
    else
        gpos = min(gpos, a[id]);
}

if (sn > 0) {
    ll ans = 1;
    for(auto x : nums)
        ans = (ans * 1ll * x) % mod;
    cout << (ans + mod) % mod << "\n";
} else {
    ll mn = 1, mx = -1;
    for(int i = 0; i < n-k; ++i) {
        mn = min(mn, a[i]);
        mx = max(mx, a[i]);
    }
    
    //cout << gneg << " " << mx << "\n";
    //cout << gpos << " " << mn << "\n";
    
    bool g1 = gneg != -1e-9-1 && mx != -1;
    bool g2 = gpos != 1e9+1 && mn != 1;
    if (g1 && g2) {
        ll val, repl;
        if (mx * 1ll * gpos > mn * 1ll * gneg)
            val = gneg, repl = mx;
        else
            val = gpos, repl = mn;
        
        for(int i = 0; i < k; ++i)
            if (nums[i] == val) {
                nums[i] = repl;
                break;
            }
        ll ans = 1;
        for(auto x : nums)
            ans = (ans * 1ll * x) % mod;
        cout << (ans + mod) % mod << "\n";
    } else if (g1) {
        for(int i = 0; i < k; ++i)
            if (nums[i] == gneg) {
                nums[i] = mx;
                break;
            }
        ll ans = 1;
        for(auto x : nums)
            ans = (ans * 1ll * x) % mod;
        cout << (ans + mod) % mod << "\n";
    } else if (g2) {
        for(int i = 0; i < k; ++i)
            if (nums[i] == gpos) {
                nums[i] = mn;
                break;
            }
        ll ans = 1;
        for(auto x : nums)
            ans = (ans * 1ll * x) % mod;
        cout << (ans + mod) % mod << "\n";
    } else {
        if (zero)
            cout << "0\n";
        else {
            ll ans = 1;
            for(int i = 0; i < k; ++i)
                ans = (ans * 1ll * a[i]) % mod;
            cout << (ans + mod) % mod << "\n";
        }
    }
    
    
}


return 0;
}



Measured memory_bytes: 6856