import Data.List
import qualified Data.ByteString.Char8 as B
import Data.Ord
import Control.Monad

main :: IO ()
main = breads >>= main'
    where
        main' [n, m] = replicateM m breads >>= print . solve . sortBy cmpf . concatMap mf
        mf [a, b] = [(a, A), (b, B)]
        cmpf (x, tx) (y, ty) = compare x y `mappend` compare tx ty

solve :: [(Int, Tag)] -> Int
solve = fst . foldl' ff (0, A)
    where
        ff (acc, A) (_, B) = (acc + 1, B)
        ff (acc, _) (_, t) = (acc, t)

data Tag = A | B
    deriving (Show, Eq)

instance Ord Tag where
    compare A B = GT
    compare B A = LT 
    compare _ _ = EQ

breads :: IO [Int]
breads = unfoldr uff <$> B.getLine
    where
        uff b = check <$> B.readInt b
        check (a, b)
            | B.null b = (a, b)
            | otherwise = (a, B.tail b)