#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<ll,ll>;

const ll MOD = 1e9 + 7;
template<ll MOD> struct ModInt {
    ll value;
    ModInt() : value(0) {}
    ModInt(const ll& v) : value(v % MOD) {
        if ( value < 0 ) value += MOD;
    }
    ModInt<MOD>& operator=(const ModInt& o) {
        value = o.value;
        return *this;
    }
    inline bool operator==(const ModInt& o) {
        return value == o.value;
    }
    inline bool operator!=(const ModInt& o) {
        return value != o.value;
    }
    ModInt<MOD>& operator+=(const ModInt& o) {
        value += o.value;
        if ( value >= MOD ) value -= MOD;
        return *this;
    }
    ModInt<MOD>& operator-=(const ModInt& o) {
        value += MOD - o.value;
        if (value >= MOD ) value -= MOD;
        return *this;
    }
    ModInt<MOD>& operator*=(const ModInt& o) {
        value *= o.value;
        value %= MOD;
        return *this;
    }
    ModInt<MOD>& operator/=(const ModInt& o) {
        value *= inverse(o.value);
        value %= MOD;
        return *this;
    }
    ModInt<MOD> operator-() {
        return ModInt<MOD>(-value);
    }
    ModInt<MOD> operator+(const ModInt& o) {
        ModInt<MOD> r(*this);
        r += o;
        return r;
    }
    ModInt<MOD> operator-(const ModInt& o) {
        ModInt<MOD> r(*this);
        r -= o;
        return r;
    }
    ModInt<MOD> operator*(const ModInt& o) {
        ModInt<MOD> r(*this);
        r *= o;
        return r;
    }
    ModInt<MOD> operator/(const ModInt& o) {
        ModInt<MOD> r(*this);
        r /= o;
        return r;
    }
    ModInt<MOD> pow(ll n) {
        ModInt<MOD> t(*this), r = 1;
        while ( n > 0 ) {
            if ( n & 1 ) r *= t;
            t *= t;
            n >>= 1;
        }
        return r;
    }
private:
    ll inverse(ll a) {
        ModInt<MOD> t(a);
        return t.pow(MOD - 2).value;
    }
};
using Int = ModInt<MOD>;

