#include <bits/stdc++.h>
using namespace std;
template <typename T>
using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
const int INF = 1 << 29;
const long long INFL = 1LL << 60;
const long long mod = 1000000007;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  long long dst = 0;
  map<int, int> mm;
  queue<pair<int, int>> q;
  for (int i = 0; i < int(n); i++) {
    int a;
    cin >> a;
    mm[a] = 1;
    q.push({a, 1});
  }
  vector<int> ans;
  while (true) {
    while (!q.empty()) {
      int a = q.front().first;
      int cur = q.front().second;
      q.pop();
      if (mm[a + 1] == 0) {
        mm[a + 1] = 1;
        ans.push_back(a + 1);
        m--;
        dst += cur;
        q.push({a + 1, cur + 1});
        if (m == 0) {
          cout << dst << endl;
          for (int j : ans) {
            cout << j << ' ';
          }
          return 0;
        }
      }
      if (mm[a - 1] == 0) {
        mm[a - 1] = 1;
        ans.push_back(a - 1);
        m--;
        dst += cur;
        q.push({a - 1, cur + 1});
        if (m == 0) {
          cout << dst << endl;
          for (int j : ans) {
            cout << j << ' ';
          }
          return 0;
        }
      }
    }
  }
  return 0;
}
