package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
	"strings"

)


func main() {
	solve(os.Stdin, os.Stdout)
}

type ReaderEx struct {
	baseScanner *bufio.Scanner
	words       []string
	nextWordIdx func() int
	initWordIdx func(int)
}

func NewScannerEx(stdin io.Reader) *ReaderEx {
	var this ReaderEx
	var idx int
	var wordsCnt int
	this.baseScanner = bufio.NewScanner(stdin)
	this.baseScanner.Buffer(make([]byte, 0), 1E+11)
	this.nextWordIdx = func() int {
		cur := idx
		idx = (idx + 1) % wordsCnt
		return cur
	}
	this.initWordIdx = func(wc int) {
		idx = 0
		wordsCnt = wc
	}
	return &this
}

func (me *ReaderEx) Scan(doSplit bool) (isScanned bool) {
	isScanned = me.baseScanner.Scan()
	if doSplit {
		me.words = strings.Fields(me.baseScanner.Text())
	} else {
		me.words = []string{me.baseScanner.Text()}
	}
	me.initWordIdx(len(me.words))
	return
}

func (me *ReaderEx) nextBytes() []byte {
	return []byte(me.words[me.nextWordIdx()])
}
func (me *ReaderEx) nextString() string {
	return me.words[me.nextWordIdx()]
}

type StringArray []string

func (me *ReaderEx) nextStringArray() StringArray {
	return me.words[me.nextWordIdx():]
}

func (me StringArray) toStrings() []string {
	return me
}

func (me StringArray) toInts() []int {
	strValues := me.toStrings()
	values := make([]int, len(strValues))
	for i, v := range strValues {
		n, err := strconv.Atoi(v)
		if err != nil {
			panic(err)
		}
		values[i] = n
	}
	return values
}
func (me *ReaderEx) nextInt() int {
	n, err := strconv.Atoi(me.words[me.nextWordIdx()])

	defer func() {
		if err != nil {
			panic(fmt.Sprintf("getInt(%d)", n))
		}
	}()
	return n
}

func pow(x, y, mod int) (ans int) {

	ans = 1
	for bit := 1 << uint(math.Floor(math.Log2(float64(y)))); ; bit >>= 1 {
		if y&bit != 0 {
			ans *= x
			if mod > 0 {
				ans %= mod
			}
		}
		if bit <= 1 {
			return
		}
		ans *= ans
		if mod > 0 {
			ans %= mod
		}
	}
}

type factType struct {
	prime int
	count int
}

func fact(n int) (facts []*factType) {

	for i := 2; i*i <= n; i++ {
		if n%i == 0 {
			fa := factType{prime: i}
			for n%fa.prime == 0 {
				n /= fa.prime
				fa.count++
			}
			facts = append(facts, &fa)
		}
	}
	if n > 1 {
		facts = append(facts, &factType{prime: n, count: 1})
	}
	return facts
}
func dec2bin(n int) (ret []bool) {
	for bit := 1 << uint(math.Floor(math.Log2(float64(n)))); ; bit >>= 1 {
		ret = append(ret, n&bit != 0)

		if bit <= 1 {
			return
		}
	}

}

func abs(v int) int {
	if v < 0 {
		v = -v
	}
	return v
}

func b2i(b bool) (i int) {
	if b {
		i = 1
	} else {
		i = 0
	}
	return
}

//RBNodeDir is
type RBNodeDir int

const (

	//RBNodeLeft 左方向
	RBNodeLeft RBNodeDir = iota

	//RBNodeRight 右方向
	RBNodeRight

	//RBNodeHere ここ
	RBNodeHere
)

//RBNode is
type RBNode struct {
	isRed    bool
	Index    int
	parent   *RBNode
	children [2]*RBNode
}

//RBCursor is
type RBCursor struct {
	Node *RBNode
	less func(i int, j int) bool
}