ll solve(ll N, ll K, vector<ll>& AA) {
    vector<ll> A(AA);
    vector<pii> a(N);
    bool all_0_neg = true;
    for ( int i = 0; i < N; i++ ) {
        ll sgn = 0;
        if ( A[i] > 0 ) sgn = 1;
        else if ( A[i] < 0 ) sgn = -1;
        a[i] = pii(abs(A[i]), sgn);
        if ( A[i] > 0 ) all_0_neg = false;
    }
    auto Mul = [&](ll& x, ll y) { 
        x = x % MOD * (y % MOD) % MOD; 
        if ( x < 0 ) x += MOD;
    };
    if ( K == N ) {
        ll ans = 1;
        ll c_neg = 0;
        for ( int i = 0; i < K; i++ ) {
            Mul(ans, a[i].first);
            if ( a[i].second < 0 ) c_neg++;
        }
        if ( c_neg % 2 == 1 ) Mul(ans, MOD - 1);
        return ans;
    } else if ( K == 1 ) {
        sort(A.rbegin(), A.rend());
        ll ans = 1;
        Mul(ans, A[0]);
        return ans;
    } else if ( all_0_neg && K%2==1 ) {
        sort(a.begin(), a.end());
        ll ans = 1;
        for ( int i = 0; i < K; i++ ) {
            Mul(ans, a[i].first);
        }
        Mul(ans, MOD - 1);
        return ans;
    } else {
        sort(a.rbegin(), a.rend());
        int n_neg = 0;
        for ( int i = 0; i < K; i++ ) {
            if ( a[i].second < 0 ) n_neg++;
        }
        if ( a[K-1].first == 0 ) {
            return 0;
        } else if ( n_neg % 2 == 0 ) {
            ll ans = 1;
            for ( int i = 0; i < K; i++ ) {
                Mul(ans, a[i].first);
            }
            return ans;
        } else if ( n_neg == K ) {
            ll ans = 1;
            for ( int i = 0; i < K-1; i++ ) {
                Mul(ans, a[i].first);
            }
            for ( int i = K-1; i < N; i++ ) {
                if ( a[i].second >= 0 ) {
                    Mul(ans, a[i].first);
                    break;
                }
            }
            return ans;            
        } else {
            ll ans = 1;
            int in = -1, ip = -1;
            {
                int m_neg = n_neg-1, m_pos0 = K - m_neg - 2;
                int c_neg = 0, c_pos0 = 0;
                for ( int i = 0; i < N; i++ ) {
                    if ( a[i].second < 0 ) {
                        if ( c_neg < m_neg ) {
                            c_neg++;
                            Mul(ans, a[i].first);
                            in = i;
                        }
                    } else {
                        if ( c_pos0 < m_pos0 ) {
                            c_pos0++;
                            Mul(ans, a[i].first);
                            ip = i;
                        }
                    }
                }
            }
            ll x = 0;
            {
                int cp = 0, cn = 0;
                ll xp = 1, xn = 1;
                for ( int i = ip+1; i < N; i++ ) {
                    if ( a[i].second >= 0 ) {
                        xp *= a[i].first;
                        cp++;
                        if ( cp == 2 ) {
                            x = max(x, xp);
                            break;
                        }
                    }
                }
                for ( int i = in+1; i < N; i++ ) {
                    if ( a[i].second < 0 ) {
                        xn *= a[i].first;
                        cn++;
                        if ( cn == 2 ) {
                            x = max(x, xn);
                            break;
                        }
                    }
                }
            }
            Mul(ans, x);
            return ans;

            // ll ans = -1;
            // for ( int n = n_neg-1; n <= n_neg+1; n+=2 ) {
            //     int m_neg = n, m_pos0 = K - m_neg;
            //     if ( m_pos0 < 0 ) continue;
            //     int c_pos0 = 0, c_neg = 0;
            //     ll t = 1;
            //     for ( int i = 0; i < N; i++ ) {
            //         if ( a[i].second < 0 && c_neg >= m_neg ) continue;
            //         if ( a[i].second >= 0 && c_pos0 >= m_pos0 ) continue;
            //         if ( c_neg == m_neg && c_pos0 == m_pos0 ) break;
            //         Mul(t, a[i].first);
            //         if ( a[i].second < 0 ) c_neg++;
            //         if ( a[i].second >= 0 ) c_pos0++;
            //     }
            //     if ( c_neg == m_neg && c_pos0 == m_pos0 ) {
            //         ans = max(ans, t);
            //     }
            // }
            // return ans;
        }
    }
    return 0;
}


ll solve_2(ll N, ll K, vector<ll>& AA) {
    vector<ll> A(AA);
    vector<pii> a(N);
    bool all_0_neg = true;
    for ( int i = 0; i < N; i++ ) {
        ll sgn = 0;
        if ( A[i] > 0 ) sgn = 1;
        else if ( A[i] < 0 ) sgn = -1;
        a[i] = pii(abs(A[i]), sgn);
        if ( A[i] > 0 ) all_0_neg = false;
    }
    if ( K == N ) {
        Int ans = 1;
        ll c_neg = 0;
        for ( int i = 0; i < K; i++ ) {
            ans *= a[i].first;
            if ( a[i].second < 0 ) c_neg++;
        }
        if ( c_neg % 2 == 1 ) ans *= Int(-1);
        return ans.value;
    } else if ( K == 1 ) {
        sort(A.rbegin(), A.rend());
        Int ans = Int(A[0]);
        return ans.value;
    } else if ( all_0_neg && K%2==1 ) {
        sort(a.begin(), a.end());
        Int ans = 1;
        for ( int i = 0; i < K; i++ ) {
            ans *= a[i].first;
        }
        ans *= Int(-1);
        return ans.value;
    } else {
        sort(a.rbegin(), a.rend());
        int n_neg = 0;
        for ( int i = 0; i < K; i++ ) {
            if ( a[i].second < 0 ) n_neg++;
        }
        if ( a[K-1].first == 0 ) {
            return 0;
        } else if ( n_neg % 2 == 0 ) {
            Int ans = 1;
            for ( int i = 0; i < K; i++ ) {
                ans *= a[i].first;
            }
            return ans.value;
        } else if ( n_neg == K ) {
            Int ans = 1;
            for ( int i = 0; i < K-1; i++ ) {
                ans *= a[i].first;
            }
            for ( int i = K-1; i < N; i++ ) {
                if ( a[i].second >= 0 ) {
                    ans *= a[i].first;
                    break;
                }
            }
            return ans.value;
        } else {
            Int ans = 1;
            int in = -1, ip = -1;
            {
                int m_neg = n_neg-1, m_pos0 = K - m_neg - 2;
                int c_neg = 0, c_pos0 = 0;
                for ( int i = 0; i < N; i++ ) {
                    if ( a[i].second < 0 ) {
                        if ( c_neg < m_neg ) {
                            c_neg++;
                            ans *= a[i].first;
                            in = i;
                        }
                    } else {
                        if ( c_pos0 < m_pos0 ) {
                            c_pos0++;
                            ans *= a[i].first;
                            ip = i;
                        }
                    }
                }
            }
            ll x = 0;
            {
                int cp = 0, cn = 0;
                ll xp = 1, xn = 1;
                for ( int i = ip+1; i < N; i++ ) {
                    if ( a[i].second >= 0 ) {
                        xp *= a[i].first;
                        cp++;
                        if ( cp == 2 ) {
                            x = max(x, xp);
                            break;
                        }
                    }
                }
                for ( int i = in+1; i < N; i++ ) {
                    if ( a[i].second < 0 ) {
                        xn *= a[i].first;
                        cn++;
                        if ( cn == 2 ) {
                            x = max(x, xn);
                            break;
                        }
                    }
                }
            }
            ans *= Int(x);
            return ans.value;
        }
    }
    return 0;
}

