using System;
using System.Collections.Generic;
//using System.Windows;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Atcoder
{
    public class Program
    {
        private static long mod = 1000000007;
        private static long max = 999999999999;

        static void Main(string[] args)
        {
            var r = ReadSplit();
            var n = r[0].Long();
            var k = r[1].Long();

            var r2 = ReadSplit();
            var pCount = 0;
            var mCount = 0;
            for (int i = 0; i < n; i++)
            {
                if (r2[i].Long() >= 0)
                {
                    pCount++;
                }
                else
                {
                    mCount++;
                }
            }

            var pal = new long[pCount];
            var mal = new long[mCount];

            var pIndex = 0;
            var mIndex = 0;
            for (int i = 0; i < n; i++)
            {
                if (r2[i].Long() >= 0)
                {
                    pal[pIndex] = r2[i].Long();
                    pIndex++;
                }
                else
                {
                    mal[mIndex] = r2[i].Long();
                    mIndex++;
                }
            }

            Array.Sort(pal);
            Array.Reverse(pal);
            Array.Sort(mal);
            var useP = 0L;
            var useM = 0L;
            long ans = 1;
            if (pCount == 0 && k % 2 != 0)
            {
                Array.Reverse(mal);
            }

            if (pCount == 0)
            {
                for (int i = 0; i < k; i++)
                {
                    ans *= mal[i];
                    ans = (ans % mod + mod) % mod;
                }
                WriteRead(ans);
                return;
            }

            if (mCount == 0)
            {
                for (int i = 0; i < k; i++)
                {
                    ans *= pal[i];
                    ans = (ans % mod + mod) % mod;
                }
                WriteRead(ans);
                return;
            }

            for (int i = 0; i < k; i++)
            {
                if (k - i >= 2 && k - useM >= 2 && mal.Length > useM && useP != pCount)
                {
                    if (useP + 1 >= pCount && useM + 1 < mCount)
                    {
                        //正を選択したときに残りの負の数が偶数であることを考慮する必要
                        if (pal[useP] <= mal[useM] * mal[useM + 1] && (k - (useP + 1 + useM)) % 2 == 1)
                        {
                            ans *= mal[useM];
                            ans = (ans % mod + mod) % mod;
                            ans *= mal[useM + 1];
                            ans = (ans % mod + mod) % mod;
                            useM += 2;
                            i++;
                        }
                        else
                        {
                            ans *= pal[useP];
                            ans = (ans % mod + mod) % mod;
                            useP++;
                        }
                    }
                    else if (useP + 1 < pCount && useM + 1 < mCount && pal[useP] * pal[useP + 1] < mal[useM] * mal[useM + 1])
                    {
                        ans *= mal[useM];
                        ans = (ans % mod + mod) % mod;
                        ans *= mal[useM + 1];
                        ans = (ans % mod + mod) % mod;
                        useM += 2;
                        i++;
                    }
                    else if (useP < pCount)
                    {
                        ans *= pal[useP];
                        ans = (ans % mod + mod) % mod;
                        useP++;
                    }
                }
                else
                {
                    if (useP < pCount)
                    {
                        ans *= pal[useP];
                        ans = (ans % mod + mod) % mod;
                        useP++;
                    }
                    else
                    {
                        ans *= mal[useM];
                        ans = (ans % mod + mod) % mod;
                        useM++;
                    }
                }
            }
            WriteRead(ans);
        }

        public static string Read()
        {
            return Console.ReadLine();
        }

        public static string[] ReadSplit()
        {
            return Console.ReadLine().Split(' ');
        }

        public static void WriteRead(object str)
        {
            Console.WriteLine(str);
            Read();
        }

        public static void Write(object str)
        {
            Console.WriteLine(str);
        }

        private static bool ChangeMin<T>(ref T a, T b) where T : IComparable
        {
            if (a.CompareTo(b) > 0)
            {
                a = b;
                return true;
            }
            return false;
        }

        private static bool ChangekMax<T>(ref T a, T b) where T : IComparable
        {
            if (b.CompareTo(a) > 0)
            {
                a = b;
                return true;
            }
            return false;
        }

        private static bool NextPermutation(int[] array)
        {
            var size = array.Length;
            var ok = false;

            //array[i]<array[i+1]を満たす最大のiを求める
            int i = size - 2;
            for (; 0 <= i; i--)
            {
                if (array[i] < array[i + 1])
                {
                    ok = true;
                    break;
                }
            }

            //全ての要素が降順の場合、NextPermutationは存在しない
            if (ok == false) return false;

            //array[i]<array[j]を満たす最大のjを求める
            int j = size - 1;
            for (; ; j--)
            {
                if (array[i] < array[j]) break;
            }

            //iとjの要素をswapする
            var tmp = array[i];
            array[i] = array[j];
            array[j] = tmp;

            //i以降の要素を反転させる
            Array.Reverse(array, i + 1, size - (i + 1));

            return true;
        }

        //要素数Nを引数として渡し、0～N-1でできた順列をすべて返す
        static List<int[]> GetAllPermutation(int N)
        {
            var res = new List<int[]>();
            var array = Enumerable.Range(0, N).ToArray();
            do
            {
                var copy = new int[N];
                array.CopyTo(copy, 0);
                res.Add(copy);
            } while (NextPermutation(array));

            return res;
        }

        //配列arrayを引数として渡し,辞書順がarray以上の順列をすべて返す
        static List<int[]> GetAllPermutation(int[] array)
        {
            var size = array.Length;
            var res = new List<int[]>();
            do
            {
                var copy = new int[size];
                array.CopyTo(copy, 0);
                res.Add(copy);
            } while (NextPermutation(array));

            return res;
        }
    }
}


public static class Extentions
{
    public static int Int(this object obj)
    {
        return int.Parse(obj.ToString());
    }

    public static long Long(this object obj)
    {
        return long.Parse(obj.ToString());
    }

    public static decimal Decimal(this object obj)
    {
        return decimal.Parse(obj.ToString());
    }

    public static double Double(this object obj)
    {
        return double.Parse(obj.ToString());
    }

    public static T2 GetValueZero<T1, T2>(this Dictionary<T1, T2> d, T1 key) where T2 : struct
    {
        T2 value;
        if (d.TryGetValue(key, out value))
        {
            return value;
        }
        return new T2();
    }
}



Measured memory_bytes: 44140