#include <bits/stdc++.h>
using namespace std;
long long t, n, a, b, k, s = 0, sum = 0;
queue<long long> q;
long long y[200005];
map<long long, long long> m, l;
int main() {
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> a;
    m[a] = 1;
    l[a] = 1;
    q.push(a);
  }
  while (sum < k) {
    a = q.front();
    q.pop();
    if (m[a + 1] == 0) {
      m[a + 1] = 1;
      sum++;
      y[sum] = a + 1;
      s += l[a];
      q.push(a + 1);
      l[a + 1] = l[a] + 1;
    }
    if (sum == k) break;
    if (m[a - 1] == 0) {
      m[a - 1] = 1;
      sum++;
      y[sum] = a - 1;
      s += l[a];
      q.push(a - 1);
      l[a - 1] = l[a] + 1;
    }
  }
  cout << s << endl;
  for (int i = 1; i <= k; i++) {
    cout << y[i];
    if (i != k) cout << " ";
  }
}
