#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<pair<int, int> > H;
vector<int> Ans[1000010];
int S[1000010];
int main() {
  scanf("%d%d", &n, &m), H.resize(m);
  int tot = 0;
  for (int i = 0; i < m; i++)
    scanf("%d", &H[i].first), tot += H[i].first, H[i].second = i + 1;
  if (tot % n != 0) H[0].first += n - tot % n, tot += n - tot % n;
  int k = tot / n, tmpk = k;
  printf("%d\n", k);
  sort(H.begin(), H.end());
  int detert = 0;
  for (int cnt = 0, t = 0;; cnt++) {
    while (t != H.size() && H[t].first == 0) t++;
    if (t == H.size()) break;
    if (H.back().first >= n) {
      for (int j = detert + 1; j <= m; j++) Ans[j].push_back(H.back().second);
      H.back().first -= n;
      pair<int, int> tmp = H.back();
      for (int j = (int)H.size() - 2; j >= t - 1; j--)
        if (j != t - 1 && H[j] > tmp)
          H[j + 1] = H[j];
        else {
          H[j + 1] = tmp;
          break;
        }
      k--;
      continue;
    }
    int mn = H[t].first;
    S[++detert] = mn;
    n -= mn;
    for (int i = t, s = k; s; i++)
      if (H[i].first >= mn) {
        H[i].first -= mn;
        Ans[detert].push_back(H[i].second);
        if (!--s) break;
      }
  }
  if (n) {
    S[++detert] = n;
  }
  for (int i = 1; i <= m; i++) printf("%d ", S[i]);
  putchar('\n');
  for (int i = 0; i < tmpk; i++) {
    for (int j = 1; j <= m; j++)
      if (Ans[j].size() > i)
        printf("%d ", Ans[j][i]);
      else
        printf("1 ");
    putchar('\n');
  }
  return 0;
}
