using namespace std;
#include<bits/stdc++.h>
#define int long long
#define pb push_back 
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define magnitude first
#define sign second
#define all(x) x.begin(), x.end()
#define repa(i,a,b) for (int i=a; i<=b; i++)
#define repd(i,b,a) for (int i=b; i>=a; i--)
#define endl "\n"
//debugging
#define debug1(a) cout<<#a<<" = "<<(a)<<endl;
#define debug2(a,b) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<endl;
#define debug3(a,b,c) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<endl;
#define debug4(a,b,c,d) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<", "<<#d<<" = "<<(d)<<endl;

const int N = 1e+6+5;
int big = 1e+18+3;
int mod = 1e+9+7;


int mod2 = 998244353;

int power (int base, int exp)
{
    int res = 1;
    base%=mod;
    while(exp)
    {
        if (exp & 1)
        {
            res*=base;
            res%=mod;
        }
        exp>>=1;
        base*=base;
        base%=mod;
    }
    return res;
}

int inv (int arg)
{
    return power(arg, mod-2);
}


signed main()
{
    IOS;
    int ans = 1;   
    int n,k; cin>>n>>k;

    pair<int,int>ar[n+1];

    repa(i,1,n)
    {
        cin>>ar[i].magnitude;
        if (ar[i].magnitude>0)
            ar[i].sign = 1;
        else if (ar[i].magnitude<0)
            ar[i].sign = -1;
        else
            ar[i].sign = 0;

        ar[i].magnitude = abs(ar[i].magnitude);
    }


    sort( ar + 1, ar + 1 + n );
    reverse(ar+1,ar+1+n);

    int pos(0),neg(0),zero(0);
    int smallest_neg = mod;
    int smallest_pos = mod;

    repa(i,1,k)
    {
        pos+=ar[i].sign==1; 
        neg+=ar[i].sign==-1; 
        zero+=ar[i].sign==0;

        if ( ar[i].sign==1 )
            smallest_pos = min(smallest_pos,ar[i].magnitude);

        if ( ar[i].sign==-1 )
            smallest_neg = min(smallest_neg,ar[i].magnitude);
    }
//    debug2(smallest_pos,smallest_neg);
    if (zero)
    {
        cout<< 0 <<endl;
        return 0;
    }

    if ( neg%2==0 )
    {
        repa(i,1,k)
            ans*=ar[i].magnitude, ans%=mod;
        cout<< ans <<endl;
        return 0;
    }
//    debug3(pos,neg,zero);
    int taking1 = -1;
    int replacing1 = smallest_pos;

    int taking2 = -1;
    int replacing2 = smallest_neg;

    if ( smallest_pos!=mod )
    {
        repa(i,k+1,n)
            if (ar[i].sign==-1)
            {
                taking1 = ar[i].magnitude;
                break;
            }
    }

    if ( smallest_neg!=mod )
    {
        repa(i,k+1,n)
            if (ar[i].sign==1)
            {
                taking2 = ar[i].magnitude;
                break;
            }
    }

    pair<int,int>fct1 = make_pair(1,1);
    pair<int,int>fct2 = make_pair(1,1);
    bool ok1 = false, ok2 = false;

    if ( taking1!=-1 && replacing1!=mod )
        fct1 = make_pair(taking1,replacing1), ok1 = true;

    if (taking2!=-1 && replacing2!=mod)
        fct2 = make_pair(taking2,replacing2), ok2 = true;

//    debug2(ok1,ok2);

    if (ok1 || ok2)
    {
        pair<int,int>fct;
        if ( ok1 && ok2 )
        {
            if ( fct1.first*fct2.second>=fct2.first*fct1.second )
                fct = fct1;
            else
                fct = fct2;
        }

        else if (ok1)
            fct = fct1;
        else
            fct = fct2;

        repa(i,1,k)
            ans*=ar[i].magnitude, ans%=mod;

        ans*=fct.first;
        ans%=mod;
        ans*=inv(fct.second);
        ans%=mod;
    }

    else
    {
    //    cout<<"Hey"<<endl;
        if (zero)
            ans = 0;
        else
        {
            reverse(ar+1,ar+1+n);

            repa(i,1,k)
                ans*=ar[i].magnitude, ans%=mod;
            ans*=-1;
            ans+=mod;
        }
    }

    cout<< ans%mod <<endl;
}

Measured memory_bytes: 6820