#define INF 10000000000
#define MOD 1000000007

#if 1   // use_templates

#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <algorithm>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define rep(i, up) for (ll i = 0; i < up; ++i)
#define repp(i, up) for (ll i = 0; i <= up; ++i)
#define rrep(i, lo, up) for (ll i = lo; i < up; ++i)
#define rrepp(i, lo, up) for (ll i = lo; i <= up; ++i)
#define eep(i, lo, up) for ((i) = (lo); (i) < (up); ++(i))
#define eepp(i, lo, up) for ((i) = (lo); (i) <= (up); ++(i))


ll gcd(ll a, ll b);

ll gcd(ll a, ll b)
{
    if (a < b) {
        return gcd(b, a);
    }
    ll r;
    while (r = a % b) {
        a = b;
        b = r;
    }
    return b;
}

#endif  // end of use_templates

#ifndef TEMPLATE_MOD
#define TEMPLATE_MOD

#include <iostream>

#ifndef MOD
#define MOD 1000000007
#pragma message("using default mod ")
#endif

typedef long long ll;
typedef unsigned long long ull;

template<class T>
constexpr auto my_pow(T a, ll n);

constexpr bool is_prime(ll n) {
    if (n < 2) {
        return false;
    }
    for (ll i = 2; i * i <= n; ++i) {
        if (n % i == 0) {
            return false;
        }
    }
    return true;
}

template<class T, T n>
class mod_t
{
    static_assert(n > 1, "invalid modulus");

    T value;

public:
    constexpr mod_t() : value() { }
    constexpr mod_t(T x) : value(normalize(x)) { }
    constexpr mod_t(const mod_t& x) : value(x.value) { }

    explicit constexpr operator T() const {
        return value;
    }
    constexpr auto& operator+=(mod_t<T, n> right) {
        value = (value + right.value) % n;
        return *this;
    }
    constexpr auto& operator++() {
        return *this += mod_t<T, n>(1);
    }
    constexpr auto operator++(int) {
        decltype(*this) tmp(*this);
        *this = *this + mod_t<T, n>(1);
        return tmp;
    }
    constexpr auto& operator-=(mod_t<T, n> right) {
        value = (value - right.value + n) % n;
        return *this;
    }
    constexpr auto& operator--() {
        return *this -= mod_t<T, n>(1);
    }
    constexpr auto operator--(int) {
        decltype(*this) tmp(*this);
        *this = *this - mod_t<T, n>(1);
        return tmp;
    }
    constexpr auto& operator*=(mod_t<T, n> right) {
        value = (value * right.value) % n;
        return *this;
    }
    constexpr auto& operator/=(mod_t<T, n> right) {
        static_assert(is_prime(n), "not a prime");
        return *this = *this * right.pow(n - 2);
    }
    constexpr auto pow(ll nn) const {
        return my_pow(*this, nn);
    }
    constexpr auto inv() const {
        return pow(n - 2);
    }

