import qualified Data.Text.Lazy as T
import qualified Data.Text.Lazy.IO as T
import qualified Data.Text.Lazy.Read as T
import Data.Bits

main :: IO ()
main = do
  let
    m = 300000 :: Int
  [n, k] <- map unsafeTextToInt . T.words <$> T.getLine :: IO [Int]
  let
    f :: [Int] -> (Int, Tree)
    f = foldl step st0
      where
        step :: (Int, Tree) -> Int -> (Int, Tree)
        step st x = modify st x (y + 1)
          where
            y = query st (max 0 (x - k), min m (x + k) + 1) :: Int
        st0 = fromList . replicate (m + 1) $ 0 :: (Int, Tree)
  as <- map unsafeTextToInt . T.lines <$> T.getContents :: IO [Int]
  print . extract . snd . f $ as

data Tree = Node Int (Maybe (Int, Tree), Maybe (Int, Tree)) deriving (Eq, Show)

extract :: Tree -> Int
extract (Node x _) = x

unsafeLeft :: Tree -> (Int, Tree)
unsafeLeft (Node _ (Just t, _)) = t

unsafeRight :: Tree -> (Int, Tree)
unsafeRight (Node _ (_, Just t)) = t

singleton :: Int -> (Int, Tree)
singleton = (,) 1 . flip Node (Nothing, Nothing)

fromList :: [Int] -> (Int, Tree)
fromList = rec . map singleton
  where
    rec :: [(Int, Tree)] -> (Int, Tree)
    rec ts@(_ : _ : _) = rec . pair $ ts
      where
        pair :: [(Int, Tree)] -> [(Int, Tree)]
        pair (st@(s, t) : st'@(s', t') : ts) = (s + s', Node (extract t `max` extract t') (Just st, Just st')) : pair ts
        pair (st@(s, t) : _) = [(s, Node (extract t) (Just st, Nothing))]
        pair _ = []
    rec ts = head ts

modify :: (Int, Tree) -> Int -> Int -> (Int, Tree)
modify (1, Node x lr) _ d = (1, Node (x `max` d) lr)
modify (n, Node x (Just sl@(s, l), r)) i d | i < s = (n, Node (x `max` d) (Just (modify sl i d), r))
modify (n, Node x (l, Just sr@(s, r))) i d = (n, Node (x `max` d) (l, Just (modify sr (i - n + s) d)))

query :: (Int, Tree) -> (Int, Int) -> Int
query (n, t) (i, j) | i == 0 && n <= j = extract t
                    | j <= s           = query sl (i, j)
                    | s <= i           = query (n - s, r) (i - s, j - s)
                    | otherwise        = query sl (i, s) `max` query (n - s, r) (0, j - s)
  where
    sl@(s, l) = unsafeLeft t :: (Int, Tree)
    (_, r) = unsafeRight t :: (Int, Tree)

leftSize :: Int -> Int
leftSize n = flip shiftR 1 . bit $ finiteBitSize n - countLeadingZeros (n - 1)

unsafeTextToInt :: T.Text -> Int
unsafeTextToInt s = case T.signed T.decimal s of
  Right (n, _) -> n
{-# INLINE unsafeTextToInt #-}
