#include<iostream>

template<int64_t p>
struct F_p{
  using value_type = int64_t;
  static constexpr inline value_type get_mod(){return p;}

  value_type value;

  constexpr F_p():value(value_type{}){}
  template<class T>constexpr F_p(T v):value(static_cast<value_type>(v<0?v%p+p:v%p)){}
// operator +, -, *, /, ^ 
  constexpr F_p operator + (const F_p& other)const{
    return F_p(*this) += other;
  }
  constexpr F_p operator - (const F_p& other)const{
    return F_p(*this) -= other;
  }
  constexpr F_p operator * (const F_p& other)const{
    return F_p(*this) *= other;
  }
  constexpr F_p operator / (const F_p& other)const{
    return F_p(*this) /= other;
  }
  template<class T> constexpr F_p operator ^ (const T other)const{
    return F_p(*this) ^= other;
  }
  constexpr F_p &operator += (const F_p& other){
    value+=other.value;
    if(value>p)value-=p;
    return *this;
  }
  constexpr F_p &operator -= (const F_p& other){
    value-=other.value;
    if(value<0)value+=p;
    return *this;
  }
  constexpr F_p &operator *= (const F_p& other){
    value*=other.value;
    if(value>p)value%=p;
    return *this;
  }
  constexpr F_p &operator /= (const F_p& other){
    value*=other.inverse();
    if(value>p)value%=p;
    return *this;
  }
  template<class T>
  constexpr F_p &operator ^= (const T n){
    value = mpow(n);
    return *this;
  }
// ext_gcd,inverse,mpow 
  constexpr value_type ext_gcd(value_type a,value_type b,value_type& x,value_type& y)const{
    if(b==0){x=1,y=0;return a;}
    value_type d=ext_gcd(b,a%b,y,x);
    y-=a/b*x;return d;
  }
  constexpr value_type inverse()const{
    value_type x,y;
    ext_gcd(value,p,x,y);
    return x<0?x%p+p:x%p;
  }
  template<class T>
  static constexpr value_type inverse(T val){
    value_type x,y;
    ext_gcd(val,p,x,y);
    return x<0?x%p+p:x%p;
  }
  template<class T>
  constexpr F_p mpow(T n)const{
    F_p res(1),vn(*this);
    while(p){
      if(n&1)res*=vn;
      vn*=vn;
      n>>=1;
    }
    return res;
  }
  template<class T>
  static constexpr T mpow(T a,T b){
    F_p x(a);
    x ^= b;
    return static_cast<T>(x.value);
  }
// operator iostream 
  constexpr friend std::istream &operator >> (std::istream& is,F_p& fp){
    is>>fp.value;
    return is;
  }constexpr friend std::ostream &operator << (std::ostream& os,const F_p& fp){
    os<<fp.value;
    return os;
  }
};

using modint998244353 = F_p<998244353>;
using modint1000000007 = F_p<(int)1e9+7>;


#include<bits/stdc++.h>

int solve_multiplication4(){
  using namespace std;
  using mint = modint1000000007;

  int n,k;
  cin>>n>>k;
  vector<mint::value_type> a(n);
  for(auto& ai:a)cin>>ai;

  if(n==k){mint prod=1;for(auto ai:a)prod*=ai;cout<<prod<<endl;return 0;}
  if((k&1)and(all_of(begin(a),end(a),[](auto ai){return ai<=0;}))){sort(rbegin(a),rend(a));cout<<(accumulate(begin(a),begin(a)+k,mint(1),[](mint acc,auto ai)->mint{return mint(acc*ai);}))<<endl;return 0;}

  sort(begin(a),end(a),[](auto ai,auto aj){return abs(ai)>abs(aj);});
  mint prod = 1;
  int minus_cnt = 0;
  for(int i=0;i<k;++i){
    prod *= mint(a[i]);
    if(a[i]<0)minus_cnt++;
  }
  if(~minus_cnt&1){cout<<prod<<endl;return 0;}

  int ia,ib,ic,id;ia=ib=ic=id=-1;
  for(int i=0;i<n;++i){
    if(i<k){
      if(a[i]>0)ia=i;
      if(a[i]<0)ib=i;
    }else{
      if(a[i]>0 and ic==-1)ic=i;
      if(a[i]<0 and id==-1)id=i;
    }
  }

  {
    if(ia>=0 and ib>=0 and ic>=0 and id>=0){
      __int128_t A=a[ia],B=a[ib],C=a[ic],D=a[id];
      // (prod/a*d < prod/b*c) == (d/a < c/b) == (bd < ac)
      if(B*D<A*C)prod = prod/mint(a[ib])*mint(a[ic]);
      else prod = prod/mint(a[ia])*mint(a[id]);
    }
    else if(ia>=0 and id>=0){
      prod = prod/mint(a[ia])*mint(a[id]);
    }
    else if(ib>=0 and ic>=0){
      prod = prod/mint(a[ib])*mint(a[ic]);
    }
    else{
      sort(begin(a),end(a),[](auto ai,auto aj){return abs(ai)<abs(aj);});
      prod = accumulate(begin(a),begin(a)+k,mint(1),[](mint acc,auto ai){return mint(acc*ai);});
    }
  }
  assert(0<=prod.value and prod.value<mint::get_mod());
  cout<<(prod)<<endl;

  return 0;
}

int main(){
  return solve_multiplication4();
}

Measured memory_bytes: 4752