    static constexpr auto normalize(T x) {
        if (x < 0) {
            return (n + x % n) % n;
        } else {
            return x % n;
        }
    }
};
template<class T, T n>
constexpr auto operator+(mod_t<T, n> left, mod_t<T, n> right) {
    return mod_t<T, n>(left) += right;
}
template<class T, T n>
constexpr auto operator+(mod_t<T, n> left, T right) {
    return mod_t<T, n>(left) += right;
}
template<class T, T n>
constexpr auto operator+(T left, mod_t<T, n> right) {
    return mod_t<T, n>(left) += right;
}
template<class T, T n>
constexpr auto operator-(mod_t<T, n> left, mod_t<T, n> right) {
    return mod_t<T, n>(left) -= right;
}
template<class T, T n>
constexpr auto operator-(mod_t<T, n> left, T right) {
    return mod_t<T, n>(left) -= right;
}
template<class T, T n>
constexpr auto operator-(T left, mod_t<T, n> right) {
    return mod_t<T, n>(left) -= right;
}
template<class T, T n>
constexpr auto operator*(mod_t<T, n> left, mod_t<T, n> right) {
    return mod_t<T, n>(left) *= right;
}
template<class T, T n>
constexpr auto operator*(mod_t<T, n> left, T right) {
    return mod_t<T, n>(left) *= right;
}
template<class T, T n>
constexpr auto operator*(T left, mod_t<T, n> right) {
    return mod_t<T, n>(left) *= right;
}
template<class T, T n>
constexpr auto operator/(mod_t<T, n> left, mod_t<T, n> right) {
    return mod_t<T, n>(left) /= right;
}
template<class T, T n>
constexpr auto operator/(mod_t<T, n> left, T right) {
    return mod_t<T, n>(left) /= right;
}
template<class T, T n>
auto& operator>>(std::istream& in, mod_t<T, n>& out) {
    T tmp;
    in >> tmp;
    out.value = mod_t<T, n>::normalize(tmp);
    return in;
}
template<class T, T n>
auto& operator<<(std::ostream& out, mod_t<T, n> val) {
    out << (T)val;
    return out;
}
typedef mod_t<ll, MOD> mod;

template<class T>
constexpr auto my_pow(T a, ll n) {
    if (n <= 0) {
        return T(1);
    } else if (n == 1) {
        return T(a);
    } else if (n % 2 == 0) {
        auto work = my_pow(a, n / 2);
        return work * work;
    } else {
        return my_pow(a, n - 1) * a;
    }
}

#endif  // defined(TEMPLATE_MOD)



int main()
{
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    rep(i, n) {
        cin >> a[i];
    }
    sort(a.begin(), a.end(), [](ll l, ll r)
         {
             return abs(l) > abs(r);
         });
    ll cnt = 0;
    rep(i, k) {
        if (a[i] < 0) {
            ++cnt;
        }
    }
    if (cnt % 2 == 0) {
        mod result = 1;
        rep(i, k) {
            result *= a[i];
        }
        cout << result << endl;
        return 0;
    }

    mod prod = 1;
    rep(i, k) {
        prod *= a[i];
    }

    bool pf = false, nf = false;
    ll pv0 = 0, pv1 = 0, nv0 = 0, nv1 = 0;
    auto pi = find_if(a.rbegin() + (a.size() - k), a.rend(), [](ll x)
                      {
                          return x > 0;
                      });
    if (pi != a.rend()) {
        auto pj = find_if(a.begin() + k, a.end(), [](ll x)
                          {
                              return x < 0;
                          });
        if (pj != a.end()) {
            pf = true;
            pv0 = *pi;
            pv1 = *pj;
        }
    }
    auto ni = find_if(a.rbegin() + (a.size() - k), a.rend(), [](ll x)
                      {
                          return x < 0;
                      });
    if (ni != a.rend()) {
        auto nj = find_if(a.begin() + k, a.end(), [](ll x)
                          {
                              return x > 0;
                          });
        if (nj != a.end()) {
            nf = true;
            nv0 = *ni;
            nv1 = *nj;
        }
    }
    mod result1, result2;
    if (pf) {
        result1 = prod / pv0 * pv1;
    }
    if (nf) {
        result2 = prod / nv0 * nv1;
    }
    if (pf && nf) {
        if (nv0 * pv1 > pv0 * nv1) {
            cout << result1 << endl;
        } else {
            cout << result2 << endl;
        }
        return 0;
    } else if (pf) {
        cout << result1 << endl;
        return 0;
    } else if (nf) {
        cout << result2 << endl;
        return 0;
    }
    sort(a.begin(), a.end(), [](ll l, ll r) { return abs(l) < abs(r); });
    prod = 1;
    rep(i, k) {
        prod *= a[i];
    }
    cout << prod << endl;
    return 0;
}


Measured memory_bytes: 4368