// Problem : E - Multiplication 4
// Contest : AtCoder - AtCoder Beginner Contest 173
// URL : https://atcoder.jp/contests/abc173/tasks/abc173_e
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define eb emplace_back
#define pb push_back
#define size(s) (int)s.size()
#define int long long
#define vi vector<int>
#define vs vector<string>
#define vv vector<vector<int>>
#define pii pair<int,int>
#define m_p(x,y) make_pair(x,y)
#define vp vector<pair<int,int>>
#define setbits(x) __builtin_popcountll(x)
#define f first
#define se second
#define inc(v,n,x) v.assign(n,x)
#define incd(v,n) v.resize(n)
#define iniz(n) memset(n,0,sizeof(n))
#define inin(n) memset(n,-1,sizeof(n))
#define inimi(n) memset(n,0xc0,sizeof(n))
#define inima(n) memset(n,0x3f,sizeof(n))
#define all(v) (v).begin(),(v).end()

using namespace std;

template<typename T1,typename T2>istream &operator>>(istream &is, vector<pair<T1,T2>> &v) { for (pair<T1,T2> &t : v) is >> t.f>>t.se; return is; }
template<typename T>istream &operator>>(istream &is, vector<T> &v) { for (T &t : v) is >> t; return is; }
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &t : v) {os << t <<" ";} os << '\n'; return os; }

const int N=200001;
double pi=acos(-1.0);
int md=1e9+7;
const int INF=1e15;
int dx1[]={0,0,-1,1};
int dy1[]={1,-1,0,0};

template<class T>
T abst(T a)
{return a<0?-a:a;}

template<class T>
T max2(T a,T b){return a>b?a:b;}
template<class T>
T min2(T a,T b){return a<b?a:b;}
bool check(int k,vi &v)
{
	int n=size(v);
	
	double d1=0,d2=0;int no4=-1;int no2=-1;
	//case 1: replacing neg with pos
	int no=-INF,ind1,ind2;
	for(int i=k;i<n;i++)
	{
		if(v[i]>0)
		{
			ind1=i;
			no=v[i];
			break;
		}
	}
	if(no!=-INF)
	{
		
		for(int i=0;i<k;i++)
		if(v[i]<0)
		no2=v[i],ind2=i;
		no2=abst(no2);
		d1=(no*1.0)/(no2*1.0);
	}
	
	//case 2: replacing pos with neg
	int no3=INF,ind3,ind4;
	for(int i=k;i<n;i++)
	{
		if(v[i]<0)
		{
			no3=v[i];
			ind3=i;
			break;
		}
	}
	if(no3!=INF)
	{
		no3=abst(no3);
		
		for(int i=0;i<k;i++)
		{
			if(v[i]>0)
			no4=v[i],ind4=i;
		}
		if(no4!=-1)
		{
			d2=(no3*1.0)/(no4*1.0);
		}
	}
	if(d1==0 and d2==0)return false;
	if(d1!=0 and d2!=0)
	{
		no=abst(no);
		no2=abst(no2);
		no3=abst(no3);
		no4=abst(no4);
		if(no*no4>no2*no3)
		{
			swap(v[ind1],v[ind2]);
		}
		else
		swap(v[ind3],v[ind4]);
	}
	else if(d1!=0)
	{
		swap(v[ind1],v[ind2]);
	}
	else
	{
		swap(v[ind3],v[ind4]);
	}
	return true;
}
void solve()
{
	int n,k;cin>>n>>k;
	vi v(n);
	cin>>v;
	sort(all(v),[&](int x,int y){
		return abst(x)>abst(y);
	});
	int pro=1;
	int cnt=0,cnt2=0,cnt3=0;
	for(int i=0;i<k;i++)
	{
		if(v[i]>0)
		cnt++;
		else if(v[i]==0)
		cnt2++;
		else
		cnt3++;
	}
	if(cnt2)
	{
		cout<<0;
		return;
	}
	else
	{
		if(cnt3&1)
		{
			//replace one neg with pos or pos with neg(greedy)
			
			if(check(k,v))
			{
				//cout<<v;
				int pro=1;
				for(int i=0;i<k;i++)
				pro=(pro*abst(v[i]))%md;
				cout<<pro;
			}
			else
			{
					sort(all(v),[&](int x,int y){
						return abst(x)<abst(y);
					});
					int pro=1;
					for(int i=0;i<k;i++)
					pro=(pro*v[i])%md;
					cout<<(pro+md)%md;
			}
				
			//if no way to avoid negative - look for zero else sort and get.
		}
		else
		{
			for(int i=0;i<k;i++)
			pro=(pro*abst(v[i]))%md;
			cout<<pro;
		}
	}
}

int32_t main(){
ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
int t=1;
//cin>>t;
for(int i=1;i<=t;i++)
{
    solve();
}
return 0;
}


Measured memory_bytes: 4792