#include <bits/stdc++.h>
using namespace std;
int read() {
  int f = 1, x = 0;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -f;
    c = getchar();
  }
  while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
  return f * x;
}
int n, m, a[1000005], ss[1000005];
int ans[3000005];
void init() {
  n = read(), m = read();
  int sum = 0;
  for (int i = 1; i <= m; ++i) a[i] = read();
  for (int i = 1; i <= m; ++i) sum += a[i], ss[i] = sum % n;
  ss[m] = n;
  sort(ss + 1, ss + m + 1);
}
void solve() {
  for (int i = m; i >= 2; --i) ss[i] -= ss[i - 1];
  int cur = 1, rd = 0;
  for (; cur <= m; ++rd) {
    for (int i = 1; i <= m; ++i) {
      if (cur > m) {
        ans[rd * n + i - 1] = m;
        continue;
      }
      if (ss[i] >= a[cur]) {
        ans[rd * n + i - 1] = cur;
        cur++;
      } else {
        ans[rd * n + i - 1] = cur;
        a[cur] -= ss[i];
      }
    }
  }
  printf("%d\n", rd);
  for (int i = 1; i < m; ++i) printf("%d ", ss[i]);
  printf("%d\n", ss[m]);
  for (int i = 0; i < rd; ++i) {
    for (int j = 0; j < m - 1; ++j) printf("%d ", ans[i * n + j]);
    printf("%d\n", ans[i * n + m - 1]);
  }
}
int main() {
  init();
  solve();
  return 0;
}
