use std::cmp::Ordering;
use std::collections::VecDeque;
use std::io::{stdin, Read};
use std::str::FromStr;

// https://qiita.com/tubo28/items/e6076e9040da57368845
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

struct SegmentTree<T> {
    vs: Vec<T>,
    ord: Ordering,
    leaf_size: usize,
    default_value: T,
}

impl<T: Clone + Ord> SegmentTree<T> {
    pub fn min(n: usize, init: T) -> SegmentTree<T> {
        let d = init.clone();
        SegmentTree {
            vs: vec![init; n * 2],
            ord: Ordering::Less,
            leaf_size: n,
            default_value: d,
        }
    }

    pub fn max(n: usize, init: T) -> SegmentTree<T> {
        let d = init.clone();
        SegmentTree {
            vs: vec![init; n * 2],
            ord: Ordering::Greater,
            leaf_size: n,
            default_value: d,
        }
    }

    pub fn update(&mut self, leaf_index: usize, x: T) {
        self.upd(leaf_index, x)
    }

    fn upd(&mut self, leaf_index: usize, x: T) {
        let mut i = self.vs.len() - (self.leaf_size - leaf_index);
        self.vs[i] = x;

        while i > 1 {
            i = i / 2; // parent node id
            let (lc, rc) = (&self.vs[i * 2].clone(), &self.vs[i * 2 + 1].clone());
            let up = if lc.cmp(rc) == self.ord { lc } else { rc };
            self.vs[i] = up.clone();
        }
    }

    pub fn query(&self, from: usize, to: usize) -> T {
        self.q(from, to, 1, 0, self.leaf_size)
    }

    fn q(&self, a: usize, b: usize, k: usize, l: usize, r: usize) -> T {
        if r <= a || b <= l {
            return self.default_value.clone();
        } else if a <= l && r <= b {
            return self.vs[k].clone();
        } else {
            let mid = l + ((r - l) / 2);
            let lc = self.q(a, b, 2 * k, l, mid);
            let rc = self.q(a, b, 2 * k + 1, mid, r);
            if lc.cmp(&rc) == self.ord {
                lc
            } else {
                rc
            }
        }
    }
}

#[allow(dead_code)]
fn main() {
    let n = read::<usize>();
    let k = read::<usize>();
    let pp = (0..n).map(|_| read::<usize>()).collect::<Vec<_>>();

    let u_max = usize::max_value() as usize;
    let mut size = 1;
    loop {
        if size >= n {
            break;
        } else {
            size *= 2;
        }
    }

    let mut s_min = SegmentTree::min(size, u_max);
    let mut s_max = SegmentTree::max(size, 0);

    for i in 0..n {
        s_min.update(i, pp[i]);
        s_max.update(i, pp[i]);
    }

    let mut prev_min = s_min.query(0, k);
    let mut prev_max = s_max.query(0, k);

    let mut ans: usize = 1;
    let end = n - k + 1;
    for i in 1..end {
        let min = s_min.query(i, i + k);
        let max = s_max.query(i, i + k);

        let same_with_prev = prev_min < min && prev_max < max;
        if !same_with_prev {
            ans += 1;
        }

        prev_min = min;
        prev_max = max;
    }

    let mut already_sorted = 0;
    let mut prev = pp[0];
    let mut count = 1;

    for i in 1..n {
        if prev < pp[i] {
            count += 1;
            if count == k {
                already_sorted += 1;
            }
        } else {
            count = 1;
        }
        prev = pp[i];
    }

    let ans = if already_sorted > 0 {
        ans - already_sorted + 1
    } else {
        ans
    };
    println!("{}", ans);
}


Measured memory_bytes: 14588