l,n = gets.chomp.split(" ").map(&:to_i)
sumMove = 0
treePoses = []
n.times do
	treePoses << gets.to_i
end
nowPos = 0
loop do
  break if treePoses.count == 0
  lastIndex = treePoses.count - 1
  reverseMove = treePoses[0] - nowPos
  move = l - treePoses[lastIndex] + nowPos
  deleteIndex = 0
  tempData = 0
  if reverseMove > move 
    tempData += reverseMove
    deleteIndex = 0
  else
    tempData += move
    deleteIndex = lastIndex
  end
  puts tempData
  sumMove += tempData
  nowPos = treePoses[deleteIndex]
  treePoses.slice!(deleteIndex)
end
puts sumMove