use std::io::{stdin, Read};
trait Monoid {
    fn unit() -> Self;
    fn add(lhs: Self, rhs: Self) -> Self;
}

struct SegTree<T: Monoid + Clone> {
    dat: Vec<T>,
    n: usize,
}

impl<T: Monoid + Copy> SegTree<T> {
    pub fn new(n: usize) -> Self {
        let dat = vec![T::unit(); n << 1];
        SegTree { dat: dat, n: n }
    }
    pub fn update(&mut self, k: usize, v: T) {
        let mut k = k + self.n;
        self.dat[k] = v;
        while {
            k >>= 1;
            k > 0
        } {
            self.dat[k] = T::add(self.dat[k << 1], self.dat[k << 1 | 1]);
        }
    }
    pub fn get(&self, a: usize, b: usize) -> T {
        let mut a = a + self.n;
        let mut b = b + self.n;
        let mut va = T::unit();
        let mut vb = T::unit();
        while a < b {
            if a & 1 != 0 {
                va = T::add(va, self.dat[a]);
                a += 1;
            }
            if b & 1 != 0 {
                vb = T::add(self.dat[b - 1], vb);
            }
            a >>= 1;
            b >>= 1;
        }
        T::add(va, vb)
    }
}

macro_rules! parse {
    ($it: ident) => {
        $it.next().unwrap().parse().unwrap()
    };
    ($it: ident,2) => {
        (parse!($it), parse!($it))
    };
    ($it: ident,3) => {
        (parse!($it), parse!($it), parse!($it))
    };
    ($it: ident,4) => {
        (parse!($it), parse!($it), parse!($it), parse!($it))
    };
    ($it: ident, $n: expr) => {
        (&mut $it).take($n).map(|e| e.parse().unwrap()).collect();
    };
}

#[derive(Clone, Copy, PartialEq, Eq, Debug)]
struct Min(usize);
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
struct Max(usize);
impl Monoid for Min {
    fn unit() -> Self {
        Min(std::usize::MAX)
    }
    fn add(lhs: Self, rhs: Self) -> Self {
        Min(std::cmp::min(lhs.0, rhs.0))
    }
}
impl Monoid for Max {
    fn unit() -> Self {
        Max(0)
    }
    fn add(lhs: Self, rhs: Self) -> Self {
        Max(std::cmp::max(lhs.0, rhs.0))
    }
}

fn solve(s: &str) {
    let mut it = s.split_whitespace();
    let (n, k): (usize, usize) = parse!(it, 2);
    let p: Vec<usize> = parse!(it, n);
    let mut maxseg = SegTree::<Max>::new(n);
    let mut minseg = SegTree::<Min>::new(n);
    for i in 0..n {
        maxseg.update(i, Max(p[i]));
        minseg.update(i, Min(p[i]));
    }
    let mut ret = n - k + 1;
    let mut count = 1;
    for i in 1..(k - 1) {
        if p[i - 1] < p[i] {
            count += 1;
        } else {
            count = 1;
        }
    }
    let mut id = false;
    for l in 0..(n - k + 1) {
        let r = l + k;
        if p[r - 2] < p[r - 1] {
            count += 1;
        } else {
            count = 1;
        }
        if count >= k {
            if id {
                ret -= 1;
            } else {
                id = true;
            }
            continue;
        }
        if r >= n {
            continue;
        }
        let min = minseg.get(l, r + 1).0;
        let max = maxseg.get(l, r + 1).0;
        if min == p[l] && max == p[r] {
            ret -= 1;
        }
    }
    println!("{}", ret);
}

fn main() {
    let mut s = String::new();
    stdin().read_to_string(&mut s).unwrap();
    solve(&s);
}

#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn test_input() {
        let s = "
        6 3
6 1 3 2 4 5
        ";
        solve(s);
    }
}


Measured memory_bytes: 17784