#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
using ll = long long;
using ld = long double;
ll mod = 998244353;
ll gcd(ll a, ll b) {
  if (a == 0 or b == 0) return a + b;
  return gcd(b, a % b);
}
ll sum(ll a, ll b) {
  a += b;
  a %= mod;
  return a;
}
ll sub(ll a, ll b) {
  a += mod - b;
  a %= mod;
  return a;
}
inline ll mul(ll a, ll b) {
  if (a * b < mod) return a * b;
  return a * b % mod;
}
inline ll pew(ll a, ll b) {
  ll res = 1;
  while (b) {
    if (b & 1) res = mul(res, a);
    a = mul(a, a);
    b /= 2;
  }
  return res;
}
int parent[600001];
int rnk[600001];
int suk[600001];
void make_set(int v) {
  parent[v] = v;
  rnk[v] = 0;
  suk[v] = 0;
}
int find_set(int v) {
  if (v == parent[v]) return v;
  return parent[v] = find_set(parent[v]);
}
void union_sets(int a, int b) {
  a = find_set(a);
  b = find_set(b);
  if (a != b and (suk[a] * suk[b] == 0)) {
    if (rnk[a] < rnk[b]) swap(a, b);
    parent[b] = a;
    if (rnk[a] == rnk[b]) ++rnk[a];
    suk[a] += suk[b];
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  ll m, n;
  cin >> n >> m;
  ll sum = 0;
  vector<ll> kek(m), cur(m);
  for (int i = 0; i < m; i++) {
    cin >> kek[i];
    cur[i] = kek[i];
    sum += kek[i];
  }
  ll k = sum / n;
  if (sum % n != 0) k++;
  vector<vector<ll>> tar(m);
  vector<ll> sz(m);
  ll was = 0;
  for (int i = 0; i < m; i++) {
    while (cur[i] >= n - was) {
      cur[i] -= n - was;
      was = 0;
    }
    if (i != m - 1)
      sz[i] = was + cur[i];
    else
      sz[i] = n;
    was = sz[i];
  }
  sort(sz.begin(), sz.end());
  for (int j = m - 1; j > 0; j--) {
    sz[j] -= sz[j - 1];
  }
  ll pos = 0;
  for (int i = 0; i < m; i++) {
    while (true) {
      while (pos < m and (kek[i] >= sz[pos] or i + 1 == m)) {
        tar[pos].push_back(i + 1);
        kek[i] -= sz[pos];
        pos++;
      }
      if (kek[i] <= 0) break;
      pos = 0;
    }
  }
  cout << k << "\n";
  for (int i = 0; i < m; i++) {
    cout << sz[i] << " ";
  }
  cout << "\n";
  for (int i = 0; i < k; i++) {
    for (int j = 0; j < m; j++) {
      cout << tar[j][i] << " ";
    }
    cout << "\n";
  }
}
