INF = 10 ** 9 n,m = gets.split.map(&:to_i) d = m.times.map { gets.to_i } d.push(0) a = d.select {|v| v >= 0 }.sort b = d.select {|v| v <= 0 }.map {|v| v.abs }.sort dp = Array.new(n+1,INF) (0..n).each do |i| j = n - i if i < a.size && j < b.size dp[i] = a[i] < b[j] ? a[i] * 2 + b[j] : a[i] + b[j] * 2 end end puts dp.min