#include <bits/stdc++.h>
using namespace std;
void debug(int* a, int n, bool flag = false) {
  if (!flag) printf("array ");
  for (int i = 1; i <= n; i++) printf("%d ", a[i]);
  printf("\n");
}
void debug(vector<int>& E, bool flag = false) {
  if (!flag) printf("vector ");
  for (auto it : E) printf("%d ", it);
  printf("\n");
}
const int maxn = 2e5 + 5;
int a[maxn];
set<pair<int, int> > s;
int n, m;
map<int, bool> Map;
vector<int> res;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    Map[a[i]] = true;
    s.insert(make_pair(i, -1));
    s.insert(make_pair(i, 1));
  }
  sort(a + 1, a + 1 + n);
  long long ans = 0;
  long long k = 1;
  while (m) {
    auto it = s.begin();
    while (it != s.end()) {
      long long val = a[it->first] + k * it->second;
      if (!Map.count(val)) {
        res.push_back(val);
        ans += k;
        it++;
        m--;
        Map[val] = true;
        if (!m) break;
      } else
        s.erase(it++);
    }
    k++;
  }
  printf("%I64d\n", ans);
  debug(res, true);
  return 0;
}
