#include <bits/stdc++.h>
using namespace std;
int n, m, a[1000010], b[1000010], tmp[1000010], pos[1000010];
vector<int> K;
int sum = 0;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d", &a[i]);
    sum += a[i];
  }
  printf("%d\n", (sum + n - 1) / n);
  copy(a + 1, a + 1 + n, b + 1);
  for (int i = 1; i <= m; i++) {
    if (b[i] < 0) {
      K.push_back(K.back() + a[i]);
      b[i + 1] += b[i];
    } else {
      b[i] %= n;
      K.push_back(b[i]);
      b[i + 1] -= n - b[i];
    }
  }
  K.back() = n;
  sort(K.begin(), K.end());
  for (int i = 0; i < K.size(); i++) pos[K[i]] = i;
  for (int i = K.size() - 1; i > 0; i--) K[i] -= K[i - 1];
  for (int x : K) printf("%d ", x);
  puts("");
  for (int i = 1; i <= m; i++) {
    while (a[i] >= n) {
      for (int j = 0; j < m; j++) printf("%d ", i);
      puts("");
      a[i] -= n;
    }
    int j = i;
    if (a[i]) {
      int hh = n - a[i];
      while (j < m && a[j + 1] <= hh) hh -= a[++j];
      a[j + 1] -= hh;
      hh = 0;
      int last = 0;
      for (int k = i; k <= j; k++) {
        hh += a[k];
        if (k == m) hh = n;
        for (int l = last; l <= pos[hh]; l++) tmp[l] = k;
        last = pos[hh] + 1;
      }
      for (int k = last; k < m; k++) tmp[k] = min(j + 1, m);
      for (int j = 0; j < m; j++) printf("%d ", tmp[j]);
      puts("");
    }
    i = j;
  }
}
