use std::collections::BinaryHeap;
use std::cmp::Reverse;

fn main() {
    const MOD: isize = 1_000_000_007;

    let [n, k]: [usize; 2] = {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        let mut iter = buf.split_whitespace();
        [
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
        ]
    };
    let a: Vec<isize> = {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        let iter = buf.split_whitespace();
        iter.map(|x| x.parse().unwrap()).collect()
    };

    let mut minus = BinaryHeap::new();
    let mut plus = BinaryHeap::new();
    for i in 0..n {
        if a[i] < 0 {
            minus.push(Reverse(a[i]));
        } else {
            plus.push(a[i]);
        }
    }

    if k % 2 == 1 && plus.len() == 0 {
        let mut minus: BinaryHeap<_> = minus.iter().map(|x| x.0).collect();
        let mut plus: BinaryHeap<_> = plus.iter().map(|x| Reverse(x)).collect();
        let mut ans = 1;
        for _ in 0..k {
            match minus.pop() {
                Some(w) => {
                    match plus.pop() {
                        Some(Reverse(x)) => {
                            if w.abs() < x.abs() {
                                ans = ans * (w + MOD) % MOD;
                                plus.push(Reverse(x));
                            } else {
                                ans = ans * x % MOD;
                                minus.push(w);
                            }
                        },
                        None => {
                            ans = ans * (w + MOD) % MOD;
                        },
                    }
                },
                None => {
                    ans = ans * plus.pop().unwrap().0 % MOD;
                }
            }
        }
        println!("{}", ans);
    } else {
        let mut ans = 1;
        let mut minus_flag = false;
        for i in 0..k {
            if minus_flag {
                ans = ans * (minus.pop().unwrap().0 + MOD) % MOD;
                minus_flag = false;
                continue;
            }
            match minus.pop() {
                Some(Reverse(w)) => {
                    match minus.pop() {
                        Some(Reverse(x)) => {
                            match plus.pop() {
                                Some(y) => {
                                    match plus.pop() {
                                        Some(z) => {
                                            if i < k - 1 && w * x >= y * z {
                                                ans = ans * (w + MOD) % MOD;
                                                minus_flag = true;
                                                minus.push(Reverse(x));
                                                plus.push(y);
                                                plus.push(z);
                                            } else {
                                                ans = ans * y % MOD;
                                                minus.push(Reverse(w));
                                                minus.push(Reverse(x));
                                                plus.push(z);
                                            }
                                        },
                                        None => {
                                            if i == k - 1 {
                                                ans = ans * y % MOD;
                                            } else {
                                                ans = ans * (w + MOD) % MOD;
                                                minus_flag = true;
                                                minus.push(Reverse(x));
                                                plus.push(y); 
                                            }
                                        },
                                    }
                                },
                                None => {
                                    ans = ans * (w + MOD) % MOD;
                                    minus_flag = true;
                                    minus.push(Reverse(x));
                                },
                            }
                        },
                        None => {
                            match plus.pop() {
                                Some(y) => {
                                    ans = ans * y % MOD;
                                    minus.push(Reverse(w));
                                },
                                None => {
                                    ans = ans * (w + MOD) % MOD;
                                },
                            }
                        },
                    }
                },
                None => {
                    ans = ans * plus.pop().unwrap() % MOD;
                },
            }
        }
        println!("{}", ans);
    }
}

Measured memory_bytes: 6392