import std.algorithm, std.conv, std.range, std.stdio, std.string; void main() { auto rd1 = readln.split.to!(int[]), n = rd1[0], m = rd1[1]; auto d = new int[](m); foreach (i; 0..m) d[i] = readln.chomp.to!int; auto d1 = d.filter!"a > 0".array.sort().array; auto d2 = d.filter!"a < 0".map!"-a".array.sort().array; if (d.canFind(0)) --n; if (n == 0) { writeln(0); return; } writeln(min(calc(n, d1, d2), calc(n, d2, d1))); } auto calc(int n, int[] a, int[] b) { if (a.length == 0) return int.max; auto r = a[n-1]; foreach (i; 1..min(a.length, n)) if (n-i < b.length) r = min(r, a[i-1] * 2 + b[n-i-1]); return r; }