#include <bits/stdc++.h>
#define lli long long int
#define vec2 vector<vector<lli>> 
#define fio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define FRE freopen("explicit.in","r",stdin);freopen("explicit.out","w",stdout)
#define mp make_pair
#define pll pair <lli,lli>
#define vll vector <lli>
#define pq2 priority_queue<pair<lli,lli>>
#define f first
#define s second
#define pb push_back
#define pf push_front
#define minii LLONG_MAX
#define all(x) x.begin(), x.end()
#define mem(a,b) memset(a,b,sizeof(a))
#define ld long double 
const long double pi = 3.1415926535898;
#define dec greater<lli>()
const lli mod=1000000007;
//const lli mod=100000000;
using namespace std;
lli lcm (lli a, lli b) {return ((a*b)/__gcd(a,b));}
lli modpower (lli a,lli b)
{
    if(b==0) return 1;
    lli c=modpower(a,b/2)%mod;
    if (b%2) return (((a*c)%mod)*c)%mod;
    else return (c*c)%mod;
}
lli power (lli a,lli b)
{
    if(b==0) return 1;
    lli c=power(a,b/2);
    if (b%2) return (a*c*c);
    else return c*c;
}
lli sieve (int n)
{
    bool qrr[n+1];
    for (int i=0;i<=n;i++)
    qrr[i]=1;qrr[0]=0;qrr[1]=0;
    for (int i=2;i*i<=n;i++)
    {
        if (qrr[i]==1)
        {
            for (int j=i*i;j<=n;j+=i)
            {qrr[j]=0;}
        }
    }
    return 0;
}
int main()
{
    fio;
    lli n,k;
    cin>>n>>k;
    lli a[n];
    vll v,w;
    for (int i=0;i<n;i++)
    {cin>>a[i];if (a[i]>=0) v.pb(a[i]);else w.pb(abs(a[i]));}
    lli ans=1;
    if (n==k)
    {
        for (int i=0;i<n;i++)
        {
            ans*=a[i];ans%=mod;
            ans+=mod;ans%=mod;
        }
        cout<<ans;exit(0);
    }
    sort(all(v));sort(all(w));
    bool flag=0;
    if (v.size()==0&&k%2)
    flag=1;
    if (flag==0)
    {
        while (k>0)
        {
            if (k%2==1)
            {
                ans*=v[v.size()-1];ans%=mod;
                v.pop_back();
                k--;continue;
            }
            if (v.size()>1&&w.size()>1)
            {
                if (v[v.size()-1]*v[v.size()-2]>w[w.size()-1]*w[w.size()-2])
                {
                    ans*=v[v.size()-1];ans%=mod;
                    ans*=v[v.size()-2];ans%=mod;
                    v.pop_back();v.pop_back();
                }
                else
                {
                    ans*=w[w.size()-1];ans%=mod;
                    ans*=w[w.size()-2];ans%=mod;
                    w.pop_back();w.pop_back();
                }
                k-=2;
                continue;
            }
            if (w.size()<=1&&v.size()>1)
            {
                ans*=v[v.size()-1];ans%=mod;
                ans*=v[v.size()-2];ans%=mod;
                v.pop_back();v.pop_back();
                k-=2;
                continue;
            }
            if (v.size()<=1&&w.size()>1)
            {
                ans*=w[w.size()-1];ans%=mod;
                ans*=w[w.size()-2];ans%=mod;
                w.pop_back();w.pop_back();
                k-=2;continue;
            }
        }
        cout<<ans;exit(0);
    }
    else
    {
        for (int i=0;i<k;i++)
        {
            ans*=((-1)*w[i]);ans%=mod;
            ans+=mod;ans%=mod;
            //cout<<ans<<"\n";
        }
        cout<<ans;
    }
    return 0;
}

Measured memory_bytes: 6912