#include <bits/stdc++.h>
using namespace std;
int M = 1e9 + 7;
int dd = 33;
int sp[3000001];
int max(int x, int y) {
  if (x > y) return x;
  return y;
}
int power(int x, int y) {
  if (y == 0) return 1;
  int t = power(x, y / 2);
  t = ((t) * (t));
  if (y % 2 == 1) t = ((t) * (x));
  return t;
}
int min(int x, int y) {
  if (x < y) return x;
  return y;
}
int dfs(vector<int> tree[], int n, int s, int p, int dp[]) {
  int c = 0;
  int i;
  int mx = 0;
  for (i = 0; i < tree[s].size(); i++) {
    if (tree[s][i] != p) {
      int f = 0;
      f = dfs(tree, n, tree[s][i], s, dp);
      c += f;
      mx = max(mx, f);
    }
  }
  mx = max(mx, n - c - 1);
  c++;
  dp[s] = mx;
  return c;
}
int check(vector<int>& v1, vector<int>& v2, int ind, int m) {
  int x = v2[0] - v1[ind];
  if (x < 0) x += m;
  int t = ind;
  for (int i = 0; i < v2.size(); i++) {
    int d = v2[i] - v1[t];
    if (d < 0) d += m;
    if (d != x) return -1;
    t++;
    t = t % (v1.size());
  }
  return x;
}
void output() {
  int n, m;
  cin >> n >> m;
  int a[n], i;
  map<int, bool> mpp;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    mpp[a[i]] = true;
  }
  vector<int> b;
  priority_queue<pair<int, int>, vector<pair<int, int> >,
                 greater<pair<int, int> > >
      pq;
  for (i = 0; i < n; i++) {
    pq.push(make_pair(1, a[i] - 1));
    pq.push(make_pair(1, a[i] + 1));
  }
  long long s = 0;
  while (!pq.empty() && b.size() != m) {
    pair<int, int> p = pq.top();
    pq.pop();
    if (mpp[p.second]) continue;
    s += ((long long)p.first);
    mpp[p.second] = true;
    b.push_back(p.second);
    if (p.first + 1 > m) continue;
    if (mpp[p.second + 1] == false)
      pq.push(make_pair(p.first + 1, p.second + 1));
    if (mpp[p.second - 1] == false)
      pq.push(make_pair(p.first + 1, p.second - 1));
  }
  cout << s << endl;
  sort(b.begin(), b.end());
  for (i = 0; i < b.size(); i++) cout << b[i] << " ";
  cout << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  t = 1;
  int i;
  while (t--) output();
}