//NewTree is
func NewTree(less func(i int, j int) bool) *RBCursor {
	tree := &RBCursor{less: less}
	return tree
}

//Clone is
func (cur *RBCursor) Clone() *RBCursor {
	wrk := *cur
	return &wrk
}

//Root is
func (cur *RBCursor) Root() *RBCursor {

	if cur.Node != nil {
		for ; cur.Node.parent != nil; cur.Node = cur.Node.parent {

		}
	}
	return cur
}

//Move is
func (cur *RBCursor) Move(dir RBNodeDir) *RBCursor {
	rev := dir ^ 1
	if next := cur.Node.children[dir]; next != nil {
		for next.children[rev] != nil {
			next = next.children[rev]
		}
		cur.Node = next
	} else {
		find := false
		for cur.Node.parent != nil {
			now := cur.Node
			cur.Node = cur.Node.parent
			if cur.Node.children[rev] == now {
				find = true
				break
			}
		}
		if !find {
			cur.Node = nil
		}
	}
	return cur
}

//Find is
func (cur *RBCursor) Find(Index int) (*RBCursor, RBNodeDir) {
	dir := RBNodeHere
	if cur.Node == nil {
		return cur, dir
	}
	cur.Root()
	for {
		if cur.less(Index, cur.Node.Index) {
			dir = RBNodeLeft
			next := cur.Node.children[dir]
			if next == nil {
				break
			}
			cur.Node = next

		} else if cur.less(cur.Node.Index, Index) {
			dir = RBNodeRight
			next := cur.Node.children[dir]
			if next == nil {
				break
			}
			cur.Node = next
		} else {
			dir = RBNodeHere
			break
		}
	}
	return cur, dir
}

//Add is
func (cur *RBCursor) Add(Index int) *RBCursor {
	newNode := &RBNode{Index: Index, isRed: true}
	cur.Root()
	if cur.Node != nil {
		pnode, dir := cur.Find(newNode.Index)
		if dir != RBNodeHere {
			newNode.parent = pnode.Node
			newNode.parent.children[dir] = newNode

			wrk := cur.Clone()
			wrk.Node = newNode
			wrk.opt()
		} else {
			pnode.Node.Index = newNode.Index
			newNode = pnode.Node
		}
	}
	cur.Node = newNode
	return cur
}

func (Node *RBNode) flip(dir RBNodeDir) {
	curGranPa := Node.parent
	newParent := Node.children[dir]
	if curGranPa != nil {
		curGranPa.children[Node.dir()] = newParent
	}
	newParent.parent, Node.parent = Node.parent, newParent

	Node.children[dir] = newParent.children[dir^1]
	if Node.children[dir] != nil {
		Node.children[dir].parent = Node
	}
	newParent.children[dir^1] = Node

}
func (Node *RBNode) dir() RBNodeDir {
	dir := RBNodeLeft
	if Node.parent.children[dir] != Node {
		dir = RBNodeRight
	}
	return dir
}
func (cur *RBCursor) opt() {
	Node := cur.Node
	for Node != nil && Node.isRed {
		parent := Node.parent
		if parent == nil {
			break
		} else if !parent.isRed {
			break
		} else if parent.parent == nil {
			parent.isRed = false
		} else {
			grandparent := parent.parent
			parentsibiling := grandparent.children[parent.dir()^1]
			if parentsibiling != nil && parentsibiling.isRed {
				grandparent.isRed = true
				parent.isRed = false
				parentsibiling.isRed = false
				Node = grandparent
			} else {
				dir := parent.dir()

				if parent.children[dir] != Node {
					parent.flip(dir ^ 1)
				}

				grandparent.flip(dir)
				grandparent.parent.isRed = false
				grandparent.isRed = true
				break
			}
		}
	}
}

//End is
func (cur *RBCursor) End(dir RBNodeDir) *RBCursor {
	cur.Root()
	if cur.Node != nil {
		for ; cur.Node.children[dir] != nil; cur.Node = cur.Node.children[dir] {

		}
	}
	return cur
}

