#include <bits/stdc++.h>
using namespace std;
int hps[1000111];
bool isSplits[1000111];
int a[1000111];
int n, m;
int ans;
int countAndStick() {
  int rez = 0;
  int remain = 0;
  for (int i = 1; i <= m; i++) {
    if (remain >= hps[i]) {
      remain -= hps[i];
      if (i < m) {
        isSplits[n - remain] = true;
      }
      continue;
    }
    int existHp = hps[i] - remain;
    rez = rez + existHp / n;
    remain = n - (existHp % n);
    if (remain == n) remain = 0;
    if (remain > 0) rez++;
    if (i < m) {
      isSplits[n - remain] = true;
    }
  }
  isSplits[n] = true;
  return rez;
}
void split() {
  for (int i = 1; i <= n; i++) a[i] = 0;
  int index = 0;
  int j = 0;
  for (int i = 1; i <= n; i++) {
    if (isSplits[i] == true) {
      j++;
      a[j] = i - index;
      index = i;
    }
  }
}
int attack(int idGroup) {
  for (int i = 1; i <= m; i++) {
    if (idGroup > m) {
      printf("%d", m);
    } else {
      printf("%d", idGroup);
      hps[idGroup] -= a[i];
      if (hps[idGroup] == 0) {
        idGroup++;
      }
    }
    if (i < m)
      printf(" ");
    else
      printf("\n");
  }
  return idGroup;
}
int main() {
  if (0 == 1) {
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
  }
  cin >> n >> m;
  for (int i = 0; i <= n; i++) isSplits[i] = false;
  for (int i = 1; i <= m; i++) cin >> hps[i];
  ans = countAndStick();
  split();
  cout << ans << endl;
  for (int i = 1; i <= m; i++) {
    cout << a[i];
    if (i < m)
      cout << " ";
    else
      cout << endl;
  }
  int idGroup = 1;
  for (int i = 1; i <= ans; i++) {
    idGroup = attack(idGroup);
  }
}
