#include <bits/stdc++.h>

#define ll long long
#define str string
#define pii pair<int, int>
#define pll pair<ll, ll>
#define fi first
#define se second

#define vc vector<char>
#define vvc vector<vc>
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vi>
#define vvll vector<vll>
#define vvvll vector<vvll>
#define vs vector<str>
#define vvs vector<vs>
#define vpii vector<pii>
#define vvpii vector<vpii>
#define vpll vector<pll>
#define vvpll vector<vpll>
#define vb vector<bool>
#define vvb vector<vb>
#define rep(i, a, b) for (int i = (a); i < int(b); i++)
#define repi(i, a, b) for (int i = (a); i <= int(b); i++)


using namespace std;
ll INF = LONG_LONG_MAX;
ll mod = 1000000000 + 7;

template <typename T, typename L>
void read(vector<T> & _data, L & _size, bool _shift) {
    _data.resize(_size + (ll)_shift);
    for (ll i = (ll)_shift; i < _size + (ll)_shift; i++)
        cin >> _data[i];
}

template <typename T, typename L>
void read(vector<vector<T>> & _data, L & _rows, L & _cols, bool _shiftRows, bool _shiftCols) {
    _data.resize(_rows + (ll)_shiftRows);
    for (ll i = 0; i < _rows + (ll)_shiftRows; i++)
        _data[i].resize(_cols + (ll)_shiftCols);
    for (ll i = (ll)_shiftRows; i < _rows + (ll)_shiftRows; i++)
        for (ll j = (ll)_shiftCols; j < _cols + (ll)_shiftCols; j++)
            cin >> _data[i][j];
}

template <typename T>
void write(vector<T> & _data, bool _shift) {
    for (ll i = (ll)_shift; i < _data.size(); i++)
        cout << _data[i] << " ";
    cout << endl;
}


//TODO: SOLUTION

ll sign(ll x) {
    if (x < 0)
        return -1;
    else if (x > 0)
        return 1;
    else
        return 0;
}

void solve() {
    ll n, k;
    cin >> n >> k;
    vll a;
    read(a, n, 0);

    vpll p;
    for (auto y : a) {
        p.push_back({abs(y), sign(y)});
    }

    sort(p.begin(), p.end());
    ll sign = 1;

    ll ans = 1;
    for (int i = n - 1; i >= n - k; i--) {
        ans *= p[i].first;
        sign *= p[i].second;
        ans = ans % mod;
    }

    if (sign >= 0) {
        cout << ans << endl;
    }
    else {
        int minneg = n;
        int i = n - 1;
        while (i >= n - k) {
            if (p[i].second == -1)
                minneg = i;
            i--;
        }
        int minpos = n;
        i = n - 1;
        while (i >= n - k) {
            if (p[i].second == 1)
                minpos = i;
            i--;
        }
        int maxneg = -1;
        i = 0;
        while (i < n - k) {
            if (p[i].second == -1)
                maxneg = i;
            i++;
        }
        int maxpos = -1;
        i = 0;
        while (i < n - k) {
            if (p[i].second >= 0)
                maxpos = i;
            i++;
        }

        int omit = -1;
        int take = -1;

        if (minneg != n && minpos != n && maxneg != -1 && maxpos != -1) {
            if (p[maxpos].fi * p[minpos].fi > p[maxneg].fi * p[minneg].fi) {
                omit = minneg;
                take = maxpos;
            }
            else {
                omit = minpos;
                take = maxneg;
            }
        }
        else if (minneg != n && maxpos != -1) {
            omit = minneg;
            take = maxpos;
        }
        else if (minpos != n && maxneg != -1) {
            omit = minpos;
            take = maxneg;
        }
        else {
            ll an = -1;
            for (int i = 0; i < k; i++) {
                an *= p[i].first;
                an = an % mod;
            }
            while (an < 0)
                an += mod;
            cout << an << endl;
            return;
        }

        ll an = 1;
        for (int j = n - 1; j >= n - k; j--) {
            if (j != omit) {
                an *= p[j].first;
                an = an % mod;
            }
        }
        an *= p[take].first;
        an = an % mod;
        cout << an << endl;
    }
}


int main() {

    // TODO: Set value of this variable manually
    bool _multipleTestCases = false;

    if (_multipleTestCases) {
        ll t; cin >> t;
        while (t--)
            solve();
    }
    else {
        solve();
    }

    return 0;
}


Measured memory_bytes: 8948