func (Node *RBNode) cut() {
	Node.parent.children[Node.dir()] = nil
	Node.parent = nil
}

//Delete is
func (cur *RBCursor) Delete(Index int) (ret bool) {
	cur = cur.Root().Clone()
	cur, dir := cur.Find(Index)
	delNode := cur.Node
	if delNode == nil || dir != RBNodeHere {
		return
	}
	ret = true

	dir = RBNodeLeft
	if delNode.children[dir] == nil {
		dir = RBNodeRight
		if delNode.children[dir] == nil {
			dir = RBNodeHere
		}
	}

	if delNode.children[RBNodeLeft] != nil &&
		delNode.children[RBNodeRight] != nil {
		var wrk *RBCursor
		if dir != RBNodeHere {
			wrk = cur.Clone().Move(dir)
			delNode.Index = wrk.Node.Index
			delNode = wrk.Node
			dir = RBNodeLeft
			if delNode.children[dir] == nil {
				dir = RBNodeRight
				if delNode.children[dir] == nil {
					dir = RBNodeHere
				}
			}
		}
	}

	if dir == RBNodeHere {
		if delNode.isRed {
			delNode.cut()
			return
		}
	} else {
		wrk := delNode.children[dir]
		delNode.Index = wrk.Index
		wrk.cut()
		return
	}

	Node := delNode
	for {
		parent := Node.parent
		if parent == nil {
			break
		}

		dir := Node.dir()
		dirOther := dir ^ 1
		sibiling := parent.children[dirOther]

		if sibiling.isRed {
			parent.flip(dirOther)
			sibiling.isRed = false
			parent.isRed = true
			sibiling = parent.children[dirOther]
		}
		//sibiling is Black

		grandChild := sibiling.children[dirOther]
		if grandChild == nil || !grandChild.isRed {
			//far grand child is Black
			grandChild = sibiling.children[dir]
			if grandChild == nil || !grandChild.isRed {
				//near grand child is Black
				sibiling.isRed = true
				if parent.isRed {
					parent.isRed = false
					break
				} else {
					Node = parent
					continue
				}
			}
			sibiling.flip(dir)
			sibiling, grandChild = grandChild, sibiling
			sibiling.isRed = false
			grandChild.isRed = true
		}
		//sibiling is Black && far grandChild is Red

		saveColor := parent.isRed
		parent.flip(dirOther)
		sibiling.isRed = saveColor
		parent.isRed = false
		grandChild.isRed = false
		break

	}
	delNode.cut()
	return
}

func solve(stdin io.Reader, stdout io.Writer) {

	r := NewScannerEx(stdin)
	r.Scan(true)
	_, k := r.nextInt(), r.nextInt()
	r.Scan(true)
	p := r.nextStringArray().toInts()

	t := NewTree(func(a, b int) bool {
		return p[a] < p[b]
	})

	for i := 0; i < k; i++ {
		t.Add(i)
	}

	cnt := 0
	same := 0
	presame := false
	for i, endi := 0, len(p)-1; i < endi; i++ {
		if p[i] < p[i+1] {
			cnt++
		}
		if i-(k-1) >= 0 {
			if p[i-(k-1)] < p[i-(k-2)] {
				cnt--
			}
		}
		if cnt == k-1 {
			if !presame {
				same++
				presame = true
			}
		} else {
			presame = false
		}
	}

	if same > 0 {
		same--
	}
	ans := 1
	for i, end := 0, len(p)-k; i < end; i++ {
		cmp1 := t.End(RBNodeLeft).Node.Index == i
		t.Delete(i)
		t.Add(i + k)
		cmp2 := t.End(RBNodeRight).Node.Index == i+k
		if !(cmp1 && cmp2) {
			ans++
		}
	}
	fmt.Fprintln(stdout, ans-same)
}


Measured memory_bytes: 12032