n, r = gets.split.map &:to_i
res = (1..r).map{ gets.split.map(&:to_i) }.sort_by(&:last) + [[n+1, n+1]]
hash ={nil => 0}
until res.empty?
	poster, prior = res.shift
	new_hash = Hash.new(Float::INFINITY)
	
	hash.each{|min, cost|
		min = poster if !min || poster < min 
		new_hash[min] = cost if cost < new_hash[min]
		c = cost + (prior - min) * 2
		new_hash[nil] = c if c < new_hash[nil]
	}
	hash = new_hash
end
p hash[nil] + n + 1