#include <bits/stdc++.h>
using namespace std;
int n, m, hp[1000010], tmphp[1000010], group_cut[1000010], s[1000010],
    a[1000010];
pair<int, int> groups[1000010];
void display(int v[]) {
  for (int i = 1; i <= m; i++) {
    printf("%d%c", v[i], i == m ? '\n' : ' ');
  }
}
int main() {
  while (scanf("%d%d", &n, &m) > 0) {
    int total_hp = 0;
    for (int i = 1; i <= m; i++) {
      scanf("%d", &hp[i]);
      total_hp += hp[i];
    }
    int t = total_hp % n ? total_hp / n + 1 : total_hp / n;
    printf("%d\n", t);
    for (int i = 1; i <= m; i++) {
      tmphp[i] = hp[i];
    }
    for (int i = 1; i <= n; i++) {
      group_cut[i] = 0;
    }
    int group_id = 1;
    int i = 1;
    while (i < m) {
      while (hp[i] >= n) {
        hp[i] -= n;
      }
      if (hp[i] == 0) {
        i++;
        continue;
      }
      int sumhp = hp[i];
      if (!group_cut[sumhp]) {
        group_cut[sumhp] = group_id++;
      }
      hp[i] = 0;
      int j = i + 1;
      while (j < m and hp[j] <= n - sumhp) {
        sumhp += hp[j];
        if (!group_cut[sumhp]) {
          group_cut[sumhp] = group_id++;
        }
        hp[j] = 0;
        j++;
      }
      hp[j] -= n - sumhp;
      i = j;
    }
    int sumcut = 0;
    for (int i = 1; i <= n; i++) {
      if (group_cut[i]) {
        s[group_cut[i]] = i - sumcut;
        sumcut = i;
      }
    }
    while (group_id <= m) {
      s[group_id++] = n - sumcut;
      sumcut = n;
    }
    for (int i = 1, j = 0; i <= n; i++) {
      if (group_cut[i]) {
        groups[j++] = make_pair(i, group_cut[i]);
      }
    }
    display(s);
    for (int i = 1; i <= m; i++) {
      hp[i] = tmphp[i];
    }
    i = 1;
    while (i < m) {
      while (hp[i] >= n) {
        hp[i] -= n;
        for (int j = 1; j <= m; j++) a[j] = i;
        display(a);
      }
      if (hp[i] == 0) {
        i++;
        continue;
      }
      for (int k = 1; k <= m; k++) {
        a[k] = 0;
      }
      int sumhp = hp[i], k = 0;
      while (groups[k].first < sumhp) {
        a[groups[k++].second] = i;
      }
      a[groups[k++].second] = i;
      hp[i] = 0;
      int j = i + 1;
      while (j < m and hp[j] <= n - sumhp) {
        sumhp += hp[j];
        while (groups[k].first < sumhp) {
          a[groups[k++].second] = j;
        }
        a[groups[k++].second] = j;
        hp[j] = 0;
        j++;
      }
      hp[j] -= n - sumhp;
      for (int k = 1; k <= m; k++) {
        if (!a[k]) a[k] = j;
      }
      display(a);
      i = j;
    }
    while (hp[m] > 0) {
      hp[m] -= n;
      for (int k = 1; k <= m; k++) {
        a[k] = m;
      }
      display(a);
    }
  }
}
