#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
using less_set = tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>;
using great_set = tree<int, null_type, greater<int>, rb_tree_tag, tree_order_statistics_node_update>;
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);
const int N = 2e3+69;
#define ALL(x) begin(x),end(x)
#define sz(x) (ll)x.size()
const int OO = 0x3f3f3f3f;
const int mod = 1e9+7;

int n, k, tmp, x;
ll arr[200069];
vector<ll> ans;
deque<ll> pos;
deque<ll> neg;
bool z = 0;
int main()
{
    FIO
    ll sum = 1LL;
    cin >> n >> k;
    tmp = k;
    for(int i = 0; i< n; i++)
    {
        cin >> x;
        if(x < 0)
        {
            neg.push_back(x);
        }
        else if(x > 0)
        {
            pos.push_back(x);
        }
        else
            z = 1;
        ans.push_back(x);
    }
    if(n == k)
    {
        for(ll g : ans)
        {
            sum = ((sum%mod) * (g%mod))%mod;
        }
        cout << (sum%mod + mod)%mod << "\n";
        return 0;
    }
    ans.clear();
    sort(ALL(pos), greater<ll>());
    sort(ALL(neg));
    ll mnpos = 99999999999;
    for(int o = 0; o < k; o++)
    {
        if(sz(pos) && sz(neg) >= 2)
        {
            if(pos[0]*pos[1] >= neg[0]*neg[1])
            {
                ans.push_back(pos[0]);
                mnpos = min(pos[0], mnpos);
                pos.pop_front();
                continue;
            }
            else if(o < k-1)
            {
                ans.push_back(neg[0]);
                ans.push_back(neg[1]);
                neg.pop_front();
                neg.pop_front();
                o++;
                continue;
            }
        }
        if(sz(pos))
        {
            ans.push_back(pos[0]);
            mnpos = min(pos[0], mnpos);
            pos.pop_front();
            continue;
        }
        if(sz(neg) >= 2 && o < k-1)
        {
            //cout << o << "\n";
            ans.push_back(neg[0]);
            ans.push_back(neg[1]);
            neg.pop_front();
            neg.pop_front();
            o++;
            continue;
        }
    }
    //cout << sz(ans) << "\n";
    if(sz(ans) == tmp)
    {
        //cout << "here1\n";
        for(ll g : ans)
        {
            sum = ((sum%mod) * (g%mod))%mod;
        }
        cout << (sum%mod + mod)%mod << "\n";
        return 0;
    }
    if(tmp - sz(ans) > sz(neg))
    {
        cout << 0 << "\n";
        return 0;
    }
    if(sz(neg) == 1)
    {
        if(z)
            cout << 0 << "\n";
        else
        {
            //cout << "here2\n";
            ans.push_back(neg[0]);
            for(ll g : ans)
            {
                sum = ((sum%mod) * (g%mod))%mod;
            }
            cout << (sum%mod + mod)%mod << "\n";
        }

        return 0;
    }
   // cout << sz(neg) << "\n";
    bool good = 0;
    for(int i = 0; i< sz(ans); i++)
    {
        if(ans[i] == mnpos)
        {
            ans[i] = 1;
            good = 1;
            break;
        }
    }
    if(good)
    {
        ans.push_back(neg[0]);
        ans.push_back(neg[1]);
    }
    else if(z)
    {
        cout << 0 << "\n";
        return 0;
    }
    else
    {
        for(int i = 0; i< sz(neg); i++)
        {
            if(i < sz(neg)-1)
                ans[i] = 1;
            ans.push_back(neg[i]);
        }
    }
    for(ll g : ans)
    {
       // cout << g << " " ;
        sum = ((sum%mod) * (g%mod))%mod;
    }
    //cout << "\n";
    //cout << sum << "\n";
    cout << (sum%mod + mod)%mod << "\n";
    return 0;
}


Measured memory_bytes: 6560