l, n = gets.split.map(&:to_i)
trees = n.times.map { gets.to_i }

steps = 0
current = 0
until trees.empty?
  tree = [trees.first, trees.last].max { |first, last| f <=> l - last }
  steps += (tree - current).abs
  current = tree
  trees.delete(tree)
end

puts steps