#include <bits/stdc++.h>
using namespace std;
const int OO = 1e9;
const long long INF = 1e18;
const int irand(int lo, int hi) {
  return ((double)rand() / (RAND_MAX + 1.0)) * (hi - lo + 1) + lo;
}
const long long lrand(long long lo, long long hi) {
  return ((double)rand() / (RAND_MAX + 1.0)) * (hi - lo + 1) + lo;
}
template <typename T>
T getnum() {
  int sign = 1;
  T ret = 0;
  char c;
  do {
    c = getchar();
  } while (c == ' ' || c == '\n');
  if (c == '-')
    sign = -1;
  else
    ret = c - '0';
  while (1) {
    c = getchar();
    if (c < '0' || c > '9') break;
    ret = 10 * ret + c - '0';
  }
  return sign * ret;
}
inline void ini(int& x) { x = getnum<int>(); }
inline void scani(int& x) { scanf("%d", &x); }
const int N = 1e6 + 5;
int n, m;
priority_queue<pair<int, int> > pq;
int v[N];
vector<int> atk[N];
bool cek(int x, int turns) {
  priority_queue<pair<int, int> > tpq = pq;
  while (!pq.empty()) {
    pair<int, int> t = pq.top();
    pq.pop();
    turns -= t.first / x;
    if (turns <= 0) break;
  }
  pq = tpq;
  return turns <= 0;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout.setf(ios::fixed);
  cout.setf(ios::showpoint);
  cout.precision(10);
  cin >> n >> m;
  int sum = 0;
  for (int i = 1; i <= m; i += 1) {
    int x;
    cin >> x;
    pq.push(make_pair(x, i));
    sum += x;
  }
  int turns = sum / n;
  if (sum % n) turns++;
  if (n <= m) {
    for (int i = 1; i <= m; i += 1) {
      if (i > n) {
        atk[i].resize(turns, 1);
        continue;
      }
      v[i] = 1;
      for (int j = 1; j <= turns; j += 1) {
        if (pq.empty())
          atk[i].push_back(1);
        else {
          pair<int, int> t = pq.top();
          pq.pop();
          atk[i].push_back(t.second);
          t.first--;
          pq.push(t);
        }
      }
    }
  } else {
    for (int i = 1; i <= m; i += 1) {
      if (i == m) {
        v[i] = n;
        n = 0;
        for (int j = 1; j <= turns; j += 1) {
          if (pq.empty())
            atk[i].push_back(1);
          else {
            pair<int, int> t = pq.top();
            pq.pop();
            atk[i].push_back(t.second);
            t.first -= v[i];
            if (t.first > 0) pq.push(t);
          }
        }
      } else if (turns > pq.size()) {
        int lo = 1, hi = OO, ans = 0;
        while (lo <= hi) {
          int mid = (lo + hi) / 2;
          if (cek(mid, turns)) {
            ans = mid;
            lo = mid + 1;
          } else {
            hi = mid - 1;
          }
        }
        if (ans == 0) {
          v[i] = n;
          n = 0;
        } else {
          v[i] = ans;
          n -= ans;
        }
        for (int j = 1; j <= turns; j += 1) {
          if (pq.empty())
            atk[i].push_back(1);
          else {
            pair<int, int> t = pq.top();
            pq.pop();
            atk[i].push_back(t.second);
            t.first -= v[i];
            if (t.first > 0) pq.push(t);
          }
        }
      } else {
        vector<pair<int, int> > vec;
        int mn = OO;
        for (int j = 1; j <= turns; j += 1) {
          vec.push_back(pq.top());
          mn = min(mn, pq.top().first);
          pq.pop();
        }
        assert(mn <= n);
        n -= mn;
        v[i] = mn;
        for (int j = 0; j < vec.size(); j++) {
          atk[i].push_back(vec[j].second);
          vec[j].first -= mn;
          if (vec[j].first > 0) {
            pq.push(vec[j]);
          }
        }
      }
    }
  }
  for (int i = 1; i <= m; i += 1) {
    while (atk[i].size() < turns) atk[i].push_back(1);
  }
  cout << turns << '\n';
  for (int i = 1; i <= m; i += 1) cout << v[i] << " ";
  cout << '\n';
  for (int i = 0; i < turns; i++) {
    for (int j = 1; j <= m; j += 1) cout << atk[j][i] << " ";
    cout << '\n';
  }
  return 0;
}
