//For higher stack size use g++ -O2 -std=c++11 -Wall -Wl,--stack=268435456 a.cpp -o a.exe in cmd
    #include <bits/stdc++.h>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <cstring>
    #include <chrono>
    #include <complex>
    #define ll long long
    #define int ll
    #define ld long double
    #define vi vector<int>
    #define vll vector<ll>
    #define vvi vector < vi >
    #define pii pair<int,int>
    #define pll pair<long long, long long>
    #define mod 1000000007
    #define inf 1000000000000000001;
    #define all(c) c.begin(),c.end()
    #define mp(x,y) make_pair(x,y)
    #define mem(a,val) memset(a,val,sizeof(a))
    #define eb emplace_back
    #define pb push_back
    #define f first
    #define s second
    
    using namespace std;

    ll power(ll a, ll b)    //a is base, b is exponent
    {
        if(b==0)
            return 1;
        if(b==1)
            return a;
        if(b%2 == 1)
            return (power(a,b-1)*a)%mod;
        ll q = power(a,b/2);
        return (q*q)%mod;
    }

    signed main()
    {
        std::ios::sync_with_stdio(false);
        int T;
        T=1;
        // cin.ignore(); must be there when using getline(cin, s)
        while(T--)
        {
            int n,i,j,k,x,z;
            cin>>n>>k;
            ll ar[n+1];
            vector<ll> v,v2,v3;
            int flag=1;
            for(i=1;i<=n;++i)
            {
                cin>>ar[i];
            }
            if(k==n)
            {
                ll ans=1;
                for(i=1;i<=n;++i)
                {
                    ans=(ans*ar[i])%mod;
                }
                if(ans<0)
                    ans=ans+mod;
                cout<<ans<<endl;
                return 0;
            }
            sort(ar+1,ar+n+1,greater<int>());
            for(i=1;i<=n;++i)
            {
                if(ar[i]<0)
                {
                    v3.pb(ar[i]);
                }
                else if(ar[i]==0)
                    v2.pb(ar[i]);
                else
                    v.pb(ar[i]);
            }
            ll ans=1;
            if(v.size()==0)
            {
                if(k%2==1)
                {
                    if(v2.size()>0)
                    {
                        cout<<0<<endl;
                        return 0;
                    }
                }
            }
            if(v.size()+v3.size()<k)
            {
                cout<<0<<endl;
                return 0;
            }
            if(v.size()+v3.size()==k && v3.size()%2==1)
            {
                cout<<0<<endl;
                return 0;
            }
            if(v.size()==0)
            {
                ans=1;
                if(k%2==1)
                {
                    for(i=0;i<k;++i)
                    {
                        ans=(ans*v3[i])%mod;
                    }
                }
                else
                {
                    for(i=0;i<k;++i)
                    {
                        ans=(ans*v3[v3.size()-1-i])%mod;
                    }
                }
                if(ans<0)
                    ans=ans+mod;
                cout<<ans<<endl;
                return 0;
            }
            else if(v3.size()==0 || v3.size()==1)
            {
                if(v.size()<k)
                {
                    cout<<0<<endl;
                    return 0;
                }
                ans=1;
                for(i=0;i<k;++i)
                    ans=(ans*v[i])%mod;
                if(ans<0)
                    ans=ans+mod;
                cout<<ans<<endl;
                return 0;
            }
            else
            {
                while(v.size()>k)
                    v.pop_back();
                if((k-v.size())%2==1)
                    v.pop_back();
                ans=1;
                sort(v3.begin(),v3.end());
                for(i=0;i<v.size();++i)
                {
                    ans=(ans*v[i])%mod;
                }
                for(i=0;i+v.size()<k;++i)
                {
                    ans=(ans*v3[i])%mod;
                }
                while(i+1<v3.size() && v.size()>1)
                {
                    x=v.size()-1;
                    if(v3[i]*v3[i+1] >= v[x]*v[x-1])
                    {
                        ans=(ans*v3[i])%mod;
                        ans=(ans*v3[i+1])%mod;
                        ans=(ans*power(v[x],mod-2))%mod;
                        ans=(ans*power(v[x-1],mod-2))%mod;
                        v.pop_back();
                        v.pop_back();
                        i=i+2;
                    }
                    else
                        break;
                }
                if(ans<0)
                    ans=ans+mod;
                cout<<ans<<endl;
            }
        }
        return 0;
    }


Measured memory_bytes: 7120