using System;
using System.Collections.Generic;
using System.Linq;
using static Scanner;

class Program
{
    static void Main() => new Program().Solve();

    public void Solve()
    {
        int n = ReadInt();
        int k = ReadInt();
        int[] a = ReadInt(n).OrderBy(x => x).ToArray();
        int[] neg = a.TakeWhile(x => x < 0).ToArray();
        int[] pos = a.SkipWhile(x => x < 0).Reverse().ToArray();

        ModInt prod = 1;
        if (neg.Length == 0 || n == k)
        {
            foreach (var x in a.TakeLast(k)) prod *= x;
            Console.WriteLine((int)prod);
            return;
        }

        if (pos.Length == 0)
        {
            if (k % 2 == 0)
            {
                foreach (var x in a.Take(k)) prod *= x;
            }
            else
            {
                foreach (var x in a.TakeLast(k)) prod *= x;
            }
            Console.WriteLine((int)prod);
            return;
        }

        for (int i = 0; i <= neg.Length; i += 2)
        {
            if (k - i > pos.Length) continue;
            if (i + 1 < neg.Length && k - i - 2 >= 0 && (long)pos[k - i - 2] * pos[k - i - 1] < (long)neg[i] * neg[i + 1]) continue;
            prod = 1;
            foreach (var x in pos.Take(k - i)) prod *= x;
            foreach (var x in neg.Take(i)) prod *= -x;
            break;
        }
        Console.WriteLine((int)prod);
    }
}

static class Scanner
{
    static Queue<string> que = new Queue<string>();
    public static string Read() { if (!que.Any()) foreach (var s in Console.ReadLine().Split()) que.Enqueue(s); return que.Dequeue(); }
    public static int ReadInt() => int.Parse(Read());
    public static long ReadLong() => long.Parse(Read());
    public static double ReadDouble() => double.Parse(Read());
    public static decimal ReadDecimal() => decimal.Parse(Read());
    public static IEnumerable<string> Read(long n) { for (long i = 0; i < n; i++) yield return Read(); }
    public static IEnumerable<int> ReadInt(long n) => Read(n).Select(int.Parse);
    public static IEnumerable<long> ReadLong(long n) => Read(n).Select(long.Parse);
    public static IEnumerable<double> ReadDouble(long n) => Read(n).Select(double.Parse);
    public static IEnumerable<decimal> ReadDecimal(long n) => Read(n).Select(decimal.Parse);
}

struct ModInt
{
    const int MOD = 1000000007;
    long value;
    static List<ModInt> fact = new List<ModInt> { 1 };
    public ModInt(long value) => this.value = value;
    public static implicit operator ModInt(long a) => new ModInt(a % MOD + (a < 0 ? MOD : 0));
    public static explicit operator int(ModInt a) => (int)a.value;
    public static ModInt operator +(ModInt a, ModInt b) => a.value + b.value;
    public static ModInt operator -(ModInt a, ModInt b) => a.value - b.value;
    public static ModInt operator *(ModInt a, ModInt b) => a.value * b.value;
    public static ModInt operator /(ModInt a, ModInt b) => a * Inv(b);
    public static ModInt Pow(ModInt a, int n) { if (n == 0) return 1; if (n == 1) return a; var p = Pow(a, n / 2); return p * p * Pow(a, n % 2); }
    public static ModInt Inv(ModInt a) => Pow(a, MOD - 2);
    public static ModInt Fact(int n) { for (int i = fact.Count; i <= n; i++) fact.Add(fact[^1] * i); return fact[n]; }
    public static ModInt Npr(int n, int r) => Fact(n) / Fact(n - r);
    public static ModInt Ncr(int n, int r) => Fact(n) / Fact(n - r) / Fact(r);
    public static ModInt Nhr(int n, int r) => Fact(n + r - 1) / Fact(n - 1) / Fact(r);
}


Measured memory_bytes: 62380