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

int* mallocint(int si)
{
    return (int*) malloc(si * sizeof(int));
}

int* inputint(int n)
{
    int *ans = mallocint(n);
    for( int i = 0; i < n; i++ ) cin >> ans[i];
    return ans;
}

#define _LL long long

class ModInt
{
public:
    static int _BM;
    long long int m_value;
    ModInt()
    {
        m_value = 0;
    }

    ModInt(int v)
    {
        m_value = (long long int) v;
    }

    ModInt(const ModInt &t)
    {
        m_value = t.getint();
    }

    int operator + (const ModInt &t) 
    {
		return ModInt::modadd(getint(), t.getint());
	}    

    int operator + (int t) 
    {
		return ModInt::modadd(getint(), t);
	}      

    int operator -  (const ModInt &t) 
    {
		return ModInt::modminus(getint(), t.getint());
	}    
    int operator - (int t) 
    {
		return ModInt::modminus(getint(), t);
	}  

    int operator * (const ModInt &t) 
    {
		return ModInt::modmul(getint(), t.getint());
	}  
    int operator * (int t) 
    {
		return ModInt::modmul(getint(), t);
	} 

    ModInt& operator += ( const ModInt &t )
    {
        (*this) += t.getint();
        return (*this);
    }


    ModInt& operator *= ( const ModInt &t )
    {
        (*this) *= t.getint();
        return (*this);
    }

    ModInt& operator -= ( const ModInt &t )
    {
        (*this) -= t.getint();
        return (*this);
    }

    ModInt& operator += ( int v )
    {
        m_value += v;
        if(m_value >= _BM) m_value -= _BM;
        return *this;
    }

    ModInt& operator -= ( int v )
    {
        m_value -= v;
        if( m_value < 0 ) m_value += _BM;
        return *this;
    }

    ModInt& operator *= ( int v )
    {
        m_value *= v;
        m_value %= _BM;
        if( m_value < 0 ) m_value += _BM;
        return *this;
    }

    static int modadd( int a, int b )
    {
        ModInt t(a);
        t += b;
        return t.getint();
    }

    static int modminus( int a, int b )
    {
        ModInt t(a);
        t -= b;
        return t.getint();
    }    

    static int modmul( int a, int b )
    {
        ModInt t(a);
        t *= b;
        return t.getint();
    }

    // a^b;
    static int modpow(int a, int b)
    {
        ModInt ans(1);
        int heap[32];
        heap[0] = a;
        for( int bit = 0; b >= (1 << bit); bit++ )
        {
            if( bit > 0 ) heap[bit] = modmul( heap[bit - 1], heap[bit - 1] );
            if( b & (1 << bit) )
            {
                ans *= heap[bit];
            }
        }
        return ans.getint();
    }

    static int reciprocal(int a)
    {
        return modpow(a, _BM - 2);
    }

    static int combination(int n, int r)
    {
        int *fac = (int *)malloc(sizeof(int) * (n + 1));
        int *facinv = (int *)malloc(sizeof(int) * (n + 1));
        fac[0] = 1;
        for( int k = 1; k <= n; k++) fac[k] = modmul(k, fac[k - 1]);
        facinv[n] = reciprocal( fac[n] );
        for( int k = n ; k > 0; k--) facinv[k - 1] = modmul(k, facinv[k]);

        ModInt ans(fac[n]);
        ans *= facinv[r];
        ans *= facinv[n - r];

        free(fac);
        free(facinv);
        return ans.getint();
    }

    int getint() const
    {
        return (int) m_value;
    }


private:
    void _mod()
    {
        m_value %= _BM;
    }
};

int ModInt::_BM = 1000000007;



bool comp(int a, int b)
{
    return abs(a) > abs(b);
}

int calc(int *a, int n, int k)
{
    int dcount = 0;
    for(int i = 0; i < k; i++ )
    {
        if( a[i] == 0 ) return 0;
        if( a[i] < 0 ) dcount++;
    }

    if( dcount % 2 == 0)
    {
        ModInt ans = 1;
        for(int i = 0; i < k; i++ ) ans *= abs(a[i]);
        return ans.getint();
    }

    int ml = -1;
    int pl = -1;
    int mf = n;
    int pf = n;
    for( int i = k - 1; i >= 0; i-- )
    {
        if( a[i] < 0 )
        {
            ml = i;
            break;
        }
    }
    for( int i = k - 1; i >= 0; i-- )
    {
        if( a[i] > 0 )
        {
            pl = i;
            break;
        }
    }

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

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


    int ci1 = 0;
    int ci2 = 0;
    if( ml < 0 || pf >= n )
    {
        if( pl < 0 || mf >= n )
        {
            // プラスにできない
            ModInt ans = 1;
            for(int i = n - k; i < n; i++ ) ans *= abs(a[i]);
            ans *= -1;
            return ans.getint();            
        }
        else
        {
            ci1 = pl;
            ci2 = mf;
        }
    }
    else
    {
        if( pl < 0 || mf >= n )
        {
            ci1 = ml;
            ci2 = pf;   
        }
        else
        {
            if( ((_LL)(a[pf])) *((_LL)(a[pl])) > ((_LL)(a[mf])) *((_LL)(a[ml])) )
            {
                ci1 = ml;
                ci2 = pf;
            }
            else
            {
                ci1 = pl;
                ci2 = mf;
            }
        }
    }

    {
        ModInt ans;
        ans = 1;
        for(int i = 0; i < k; i++ ) 
        {
            if( i != ci1) ans *= abs(a[i]);
        }
        ans *= abs(a[ci2]);
        return ans.getint();      
    }
    


}

int main()
{
    int n, k;
    cin >> n >> k;
    int *a = inputint(n);
    sort(a, a + n, comp);
    cout << calc(a, n, k);
}

Measured memory_bytes: 4324