const MOD: i64 = 1e9 as i64 + 7;
fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());
    let n: usize = sc.read();
    let k: usize = sc.read();

    let mut positive: Vec<i64> = vec![];
    let mut negative: Vec<i64> = vec![];
    for _ in 0..n {
        let a: i64 = sc.read();
        if a > 0 {
            positive.push(a);
        }
        if a < 0 {
            negative.push(a);
        }
    }

    positive.sort();
    positive.reverse();
    negative.sort();

    let mut p_sum = vec![0.0; positive.len() + 1];
    for i in 0..positive.len() {
        p_sum[i + 1] = p_sum[i] + (positive[i] as f64).log10();
    }
    let mut n_sum = vec![0.0; negative.len() + 1];
    for i in 0..negative.len() {
        n_sum[i + 1] = n_sum[i] + (-negative[i] as f64).log10();
    }

    let mut is_positive = false;
    let mut max_log = 0.0;
    let mut max_positive_count = 0;
    for positive_count in 0..=positive.len() {
        if positive_count > k {
            break;
        }
        let negative_count = k - positive_count;
        if negative_count % 2 == 1 {
            continue;
        }
        if negative_count > negative.len() {
            continue;
        }

        is_positive = true;
        let log = p_sum[positive_count] + n_sum[negative_count];
        if max_log < log {
            max_log = log;
            max_positive_count = positive_count;
        }
    }

    if !is_positive {
        let zero = n - positive.len() - negative.len();
        let mut v = vec![];
        for positive in positive.into_iter() {
            v.push(positive);
        }
        for negative in negative.into_iter() {
            v.push(-negative);
        }
        for _ in 0..zero {
            v.push(0);
        }
        v.sort();

        let mut ans = 1;
        for i in 0..k {
            ans *= v[i];
            ans %= MOD;
        }
        let ans = (MOD - ans) % MOD;
        println!("{}", ans);

        return;
    }

    let mut ans = 1;
    let negative_count = k - max_positive_count;
    for i in 0..negative_count {
        ans *= -negative[i];
        ans %= MOD;
    }
    for i in 0..max_positive_count {
        ans *= positive[i];
        ans %= MOD;
    }
    println!("{}", ans);
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> Self {
        Self(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: ToString>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.to_string().as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 7932