import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine
toTuple (x : y : _) = (x, y)

main = do
    [n, m] <- getIntList
    lrs <- map toTuple <$> replicateM m getIntList
    let (x, y) = foldl solve (1, n) lrs
    print $ max 0 (y - x + 1)

solve (l, r) (l', r') = (max l l', min r r')