#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int,int> pii;
typedef long long ll;
const long long MOD=1000000007;
#define rep(i,n) for(long long i=0;i<(n);i++)
#define rep2(i,m,n) for(long long i=m;i<(n);i++)
#define ALL(v) v.begin(), v.end()
#define pb push_back




int main(){

    ll n,k;
    cin>>n>>k;

    ll plus=0,minus=0,zero=0;


    vector<ll> data(n);
    vector<ll> plusdata;
    vector<ll> minusdata;
    

    rep(i,n){
        ll tmp;
        cin>>tmp;
        data.at(i)=tmp;
        if (tmp>0){
            plus++;
            plusdata.pb(tmp);
        }
        else if (tmp==0){
            zero++;
        }
        else {
            minus++;
            minusdata.pb(tmp);
        }
    }

    ll answer=1;

   

    if (k>plus+minus){
        answer=0;
    }

    else if (plus==0 and k%2==1 and zero>=1){
        answer=0;
    }

    else if (plus==0 and k%2==1 and zero==0){
        sort(ALL(minusdata));
        reverse(ALL(minusdata));
        rep(i,k){
            ll tmp=minusdata.at(i);
            answer*=tmp%MOD;
            answer%=MOD;
        }
          answer=MOD+answer;
    }

    else if (plus==0){
        sort(ALL(minusdata));
        rep(i,k){
            ll tmp=minusdata.at(i);
            answer*=tmp%MOD;
            answer%=MOD;
            answer=abs(answer);
            
        }
    }

    else if (k==plus+minus and minus%2==1 and zero>=1){
        answer=0;
    }
  
  	else if (k==plus+minus and minus%2==1){
      rep(i,k){
        answer*=data.at(i)%MOD;
        answer%=MOD;
      }
      answer=MOD+answer;
    }
  
      
      






    else {

        vector<pair<ll,string>> newdata;
        rep(i,plus){
            auto tmp=make_pair(plusdata.at(i),"p");
            newdata.pb(tmp);
        }
        rep(i,minus){
            auto tmp=make_pair(abs(minusdata.at(i)),"m");
            newdata.pb(tmp);
        }

        sort(ALL(newdata));
        reverse(ALL(newdata));

        ll pcnt=0,mcnt=0;

        rep(i,k){
            if (newdata.at(i).second=="p"){
                pcnt++;
            }
            else {
                mcnt++;
            }
            
        }

        sort(ALL(plusdata));
        reverse(ALL(plusdata));

        sort(ALL(minusdata));

        if (mcnt%2==0){
            rep(x,pcnt){
                ll tmp=plusdata.at(x);
                answer*=tmp%MOD;
                answer%=MOD;
            }
            rep(x,mcnt){
                ll tmp=minusdata.at(x);
                answer*=tmp%MOD;
                answer%=MOD;
            }
            answer=abs(answer);
        }


        else if (pcnt==0){
             rep(x,mcnt-1){
                ll tmp=minusdata.at(x);
                answer*=tmp%MOD;
                answer%=MOD;
            }
            answer*=plusdata.at(0)%MOD;
            answer%=MOD;
            answer=abs(answer);

        }

        else if (pcnt!=0 and pcnt==plus){
            rep(x,pcnt-1){
                ll tmp=plusdata.at(x);
                answer*=tmp%MOD;
                answer%=MOD;
            }
            rep(x,mcnt-1){
                ll tmp=minusdata.at(x);
                answer*=tmp%MOD;
                answer%=MOD;
            }
            answer*=minusdata.at(mcnt-1)%MOD;
            answer%=MOD;
            answer*=minusdata.at(mcnt)%MOD;
            answer%=MOD;
            answer=abs(answer);


        }

        else if (pcnt!=0 and pcnt!=plus and mcnt==minus){
             rep(x,pcnt-1){
                ll tmp=plusdata.at(x);
                answer*=tmp%MOD;
                answer%=MOD;
            }
            rep(x,mcnt-1){
                ll tmp=minusdata.at(x);
                answer*=tmp%MOD;
                answer%=MOD;
            }
            answer*=plusdata.at(pcnt-1)%MOD;
            answer%=MOD;
            answer*=plusdata.at(pcnt)%MOD;
          	answer%=MOD;
            answer=abs(answer);


        }

        else {
            rep(x,pcnt-1){
                ll tmp=plusdata.at(x);
                answer*=tmp%MOD;
                answer%=MOD;
            }
            rep(x,mcnt-1){
                ll tmp=minusdata.at(x);
                answer*=tmp%MOD;
                answer%=MOD;
            }
            answer=abs(answer);

            ll tmp1=((plusdata.at(pcnt-1))*(plusdata.at(pcnt)));
            ll tmp2=((minusdata.at(mcnt-1))*(minusdata.at(mcnt)));

            ll bigger=max(tmp1,tmp2);

            answer*=bigger%MOD;
          	answer%=MOD;

        }


  }

  cout<<answer<<endl;






    }






            






Measured memory_bytes: 17980