n, m = gets.chomp.split.map(&:to_i)
arr = []
m.times{
    atari, hazure =  gets.chomp.split.map(&:to_i)
    arr << atari
}
arr.sort!.reverse!.pop

goods = m - 1
cost = 0
arr.each{|atari| cost += (n - atari) if n > atari}
puts cost
