#include <algorithm>
#include <chrono>
#include <cmath>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vi2;
typedef vector<vi2> vi3;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<ll> vll;
typedef vector<vll> vll2;
typedef vector<vll2> vll3;
typedef vector<bool> vb;

#define el '\n'
#define rep(i, a, b) for (int i = a; i < b; i++)
#define repi(i, a, b) for (int i = a; i >= b; i--)
#define repeat(n) for (int i = 0; i < n; i++)
#define umap unordered_map
#define uset unordered_set
#define vec vector
#define loop(a) for (auto &x : a)
#define all(a) begin(a), end(a)
#define mp make_pair
#define pb push_back

template <typename T>
void debug0(const T &value) {
    cerr << value << endl;
}

template <typename T, typename... Args>
void debug0(const T &value, const Args &... args) {
    cerr << value << ' ';
    debug0(args...);
}

#ifdef LOCAL
#define debug(...) debug0(__VA_ARGS__)
#else
#define debug(...)
#endif

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll MODULO = 1e9 + 7;

class ModLL {
   public:
    ModLL() : x(0) {}

    ModLL(ll x) : x(x % MODULO) {}

    ModLL operator=(ll x) {
        return ModLL(x);
    }

    ModLL operator=(const ModLL &x) {
        return ModLL(x.x);
    }

    ModLL operator+(const ModLL &x) {
        ModLL ret(this->x);
        adds(ret.x, x.x);
        return ret;
    }

    ModLL operator-(const ModLL &x) {
        ModLL ret(this->x);
        adds(ret.x, -x.x);
        return ret;
    }

    ModLL operator*(const ModLL &x) {
        ModLL ret(this->x);
        muls(ret.x, x.x);
        return ret;
    }

    ModLL operator/(const ModLL &x) {
        ModLL ret(this->x);
        muls(ret.x, invmod(x.x));
        return ret;
    }

    void operator*=(const ModLL &x) {
        muls(this->x, x.x);
    }

    void operator/=(const ModLL &x) {
        muls(this->x, invmod(x.x));
    }

    friend ostream &operator<<(ostream &os, const ModLL &x);

   private:
    ll x;

    void adds(ll &a, ll b) {
        a += b;
        while (a >= MODULO) {
            a -= MODULO;
        }
        while (a < 0) {
            a += MODULO;
        }
    }

    void muls(ll &a, ll b) {
        a = (a % MODULO) * (b % MODULO) % MODULO;
    }

    ll extgcd(ll a, ll b, ll &x, ll &y) {
        if (a == 0) {
            x = 0;
            y = 1;
            return b;
        }
        ll x1, y1;
        ll d = extgcd(b % a, a, x1, y1);
        x = y1 - (b / a) * x1;
        y = x1;
        return d;
    }

    ll invmod(ll a, ll m) {
        ll x, y;
        ll g = extgcd(a, m, x, y);
        if (g != 1) {
            return -1;
        } else {
            x = (x % m + m) % m;
            return x;
        }
    }

    ll invmod(ll a) {
        return invmod(a, MODULO);
    }
};

ostream &operator<<(ostream &os, const ModLL &x) {
    os << x.x;
    return os;
}

ll mod(ll x) {
    ll ret = x % MODULO;
    if (ret < 0) {
        ret += MODULO;
    }
    return ret;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int N, K;
    cin >> N >> K;
    vi A(N);
    int n = 0, z = 0, p = 0;
    loop(A) {
        cin >> x;
        if (x > 0) {
            p++;
        } else if (x == 0) {
            z++;
        } else {
            n++;
        }
    }
    debug(n, z, p);
    // postive max
    if ((K % 2 == 0 && p / 2 + n / 2 >= K / 2) || (K % 2 == 1 && (p > 0) && (p - 1) / 2 + n / 2 >= (K - 1) / 2)) {
        debug("go positive");
        sort(all(A));
        int i = 0, j = N - 1;
        ModLL ans = 1;
        int left = K;
        if (K % 2 == 1) {
            ans *= A[j];
            j--;
            left--;
        }
        while (left > 0) {
            ll nn = -1, pp = -1;
            if (A[i] < 0 && A[i + 1] < 0) {
                nn = (ll)A[i] * A[i + 1];
            }
            if (A[j] > 0 && A[j - 1] > 0) {
                pp = (ll)A[j] * A[j - 1];
            }
            if (nn > 0 && nn > pp) {
                ans *= nn;
                i += 2;
            } else {
                ans *= pp;
                j -= 2;
            }
            left -= 2;
        }
        cout << ans << el;
        return 0;
    }

    // zero
    if (z > 0) {
        cout << 0 << el;
        return 0;
    }

    // negative min
    sort(all(A), [](int a, int b) {
        return abs(a) < abs(b);
    });
    ModLL ans = 1;
    repeat(K) {
        ans *= mod(A[i]);
    }
    cout << ans << el;
}


Measured memory_bytes: 3996