#include <bits/stdc++.h>
using namespace std;
int sum(long long a) {
  int sum = 0;
  while (a > 0) {
    sum = sum + (a % 10);
    a = a / 10;
  }
  return sum;
}
int count_digit(long long n) {
  int count = 0;
  while (n > 0) {
    n = n / 10;
    count++;
  }
  return count;
}
int binarySearch(int x, int y, long long z, long long v[]) {
  int low = x;
  int high = y;
  int mid = x + (y - x) / 2;
  while (low <= high) {
    if (v[mid] == z) return mid;
    if (v[mid] < z) return binarySearch(mid + 1, high, z, v);
    if (v[mid] > z) return binarySearch(low, mid - 1, z, v);
  }
  return -1;
}
long long modularExponentiation(long long x, long long n, long long M) {
  if (n == 0)
    return 1;
  else if (n % 2 == 0)
    return modularExponentiation((x * x) % M, n / 2, M);
  else
    return (x * modularExponentiation((x * x) % M, (n - 1) / 2, M)) % M;
}
long long binaryExponentiation(long long x, long long n) {
  if (n == 0)
    return 1;
  else if (n % 2 == 0)
    return binaryExponentiation(x * x, n / 2);
  else
    return x * binaryExponentiation(x * x, (n - 1) / 2);
}
set<long long> s;
void genrate(long long n, int len, int max) {
  if (len > max) return;
  s.insert(n);
  genrate(n * 10 + 1, len + 1, max);
  genrate(n * 10 + 0, len + 1, max);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int tests = 1;
  while (tests--) {
    int n, m;
    cin >> n >> m;
    vector<long long> v(n);
    for (int i = 0; i < v.size(); i++) {
      cin >> v[i];
    }
    sort((v).begin(), (v).end());
    queue<pair<long long, long long>> Q;
    set<long long> s;
    for (int i = 0; i < v.size(); i++) {
      s.insert(v[i]);
      Q.push({v[i], 0});
    }
    long long res = 1;
    long long final = 0;
    vector<long long> ans;
    while (ans.size() < m) {
      int x = Q.size();
      for (int i = 0; i < x; i++) {
        if (ans.size() == m) break;
        pair<long long, long long> y = Q.front();
        Q.pop();
        if (y.second != 0) {
          ans.push_back(y.first);
          final = final + y.second;
        }
        if (s.find(y.first - 1) == s.end()) {
          s.insert(y.first - 1);
          Q.push({y.first - 1, y.second + 1});
        }
        if (s.find(y.first + 1) == s.end()) {
          s.insert(y.first + 1);
          Q.push({y.first + 1, y.second + 1});
        }
      }
    }
    cout << final << '\n';
    for (int i = 0; i < ans.size(); i++) cout << ans[i] << " ";
  }
}
