#include <bits/stdc++.h>
using namespace std;
long long maxi = LLONG_MIN;
long long mini = LLONG_MAX;
void fast() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
long long t, i, j, k, n, temp, flag, ans, m;
int main() {
  int n, m;
  cin >> n >> m;
  vector<long long> x(n + 1, 0);
  queue<int> q;
  for (int i = 1; i <= n; i++) {
    cin >> x[i];
    q.push(x[i]);
  }
  int i = 1;
  vector<long long> ans;
  map<int, int> ma;
  while (!q.empty() && i <= n + m) {
    int x = q.front();
    q.pop();
    if (ma[x] != 1) {
      ans.push_back(x);
      ma[x] = 1;
      q.push(x + 1);
      q.push(x - 1);
      i++;
    }
  }
  sort(ans.begin(), ans.end());
  sort(x.begin() + 1, x.end());
  vector<long long> ans2;
  int l = 0;
  for (int i = 1; i <= n; i++) {
    while (ans[l] != x[i]) {
      ans2.push_back(ans[l]);
      l++;
    }
    l++;
  }
  while (l < n + m) {
    ans2.push_back(ans[l]);
    l++;
  }
  long long res = 0, lb, ub = x[1], poi = 1;
  ;
  int mark = -1;
  for (int i = 0; i < m; i++) {
    if (ans2[i] < x[1]) {
      res += (x[1] - ans2[i]);
      lb = x[1];
    } else if (ans2[i] > lb && ans2[i] < ub) {
      res += min(ub - ans2[i], ans2[i] - lb);
    } else {
      poi++;
      if (poi > n) {
        mark = i;
        break;
      }
      lb = ub;
      ub = x[poi];
      i--;
    }
  }
  if (mark != -1) {
    for (int i = mark; i < m; i++) {
      res += (ans2[i] - x[n]);
    }
  }
  cout << res << "\n";
  for (int i = 0; i < ans2.size(); i++) {
    cout << ans2[i] << " ";
  }
  return 0;
}
