#include <bits/stdc++.h> 
/*#ifndef M_PI
    #define M_PI 3.14159265358979323846
#endif
*/

using namespace std;
#define m 1000000007
#define rep(i,a,b) for(int i=a;i<b;++i)
#define repb(i,a,b) for(int i=a;i>=b;--i)
#define repv(arr)  for(auto it=x.begin();it!=x.end();++it)  
#define vi vector<int>
#define vb vector<bool>
#define vs vector<string>
#define vl vector<long long int>
#define ssortA(arr)   stable_sort(arr.begin(),arr.end())
#define search(arr,c)  binary_search(arr.begin(),arr.end(),c)
#define pb   push_back
#define ll long long
#define mp make_pair 
#define LCM(a,b) boost::math::lcm(a,b)
#define cl_bf cin.ignore(numeric_limits<streamsize>::max(), '\n1');
int cmp1(int a,int b){
    int x=abs(a);
    int y=abs(b);
    return x<y;
}
int cmp2(int a,int b){
    int x=abs(a);
    int y=abs(b);
    return x>y;
}
int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n1,k;
    cin>>n1>>k;
    vl arr(n1);
    //vector<pair<ll,int> > p,n1;
    int c1=0,c2=0;

    rep(i,0,n1){
        cin>>arr[i];
        
        if(arr[i]<0)
        {c2++;
        
        }
        else{
            c1++;
           
        }
    }
    ll pro=1;
   // cout<<"hi"<<endl;
    if(n1==k){
       
        rep(i,0,n1){
            pro=(m+(pro*arr[i])%m)%m;
        }
    }
    else{
         
        if(k%2!=0&&c2==n1){
stable_sort(arr.begin(),arr.end(),cmp1);
rep(i,0,k){
    pro=(m+(pro*arr[i])%m)%m;
}
        }
    else{
        stable_sort(arr.begin(),arr.end(),cmp2);
        vi flag(n1,0);
        int i1=-1,i2=-1,i3=-1,i4=-1;
        //cout<<"hi"<<endl;
        int o=1;
         rep(i,0,k){
            flag[i]=1;
            if(arr[i]<0)
            o*=-1;
            else
            {
                if(arr[i]==0)
                o=0;
                else
                o*=1;
            }
        }
        if(o<0){
        rep(i,k,n1){
            if(arr[i]>=0)
            {i1=i;
            break;
            }
        }
         rep(i,k,n1){
            if(arr[i]<0)
           { i3=i;
            break;}
        }
        repb(i,k-1,0){
            if(arr[i]>0)
            {i2=i;
            break;}
        }
         repb(i,k-1,0){
            if(arr[i]<0)
            {i4=i;
            break;
            }
        }
       
        //cout<<"hi"<<endl;
        double x=0,y=0;               
        int f1=0,f2=0;
        if(i1!=-1&&i4!=-1){
         //  x=((1.0)*arr[i1])/arr[i4];
           //  cout<<fixed<<setprecision(12)<<fabs(x)<<endl;

            f1=1;
        }
        if(i3!=-1&&i2!=-1){
           // y=((1.0)*arr[i3])/arr[i2];
          // cout<<fixed<<setprecision(12)<<fabs(y)<<endl;
            f2=1;
        }
        if(f1==1&&f2==1){
        if(abs(arr[i1])*abs(arr[i2])>=abs(arr[i4])*abs(arr[i3])){
            flag[i1]=1;
            flag[i4]=0;
        }
        else{
            flag[i3]=1;
            flag[i2]=0;
        }
        }
        else{
            if(f1==1){
                flag[i1]=1;
            flag[i4]=0;
            }
            else{
                if(f2==1)
                { flag[i3]=1;
            flag[i2]=0;}
            }
        }
        }
        rep(i,0,n1){
            if(flag[i]==1){
             //cout<<arr[i]<<" ";
          pro=(pro*arr[i])%m;
            }
        }
       // cout<<endl;

    }
    
    }
    cout<<pro<<endl;
}

        
   /* if(c1==0&&k%2!=0){
        ssortA(arr);
        rep(i,0,k){
            pro=(pro*arr[i])%m;
        }
        pro=(m+(pro*-1)%m)%m;
    }
    else{
        if(c2%2!=0&&k==n1){
            ssortA(arr);
        rep(i,0,k){
            pro=(pro*arr[i])%m;
        }
        pro=(m+(pro*-1)%m)%m;
        }
        else{

        
    
    stable_sort(p.begin(),p.end(),greater<pair<ll,int> >());
    stable_sort(n1.begin(),n1.end(),greater<pair<ll,int> >());
    vector<pair<ll,int> > f;
    for(int i=0;i<2*(p.size()/2);i+=2){
            ll y=p[i].first;
           ll  x=p[i+1].first;
            ll p=(x*y)%m;
           // cout<<p<<endl;
            f.pb(mp(p,1));
    }
    for(int i=0;i<2*(n1.size()/2);i+=2){
            ll y=n1[i].first;
           ll  x=n1[i+1].first;
            ll p=(x*y)%m;
            //cout<<p<<endl;
            f.pb(mp(p,2));
    }
    stable_sort(f.begin(),f.end(),greater<pair<ll,int> >());
    if(k%2==0){
        rep(i,0,k/2){
            pro=(pro*f[i].first)%m;
        }
    }
    
    else{
        int r=0;
        rep(i,0,k/2){
           if(f[i].second==1)
           ++r;
            pro=(pro*f[i].first)%m;
        }
        r*=2;
        pro=pro*(p[r].first);
    }
        }
    }
    cout<<pro<<endl;
}*/




Measured memory_bytes: 5580