ll solve_3(ll N, ll K, vector<ll>& AA) {
    vector<ll> A(AA);
    bool all_neg = true;
    for ( int i = 0; i < N; i++ ) {
        if ( A[i] >= 0 ) all_neg = false;
    }
    const ll MOD = 1e9 + 7;
    auto Add = [&](ll& x, ll y) { x = ( x % MOD + y % MOD ) % MOD; };
    auto Mul = [&](ll& x, ll y) {
        x = x % MOD * (y % MOD) % MOD; 
        if ( x < 0 ) x += MOD;
    };
    auto Pow = [&](ll x, ll n) -> ll {
        ll t = x % MOD, r = 1;
        if ( t < 0 ) t += MOD;
        while ( n > 0 ) {
            if ( n & 1 ) Mul(r, t);
            Mul(t, t);
            n >>= 1;
        }
        return r;
    };
    auto Inv = [&](ll a) -> ll {
        return Pow(a, MOD - 2);
    };

    if ( N == K ) {
        ll ans = 1;
        for ( int i = 0; i < K; i++ ) {
            Mul(ans, A[i]);
        }
        return ans;
    } else if ( all_neg && K%2==1 ) {
        sort(A.rbegin(), A.rend());
        ll ans = 1;
        for ( int i = 0; i < K; i++ ) {
            Mul(ans, A[i]);
        }
        return ans;
    } else {
        vector<pii> a(N);
        for ( int i = 0; i < N; i++ ) {
            ll sg = 0;
            if ( A[i] > 0 ) sg = 1;
            else if ( A[i] < 0 ) sg = -1;
            a[i] = pii(abs(A[i]),sg);
        }
        sort(a.rbegin(), a.rend());
        if ( a[K-1].first == 0 ) return 0;
        int n_neg = 0;
        ll ans = 1;
        ll lp = -1, ln = -1, rp = -1, rn = -1;
        for ( int i = 0; i < K; i++ ) {
            if ( a[i].second < 0 ) n_neg++;
            Mul(ans, a[i].first);
            if ( a[i].second >= 0 ) lp = a[i].first;
            if ( a[i].second < 0 ) ln = a[i].first;
        }
        for ( int i = K; i < N; i++ ) {
            if ( rp < 0 && a[i].second >= 0 ) rp = a[i].first;
            if ( rn < 0 && a[i].second < 0 ) rn = a[i].first;
        }
        if ( n_neg % 2 == 0 ) {
            return ans;
        } else {
            long double x = -1e100;
            ll t = 1;
            if ( ln >= 0 && rp >= 0 ) {
                long double y = rp/(long double)ln;
                if ( y > x ) {
                    x = y;
                    t = 1;
                    Mul(t, rp);
                    Mul(t, Inv(ln));
                }
            } 
            if ( lp >= 0 && rn >= 0 ) {
                long double y = rn/(long double)lp;
                if ( y > x ) {
                    x = y;
                    t = 1;
                    Mul(t, rn);
                    Mul(t, Inv(lp));
                }
            }
            Mul(ans, t);
            return ans;
        }
    }
    return 0;
}

