#include <bits/stdc++.h>
using namespace std;

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a/gcd(a, b) * b;
}

// pairsをfirstを優先キーとして降順ソート
bool compare_by_a(pair<ll, ll> a, pair<ll, ll> b) {
    if(a.first != b.first){
        return a.first > b.first;
    }else{
        return a.second > b.second;
    }
}
int main()
{
    cout << fixed << setprecision(15);
    ll N, K;
    cin >> N >> K;

    vector<ll> A(N);
    vector<P> B(N);

    REP(i, N){
        cin >> A[i];

        if(A[i] > 0){
            B[i].first = A[i];
            B[i].second = 1;
        }
        if(A[i] < 0){
            B[i].first = (-1) * A[i];
            B[i].second = -1;
        }
        if(A[i] == 0){
            B[i].first = 0;
            B[i].second = 0;
        }
    }

    if(N == K){
        ll ans = 1;
        ll check = 1;
        REP(i, N){
            check = check*B[i].second;
            ans = ans *B[i].first;
            ans = (ans+MOD) % MOD;
        }
        if(check == -1) ans *= -1;
        ans = (ans+MOD) % MOD;
        cout << ans << endl;
        return 0;
    }
    sort(B.begin(), B.end(), compare_by_a);

    // REP(i, N){
    //     cout << B[i].first << " " << B[i].second << endl;
    // }

    ll check = 1;
    REP(i, K){
        check *= B[i].second;
    }
    if(check == 1){
        ll ans = 1;
        REP(i, K){
            ans = ans * B[i].first;
            ans = (ans+MOD) % MOD;
        }
        cout << ans << endl;
        // cout << "A" << endl;
        return 0;
    }

    if(check == 0){
        cout << 0 << endl;
        // cout << "B" << endl;
        return 0;
    }

    ll minusid = -1;
    for(ll i=K-1; i>=0; i--){
        if(B[i].second == -1){
            minusid = i;
            break;
        }
    }
    ll plusid = -1;
    for(ll i=K-1; i>=0; i--){
        if(B[i].second == 1){
            plusid = i;
            break;
        }
    }

    ll minusnext = -1;
    for(ll i=K; i<N; i++){
        if(B[i].second == -1){
            minusnext = i;
            break;
        }
    }
    ll plusnext = -1;
    for(ll i=K; i<N; i++){
        if(B[i].second == 1){
            plusnext = i;
            break;
        }
    }

    if(plusid == -1){
        // 結局すべてがマイナスか０で構成されている
        if(plusnext == -1){
            ll ans = 1;
            for(ll i=N-1; i>=N-K; i--){
                ans = ans * B[i].first;
                ans = (ans+MOD) % MOD;
            }
            ans *=-1;
            ans = (ans+MOD) % MOD;
            cout << ans << endl;
            // cout << "C" << endl;
            return 0;
        }

        ll ans = 1;
        REP(i, K){
            if(i == minusid) continue;
            ans = ans * B[i].first;
            ans = (ans+MOD) % MOD;
        }
        ans = ans * B[plusnext].first;
        ans = (ans+MOD) % MOD;
        cout << ans << endl;
        // cout << "D" << endl;
        return 0;
    }

    ll temp = 1;
    REP(i, K){
        if(i == minusid) continue;
        temp = temp * B[i].first;
        temp = (temp+MOD) % MOD;
    }
    // cout << "plusnext:" << plusnext << endl;
    temp = temp * B[plusnext].first;
    temp = (temp+MOD) % MOD;
    // if(plusnext == -1) temp = 0;
    
    ll temp2 = 1;
    REP(i, K){
        if(i == plusid) continue;
        temp2 = temp2 * B[i].first;
        temp2 = (temp2+MOD) % MOD;
    }
    temp2 = temp2 * B[minusnext].first;
    temp2 = (temp2+MOD) % MOD;
    // if(minusnext == -1) temp2 = 0;

    if(plusnext == -1){
        cout << temp2 << endl;
        // cout << "E" << endl;
        return 0;
    }
    if(minusnext == -1){
        cout << temp << endl;
        // cout << "F" << endl;
        return 0;
    }

    if(B[minusid].first * B[minusnext].first > B[plusid].first * B[plusnext].first){
        cout << temp2 << endl;
        // cout << "G" << endl;
        return 0;
    }
    else{
        cout << temp << endl;
        // cout << "H" << endl;
    }
    return 0;
}

Measured memory_bytes: 7996