{-
AOJ #2801
Suntan
-}
import Data.List

main = do cs0  <- getContents
          let cs1 = words cs0
	  let cs  = map (\x -> read x ::Int) cs1
          let t = head cs :: Int
          let n = head $ tail cs :: Int
          let live = group2 $ tail $ tail cs
	  -- print live
	  print $ max (interseca live t)(intersecb live t)	

group2 :: [a] -> [[a]]
group2 [] = []
group2 xs = take 2 xs : group2 (drop 2 xs)


-- ?????????[a,b]??¨[c,d]?????±??????????????????
intersecSec :: Int -> Int -> Int -> Int -> Int
intersecSec a b c d 
  | a <= c && b <= c  = 0
  | a >= d && b >= d  = 0
  | otherwise         = (head $ tail $ tail $ sort [a,b,c,d])-(head $ tail $ sort [a,b,c,d])


intersec2 :: Int -> Int -> [[Int]] -> Int
intersec2 low high list = sum (map (\x -> intersecSec low high (head x)(head $ tail x)) list)

interseca :: [[Int]] -> Int -> Int
interseca list t = maximum $ map (\x -> intersec2 (head x) ((head x)+t) list) list

intersecb :: [[Int]] -> Int -> Int
intersecb list t = maximum $ map (\x -> intersec2 ((head $ tail x)-t) (head $ tail x) list) list