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

# define C continue;
# define R return

# define D double
# define I insert
# define ll long long
# define ld long double

# define ull unsigned long long
# define ui unsigned int

# define pb push_back
# define pf push_front

# define vi vector < int >
# define vc vector < char >
# define vs vector < string >
# define vb vector < bool >
# define vd vector < D >
# define vll vector < ll >
# define vull vector < ull >
# define vld vector < ld >
# define PQ priority_queue

# define vvi vector < vector < int > >
# define vvb vector < vector < bool > >
# define vvc vector < vector < char > >
# define vvs vector < vs >
# define vvll vector < vector < ll > >
# define vvd vector < vector < D > >
# define vvld vector < vector < ld > >

# define all(v) (v).begin() , (v).end()
# define allrev(v) (v).rbegin() , (v).rend()
# define allcomp(v) v.begin() , v.end() , comp
# define allrevcomp(v) v.rbegin() , v.rend() , comp

# define pii pair < int , int >
# define pll pair < ll , ll >
# define pld pair < ld , ld >
# define pDD pair < D , D >

# define vpld vector < pld >
# define vpii vector < pii >
# define vpll vector < pll >
# define vpDD vector < pDD >

# define vvpii vector < vector < pii > >
# define F first
# define S second
# define mp make_pair

# define dist(a,b,p,q) sqrt((p-a)*(p-a) + (q-b)*(q-b))

# define pp(n) printf("%.10Lf",n);
# define line cout<<"\n";
# define fast ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0);

string vow = "aeiou";
int month[] = {-1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

const int dxhorse[] = {-2, -2, -1, -1, 1, 1, 2, 2};
const int dyhorse[] = {1, -1, 2, -2, 2, -2, 1, -1};

const int dx[] = { -1 , 0 , 1 , 0 } ;
const int dy[] = { 0 , 1 , 0 , -1 } ;

const ld pie = 3.1415926535897932384626 ;
const ll mod = 1e9 + 7 ;

/// Tip : If a and b are positive integers ; we may say - ceil (a/b) = 1 + floor ( (a-1)/b ) .

bool comp ( const int &a , const int &b )
{
    int temp_a = abs ( a ) ;
    int temp_b = abs ( b ) ;

    if ( temp_a > temp_b )
        return true ;

    if ( temp_a < temp_b )
        return false ;

    return ( a > b ) ;
}

ll mod_pow ( ll a , ll b )
{
    if ( b == 0 ) return 1 ;
    if ( b == 1 ) return (a%mod) ;
    if ( b == 2 ) return ((a%mod)*(a%mod))%mod ;

    return (mod_pow ( mod_pow ( a , b>>1 ) , 2 ) * mod_pow ( a , (b&1) ))%mod ;
}

ll mod_inv ( ll n ) /// mod should be prime
{
    return mod_pow ( n , mod - 2 ) ;
}

void print ( vi &v )
{
    for ( auto &i : v )
        cout << i << " " ;

    line ;
}

void solve ( int test_case )
{
    int n , k ;
    cin >> n >> k ;

    vi v ( n ) ;
    for ( int i=0 ; i < n ; i ++ )
        cin >> v[i] ;

    sort ( allcomp ( v ) ) ;

//    print ( v ) ;

    int neg = 0 ;
    for ( int i=0 ; i < k ; i ++ )
    {
        if ( v[i] < 0 )
            neg ++ ;
    }

    if ( v[k - 1] == 0 || ( neg % 2 == 0 ) )
    {
        ll ans = 1 ;

        for ( int i=0 ; i < k ; i ++ )
            ans *= v[i] , ans %= mod ;

        if ( ans < 0 )
            ans += mod ;

        cout << ans ; line ; return ;
    }

    /// choice 1 :

    ll take_1 = INT_MAX ;
    ll rem_1 = INT_MAX ;

    for ( int i = k ; i < n ; i ++ )
    {
        if ( v[i] < 0 )
        {
            take_1 = v[i] ;
            break ;
        }
    }

    for ( int i=0 ; i < k ; i ++ )
    {
        if ( v[i] > 0 )
        {
            rem_1 = v[i] ;
        }
    }

    /// choice 2 :

    int take_2 = INT_MAX , rem_2 = INT_MAX ;

    for ( int i=k ; i < n ; i ++ )
    {
        if ( v[i] > 0 )
        {
            take_2 = v[i] ;
            break ;
        }
    }

    for ( int i=0 ; i < k ; i ++ )
    {
        if ( v[i] < 0 )
            rem_2 = v[i] ;
    }

//    cout << take_1 << " " << rem_1 << " " << take_2 << " " << rem_2 << '\n' ;

    pll opt = { INT_MAX , INT_MAX } ;

    if ( take_1 != INT_MAX && take_2 != INT_MAX && rem_1 != INT_MAX && rem_2 != INT_MAX )
    {
        if ( take_1 * rem_2 > take_2 * rem_1 )
            opt = { take_1 , rem_1 } ;

        else opt = { take_2 , rem_2 } ;
    }

    else if ( take_1 != INT_MAX && rem_1 != INT_MAX )
        opt = { take_1 , rem_1 } ;

    else if ( take_2 != INT_MAX && rem_2 != INT_MAX )
        opt = { take_2 , rem_2 } ;

    if ( opt.F != INT_MAX && opt.S != INT_MAX )
    {
//        cout << "opt.F : " << opt.F << " and opt.S : " << opt.S ; line ;

        ll ans = 1 ;
        for ( int i=0 ; i < k ; i ++ )
            ans *= v[i] , ans %= mod ;

        ans *= mod_inv ( opt.S ) ;
        ans %= mod ;

        ans *= opt.F ;
        ans %= mod ;

//        cout << "ans : " << ans ; line ;

        if ( ans < 0 )
            ans += mod ;

        cout << ans ; line ; return ;
    }

    reverse ( all ( v ) ) ;

    ll ans = 1 ;

    for ( int i=0 ; i < k ; i ++ )
        ans *= v[i] , ans %= mod ;

    if ( ans < 0 )
        ans += mod ;

    cout << ans ; line ;
}

int main()
{fast
    int t = 1;
    // cin >> t;

    for ( int i = 1 ; i <= t ; i ++ )
    {
        solve ( i ) ;
    }

    return 0;
}


Measured memory_bytes: 3976