#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 7;
long long a[maxn];
long long b[maxn];
long long ans[maxn];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> a[i];
  sort(a + 1, a + 1 + n);
  a[0] = a[1] - m - m;
  a[n + 1] = a[n] + m + m;
  vector<pair<long long, long long> > v(n);
  for (int i = 0; i < n; i++) {
    v[i] = make_pair(a[i + 1], a[i + 1]);
  }
  int cnt = 0;
  long long dis = 1;
  long long now = 0;
  long long sum = 0;
  while (cnt < m) {
    int k = 0;
    now++;
    for (int i = 0; i < n; i++) {
      bool flag = 0;
      if (i - 1 < 0) {
        v[i].first -= dis;
        sum += now;
        if (dis > 0) ans[cnt++] = v[i].first;
        if (cnt >= m) break;
      } else {
        long long p = v[i].first - dis;
        if (p == v[i - 1].second) {
          flag = 1;
        } else {
          v[i].first -= dis;
          sum += now;
          if (dis > 0) ans[cnt++] = v[i].first;
          if (cnt >= m) break;
        }
      }
      if (i + 1 >= n) {
        v[i].second += dis;
        sum += now;
        if (dis > 0) ans[cnt++] = v[i].second;
        if (cnt >= m) break;
      } else {
        long long p = v[i].second + dis;
        if (p < v[i + 1].first) {
          v[i].second += dis;
          sum += now;
          if (dis > 0) ans[cnt++] = v[i].second;
          if (cnt >= m) break;
        }
      }
      if (flag == 0) {
        v[k] = v[i];
        k++;
      } else {
        v[k - 1].second = v[i].second;
      }
    }
    n = k;
    n = max(1, n);
  }
  cout << sum << endl;
  for (int i = 0; i < m; i++) cout << ans[i] << ' ';
  cout << endl;
  return 0;
}
