#include <bits/stdc++.h>
#define pb push_back
#define ss second
#define ff first
#define all(x) x.begin(), x.end()
#define INF 300000000000001
#define ll_max 9000000000000000000
#define PI 3.14159265358979323846L
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define db(args...) {string _ss = #args; replace(_ss.begin(), _ss.end(), ',' , ' '); stringstream ___s(_ss) ; debug(___s, args);}
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<pair<ll,ll> > vll;
typedef vector<int> vi;
typedef pair<ll,ll> pll;
const ll mod = 1000000007;
const ll N = 1001;
const ll M = log2(N);

struct point {
    ll x, y, i;
    bool operator == (const point b)
    {
        if(this -> x == b.x && this -> y == b.y) return 1;
        return 0;
    }
    bool operator != (const point b) {return !(*this == b);}
    friend bool operator < (const point a, const point b)
    {
        if(a.x != b.x)
            return a.x < b.x;
        return a.y < b.y;
    }
};

void debug(stringstream &s){}
template <typename T, typename... Args>
void debug(stringstream &s, T a, Args... args)
{
    string word;
    s >> word;
    cerr << word << " = " << a << endl;
    debug(s, args...);
}
bool overflow;
ll fast_exp(ll x, ll n)
{
    if(n == 0) return 1;
    ll ans;
    if(n % 2 == 0)
    {
         ans = fast_exp(x, n / 2);
         if(ans > ans * ans % mod)
                overflow = 1;
         ans = ans * ans % mod;
    }
    else
    {
        ans = fast_exp(x, n - 1);
        if(ans > ans * x % mod)
            overflow = 1;
        ans = ans * x % mod;
    }
    return ans;
}


bool cmp(ll a, ll b)
{
    return abs(a) < abs(b);
}

int main()
{
    fast;
    int _ = 1;
    //cin >> _;
    while(_--)
    {
        ll n = 0, m = 0, x = 0, y = 0, ans = 1, k;
        cin >> n >> k;
        vector<ll> pos, neg, a;
        for(int i = 0; i < n; i++)
        {
            cin >> x;
            if(x > 0) pos.pb(x);
            else neg.pb(x);
            a.pb(x);
        }
        y = 0;
        sort(all(pos));
        sort(all(neg), greater<ll>());
        if(k == n && neg.size() % 2 || (n == neg.size() && k % 2))
            y = 1;
        if(y == 1)
        {
            sort(all(a), cmp);
            for(int i = 0; i < k; i++)
            {
                ans = (ans * a[i] % mod + mod) % mod;
            }
        }
        else
        {
            while(k > 0)
            {
                if(k == 1)
                {
                    if(!pos.empty())
                    {
                        ans = ans * pos.back() % mod;
                        break;
                    }
                    else
                    {
                        ans = (ans * ((neg.back() + mod) % mod) % mod) % mod;
                        break;
                    }
                }
                else
                {
                    k -= 2;
                    if(pos.size() > 1 && neg.size() > 1)
                    {
                        if(pos[pos.size() - 1] * pos[pos.size() - 2] > neg[neg.size() - 1] * neg[neg.size() - 2])
                        {
                            ans = ans * pos.back() % mod;
                            pos.pop_back();
                            ans = ans * pos.back() % mod;
                            pos.pop_back();
                        }
                        else
                        {
                            x = neg.back();
                            neg.pop_back();
                            x = x * neg.back();
                            neg.pop_back();
                            x %= mod;
                            ans = ans * x % mod;
                        }
                    }
                    else if(pos.size() > 1)
                    {
                        ans = ans * pos.back() % mod;
                        pos.pop_back();
                        ans = ans * pos.back() % mod;
                        pos.pop_back();
                    }
                    else
                    {
                        x = neg.back();
                        neg.pop_back();
                        x = x * neg.back();
                        neg.pop_back();
                        x %= mod;
                        ans = ans * x % mod;
                    }
                }
            }
        }
        cout << ans << "\n";
    }
    return 0;
}


Measured memory_bytes: 7488