#pragma GCC optimize("O3")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("unroll-loops")

#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; 

#define int long long
#define pb push_back
#define pf push_front
#define eb emplace_back
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define f first
#define s second
#define sz(x) (int)x.size()
#define endl "\n"
#define forn(i,n) for(int i=0;i<n;++i)
#define fore(i,l,r) for(int i=int(l);i<=int(r);++i)
#define rep(i,begin,end) for(__typeof(end) i=(begin);i!=(end);i++)
#define fill(a,value) memset(a,value,sizeof(a));
#define gcd(a,b) __gcd((a),(b))
#define watch1(x) cout<<(x)<<endl
#define watch2(x,y) cout<<(x)<<" "<<(y)<<endl
#define watch3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef long double ld; 
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;

const int INF = 9e18;
const int mod = 1e9 + 7;
const int N = 2e5 + 5;

int i,n,k,a[N];

int pwr(int x,int y)
{
    int res=1;
    x%=mod;
    while(y>0)
    {
        if(y&1)
            res=(res*x)%mod;
        y>>=1;
        x=(x*x)%mod;
    }
    return res;
}
 
int modinv(int n)
{
    return pwr(n,mod-2);
}

void solve()
{
    cin>>n>>k;
    vpii v;
    int ok=0;
    for(i=1;i<=n;++i)
    {
        cin>>a[i];
        if(a[i]>=0)
        {
            v.pb({abs(a[i]),1});
            ok=1;
        }
        else
            v.pb({abs(a[i]),-1});
    }
    if(k==n)
    {
        int ans=1;
        for(i=1;i<=n;++i)
        {
            ans*=a[i];
            ans%=mod;
            ans+=mod;
            ans%=mod;
        }
        cout<<ans;
        return;
    }
    sort(all(v));
    if(!ok)
    {
        if(k&1)
        {
            int ans=1;
            for(i=0;i<k;++i)
            {
                ans*=-v[i].f;
                ans%=mod;
                ans+=mod;
            	ans%=mod;
            }
            cout<<ans;
        }
        else
        {
            reverse(all(v));
            int ans=1;
            for(i=0;i<k;++i)
            {
                ans*=v[i].f;
                ans%=mod;
            }
            cout<<ans;
        }
    }
    else
    {
        int ans=1,neg=0,pos=0;
        reverse(all(v));
        for(i=0;i<k;++i)
        {
        	ans*=v[i].f;
        	ans%=mod;
        	if(v[i].s==-1)
        		neg++;
        	else
        		pos++;
        }
        if(neg&1)
        {
        	int mn1=INF,mx1=-INF,mn2=INF,mx2=-INF;
        	if(pos>0)
        	{
        		for(i=0;i<k;++i)
        		{
        			if(v[i].s==1)
        				mn1=min(mn1,v[i].f);
        		}
        		for(i=k;i<n;++i)
        		{
        			if(v[i].s==-1)
        				mx1=max(mx1,v[i].f);
        		}
        	}
        	if(neg>0)
        	{
        		for(i=0;i<k;++i)
        		{
        			if(v[i].s==-1)
        				mn2=min(mn2,v[i].f);
        		}
        		for(i=k;i<n;++i)
        		{
        			if(v[i].s==1)
        				mx2=max(mx2,v[i].f);
        		}
        	}
        	if(mn2==INF || mx2==-INF)
        	{
        		ans*=modinv(mn1);
				ans%=mod;
				ans*=mx1;
				ans%=mod;
        	}
        	else if(mn1==INF || mx1==-INF)
        	{
        		ans*=modinv(mn2);
        		ans%=mod;
        		ans*=mx2;
        		ans%=mod;
        	}
        	else
        	{
        		if(mx1*mn2>=mx2*mn1)
    			{
    				ans*=modinv(mn1);
    				ans%=mod;
    				ans*=mx1;
    				ans%=mod;
    			}
    			else
    			{
    				ans*=modinv(mn2);
    				ans%=mod;
    				ans*=mx2;
    				ans%=mod;
    			}
        	}
        	cout<<ans;
        }
        else
        {
        	cout<<ans;
        }
    }
}

signed main()
{
    fastio;
    int t;
    //cin>>t;
    t=1;
    while(t--)
    {
        solve();
        cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 8448