using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

class MainClass : Scanner
{
    static void Main()
    {
        var (N, K) = ReadTuple<int,int>();
        var A = RLongs();
        Array.Sort(A, (a, b) => Abs(a).CompareTo(Abs(b)));
        Array.Reverse(A);

        if (N == K)
        {
            Modular ans = 1;
            for (int i = 0; i < N; i++)
            {
                ans *= A[i];
            }
            WriteLine((int)ans); return;
        }
        var Posi = new List<long>();
        var Nega = new List<long>();
        for (int i = 0; i < N; i++)
        {
            if (A[i] >= 0) Posi.Add(A[i]);
            else Nega.Add(A[i]);
        }
        if (Posi.Count == 0)
        {
            Modular ans = 0;
            if (K % 2 == 0) ans = MulFromFirst(A, K);
            else ans = MulFromLast(A, K);
            WriteLine((int)ans);
            return;
        }
        if (Nega.Count == 0)
        {
            Modular ans = MulFromFirst(A, K);
            WriteLine((int)ans);
            return;
        }
        {
            Modular ans = 1;
            int k = K;
            int p = 0, n = 0;
            while (k >= 2)
            {
                long ps = -1, ng = -1;
                if (Posi.Count > p + 1) { ps = Posi[p] * Posi[p + 1]; }
                if (Nega.Count > n + 1) { ng = Nega[n] * Nega[n + 1]; }

                if (ps >= ng) {  ans *= Posi[p];p += 1;k--; }
                else { ans *= ng;n += 2;k -= 2; }
            }
            if (k == 1)
            {
                if (Posi.Count > p) { ans *= Posi[p]; }
                else
                {
                    //p>=1
                    ans /= Posi[p - 1];
                    ans *= Nega[n] * Nega[n + 1];
                }
            }
            WriteLine((int)ans);
        }

    }
    static Modular MulFromFirst(long[] A,int K)
    {
        Modular ans = 1;
        for (int i = 0; i < K; i++)
        {
            ans *= A[i];
        }
        return ans;
    }
    static Modular MulFromLast(long[] A,int K)
    {
        Modular ans = 1;
        int N = A.Length;
        for (int i = N - 1; i >= N-K; i--)
        {
            ans *= A[i];
        }
        return ans;
    }
}
class Modular
{
    private const int M = 1000000007;
    private const int arysize = 2000001;
    private long value;
    public Modular(long value = 0) { this.value = value; }
    public override string ToString() { return value.ToString(); }
    public static implicit operator Modular(long a)
    {
        var m = a % M;
        return new Modular((m < 0) ? m + M : m);
    }
    public static Modular operator +(Modular a, Modular b)
    => a.value + b.value;
    public static Modular operator -(Modular a, Modular b)
    => a.value - b.value;
    public static Modular operator *(Modular a, Modular b)
    => a.value * b.value;
    public static Modular Pow(Modular a, long n)
    {
        Modular ans = 1;
        for (; n > 0; n >>= 1, a *= a)
        {
            if ((n & 1) == 1) ans *= a;
        }
        return ans;
    }
    public static Modular operator /(Modular a, Modular b)
    {
        return a * Pow(b, M - 2);
    }
    private static int[] facs = new int[arysize];
    private static int facscount = -1;

    public static Modular Fac(int n)   //階乗
    {
        facs[0] = 1;
        while (++facscount <= n)
        {
            facs[facscount + 1] = (int)(Math.BigMul(facs[facscount], facscount + 1) % M);
        }
        return facs[n];
    }
    public static Modular Fac(int r, int n)//記録しない階乗
    {
        int temp = 1;
        for (int i = r; i <= n; i++)
        {
            temp = (int)(Math.BigMul(temp, i) % M);
        }
        return temp;
    }
    public static Modular Ncr(int n, int r) //nCr
    {
        return (n < r) ? 0
             : (n == r) ? 1
                        : (Math.Max(n, r) <= arysize) ? Fac(n) / (Fac(r) * Fac(n - r))
                            : Fac(n - r + 1, n) / Fac(r);
    }
    public static explicit operator int(Modular a)
    {
        return (int)a.value;
    }
}


class Scanner
{
    public static string RString() => Console.ReadLine();
    public static int RInt() => ReadTuple<int>();
    public static long RLong() => ReadTuple<long>();
    public static double RDouble() => ReadTuple<double>();

    public static string[] RStrings() => Console.ReadLine().Split();
    public static int[] RInts() => Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
    public static long[] RLongs() => Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
    public static double[] RDoubles() => Array.ConvertAll(Console.ReadLine().Split(), double.Parse);
    public static int[] RInts(Func<string, int> func) => Console.ReadLine().Split().Select(func).ToArray();
    public static long[] RLongs(Func<string, long> func) => Console.ReadLine().Split().Select(func).ToArray();
    public static double[] RDoubles(Func<string, double> func) => Console.ReadLine().Split().Select(func).ToArray();
    //public static string[] RStrings(Func<string, string> func) => Console.ReadLine().Split().Select(func).ToArray();

    public static T1 ReadTuple<T1>()
    {
        var r = RString();
        var r1 = (T1)Convert.ChangeType(r, typeof(T1));
        return r1;
    }
    public static (T1, T2) ReadTuple<T1, T2>()
    {
        var r = RStrings();
        var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
        var r2 = (T2)Convert.ChangeType(r[1], typeof(T2));
        return (r1, r2);
    }
    public static (T1, T2, T3) ReadTuple<T1, T2, T3>()
    {
        var r = RStrings();
        var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
        var r2 = (T2)Convert.ChangeType(r[1], typeof(T2));
        var r3 = (T3)Convert.ChangeType(r[2], typeof(T3));
        return (r1, r2, r3);
    }
    public static (T1, T2, T3, T4) ReadTuple<T1, T2, T3, T4>()
    {
        var r = RStrings();
        var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
        var r2 = (T2)Convert.ChangeType(r[1], typeof(T2));
        var r3 = (T3)Convert.ChangeType(r[2], typeof(T3));
        var r4 = (T4)Convert.ChangeType(r[3], typeof(T4));
        return (r1, r2, r3, r4);
    }
}


Measured memory_bytes: 59044