#include<bits/stdc++.h>
using namespace std;

#define ff first
#define ss second
#define PI acos(-1)
#define pb push_back
#define int long long
#define ld long double
#define sp fixed<<setprecision
#define bp __builtin_popcountll
#define all(x) x.begin(),x.end()
#define pii pair<long long,long long>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

const int M = (1e9)+7;
const int N = 1e6+5;

signed main()
{
    FAST
    int tc=1;
    //cin>>tc;
    for(int ti=1;ti<=tc;ti++)
    {
        int n,k,zeros=0;
        cin>>n>>k;
        multiset<int> pos,neg;
        for(int i=0;i<n;i++)
        {
            int x;
            cin>>x;
            if(x > 0)pos.insert(x);
            else if(x < 0)neg.insert(-x);
            else zeros++;
        }

        multiset<int> now,pos_taken,neg_taken;

        //First take k largest elements(except 0)
        while(now.size() < k)
        {
            if(!pos.size() && !neg.size())break;
            int op1 = pos.size() ? *pos.rbegin() : 0;
            int op2 = neg.size() ? *neg.rbegin() : 0;
            if(op1 >= op2)pos.erase(pos.find(op1)),pos_taken.insert(op1);
            else if(op1 < op2)neg.erase(neg.find(op2)),neg_taken.insert(op2);
            now.insert(max(op1,op2));
        }

        //If at least one zero has to be taken
        if(now.size() < k)return cout<<0,0;

        //If among the largest k, the number of negatives taken is odd
        int neg_flag = 0;
        if(neg_taken.size() % 2)
        {
            // Option 1 : remove the smallest negative taken and add the largest positive available
            // Option 2 : remove the smallest positive taken and add the largest negative available

            int op1 = (neg_taken.size() && pos.size());
            int op2 = (pos_taken.size() && neg.size());
            int ok = (op1 || op2);

            //If at least one option is available
            if(ok)
            {
                if(op1 && !op2)
                {
                    now.erase(now.find(*neg_taken.begin()));
                    now.insert(*pos.rbegin());
                }
                else if(!op1 && op2)
                {
                    now.erase(now.find(*pos_taken.begin()));
                    now.insert(*neg.rbegin());
                }
                else
                {
                    int chk = ( (*pos.rbegin())*(*pos_taken.begin()) >= (*neg.rbegin())*(*neg_taken.begin()) );
                    if(chk)
                    {
                        //Option 1 is better
                        now.erase(now.find(*neg_taken.begin()));
                        now.insert(*pos.rbegin());
                    }
                    else
                    {
                        //Option 2 is better
                        now.erase(now.find(*pos_taken.begin()));
                        now.insert(*neg.rbegin());
                    }
                }
            }
            else
            {
                // Now we cannot have >0 answer, so we try to get as less negative as possible.
                if(zeros)
                {
                    //At least one zero is available. Add it in the set and answer will be 0.
                    now.erase(now.begin());
                    now.insert(0);
                }
                else
                {
                    //Answer will be <0 take the smallest k elements out of all available.
                    multiset<int> sab;
                    for(int i:neg_taken)sab.insert(i);
                    for(int i:pos_taken)sab.insert(i);
                    for(int i:neg)sab.insert(i);
                    for(int i:pos)sab.insert(i);
                    now.clear();
                    for(int i=0;i<k;i++)now.insert(*sab.begin()),sab.erase(sab.begin());
                    neg_flag = 1;
                }
            }
        }

        //Calculate and print the answer
        int ans = 1;
        for(int i:now)ans *= i,ans %= M;
        if(neg_flag)ans *= -1;
        ans += M; ans %= M;
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 31628