ll solve_small_2(ll N, ll K, vector<ll>& AA) {
    ll ans = -1LL<<60;
    long double mx = 1e300*(-1);
    function<void(int,int,ll,long double,ll)> dfs = [&](int d, int b, ll x, long double y, ll s) {
        if ( d == K ) {
            if ( s == 0 ) {
                if ( mx < 0 ) {
                    mx = 0;
                    ans = 0;
                }
            } else {
                if ( mx < (1+y)*s ) {
                    mx = (1+y)*s;
                    ans = x;
                }
            }
            return;
        }
        for ( int i = b; i < N; i++ ) {
            long double lx = log2l(abs(AA[i]));
            ll sg = 0;
            if ( AA[i] > 0 ) sg = 1;
            if ( AA[i] < 0 ) sg = -1;
            dfs(d+1, i+1, x * AA[i] % MOD, y + lx, s * sg);
        }
    };
    dfs(0,0,1,0,1);
    ans %= MOD;
    if ( ans < 0 ) ans += MOD;
    return ans;
}

ll solve_small(ll N, ll K, vector<ll>& AA) {
    ll ans = -1LL<<60;
    function<void(int,int,ll)> dfs = [&](int d, int b, ll x) {
        if ( d == K ) {
            ans = max(ans, x);
            return;
        }
        for ( int i = b; i < N; i++ ) {
            dfs(d+1, i+1, x * AA[i]);
        }
    };
    dfs(0,0,1);
    ans %= MOD;
    if ( ans < 0 ) ans += MOD;
    return ans;
}

struct Data {
    ll N;
    ll K;
    vector<ll> A;
};

void test() {
    mt19937_64 mt64(0);
    //uniform_int_distribution<ll> rnd(-10, 10);
    uniform_int_distribution<ll> rnd(-100000000, 100000000);
    ll x = rnd(mt64);

    vector<Data> ts;
    ts.push_back(Data{4,3,{-2,3,9,-3}});
    ts.push_back(Data{4,2,{1,3,-1,-2}});
    ts.push_back(Data{4,1,{-1,-2,-3,-4}});
    ts.push_back(Data{4,4,{3,-3,1,0}});
    ts.push_back(Data{2,1,{-1,1000000000}});
    ts.push_back(Data{4,3,{1,-2,-2,-2}});
    ts.push_back(Data{4,2,{1,2,-3,-4}});
    ts.push_back(Data{4,3,{-1,-2,-3,-4}});
    for ( int i = 0; i < 100; i++ ) {
        //for ( int n = 8; n <= 9; n++ ) {
        for ( int n = 4; n <= 5; n++ ) {
            vector<ll> a(n);
            for ( int j = 0; j < n; j++ ) {
                ll y = rnd(mt64);
                if ( i % 2 == 0 && y == 0 ) y = rnd(mt64);
                if ( i % 5 == 0 ) y = -abs(y);
                a[j] = y;
            }
            for ( int k = 1; k <= n; k++ ) {
                ts.push_back(Data{n,k,a});
            }
        }
    }

    for ( auto t : ts ) {
        ll ans1 = solve(t.N, t.K, t.A);
        ll ans2 = solve_2(t.N, t.K, t.A);
        ll ans3 = solve_3(t.N, t.K, t.A);
        ll ans4 = solve_small_2(t.N, t.K, t.A);
        if ( ans1 != ans2 || ans1 != ans3 || ans1 != ans4 ) {
            cout << ans1 << " " << ans2 << " " << ans3 << " " << ans4 << "\n";
        }
        // ll ans3 = solve_small(t.N, t.K, t.A);
        // if ( ans1 != ans2 || ans1 != ans3 ) {
        //     cout << ans1 << " " << ans2 << " " << ans3 << "\n";
        // }
    }
    cout << "end\n";
}

int main() {
    // test();

    ll N, K;
    cin >> N >> K;
    vector<ll> A(N);
    for ( int i = 0; i < N; i++ ) {
        cin >> A[i];
    }
    auto ans = solve_3(N, K, A);
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 9648