#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 6;
const int INF = 1e9 + 4;
struct mang {
  int x, y, z;
};
mang b[N];
bool cmp(mang A1, mang B1) { return A1.z < B1.z; }
map<int, int> cnt;
int n, k, a[N], sl, f[10000][5005], ans;
vector<int> c;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> k >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  sort(a + 1, a + n + 1);
  for (int i = 2; i <= n; i++) {
    b[i - 1].x = a[i];
    b[i - 1].y = a[i - 1];
    b[i - 1].z = a[i] - a[i - 1];
  }
  sort(b + 1, b + n, cmp);
  for (int i = 1; i <= 2 * k && i <= n - 1; i++) {
    if (binary_search(c.begin(), c.end(), b[i].x) == false) {
      c.push_back(b[i].x);
    }
    if (binary_search(c.begin(), c.end(), b[i].y) == false) {
      c.push_back(b[i].y);
    }
  }
  sort(c.begin(), c.end());
  for (int i = 0; i < c.size(); i++) cout << c[i] << " ";
  return 0;
  ans = INF;
  for (int i = 0; i <= 4 * k && i <= n; i++)
    for (int j = 0; j <= k; j++)
      if (j == 0)
        f[i][j] = 0;
      else
        f[i][j] = INF;
  for (int i = 2; i <= 4 * k && i <= n; i++)
    for (int j = 1; j <= k && j * 2 <= i; j++) {
      f[i][j] = min(f[i - 2][j - 1] + abs(c[i - 1] - c[i - 2]), f[i - 1][j]);
      if (j == k) ans = min(ans, f[i][j]);
    }
  cout << ans;
  return 0;
}
