#include <bits/stdc++.h>
using namespace std;
bool solve(int n, vector<int> targets, int nstep, bool print_solution = false) {
  const int m = targets.size();
  set<pair<int, int>> rest_pos;
  for (int i = 0; i < m; ++i)
    if (targets[i] > 0) rest_pos.emplace(targets[i], i);
  vector<int> group_values(m, 0);
  vector<vector<int>> attacks(m);
  for (int i = 0; i < m; ++i) {
    int group_value;
    if (i == m - 1) {
      group_value =
          n - accumulate(group_values.begin(), group_values.end() - 1, 0);
      if (group_value < 0) {
        assert(!print_solution);
        return false;
      }
    } else if (rest_pos.empty()) {
      group_value = 0;
    } else {
      auto it = rest_pos.rbegin();
      struct event_t {
        int value;
        int rest;
        int pos;
        int div_by;
        bool operator<(const event_t &o) const { return value < o.value; }
      };
      priority_queue<event_t> pq;
      int value = INT_MAX;
      int can_go = 0;
      while (can_go < nstep && (!pq.empty() || it != rest_pos.rend())) {
        if (it != rest_pos.rend()) {
          pq.push({it->first, it->first, it->second, 1});
          ++it;
        }
        event_t ev = pq.top();
        pq.pop();
        value = ev.value;
        ++can_go;
        int next_value = ev.rest / (ev.div_by + 1);
        if (next_value > 0) {
          pq.push({next_value, ev.rest, ev.pos, ev.div_by + 1});
        }
      }
      if (can_go < nstep) {
        group_value = 0;
      } else {
        group_value = value;
      }
    }
    group_values[i] = group_value;
    for (int rep = 0; rep < nstep; ++rep) {
      if (rest_pos.empty()) break;
      pair<int, int> last = *rest_pos.rbegin();
      rest_pos.erase(last);
      last.first -= group_value;
      attacks[i].push_back(last.second);
      if (last.first > 0) rest_pos.insert(last);
    }
  }
  if (!rest_pos.empty()) {
    assert(!print_solution);
    return false;
  }
  if (print_solution) {
    printf("%d\n", nstep);
    for (int i = 0; i < m; ++i) {
      if (i > 0) printf(" ");
      printf("%d", group_values[i]);
    }
    printf("\n");
    for (int j = 0; j < nstep; ++j) {
      for (int i = 0; i < m; ++i) {
        if (i > 0) printf(" ");
        printf("%d", j < (int)attacks[i].size() ? attacks[i][j] + 1 : 1);
      }
      printf("\n");
    }
  }
  return true;
}
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  vector<int> targets(m);
  for (int i = 0; i < m; ++i) scanf("%d", &targets[i]);
  const int tsum = accumulate(targets.begin(), targets.end(), 0);
  int left = (tsum + (n - 1)) / n, right = left + (int)1e6;
  for (int k = 0; k < 10; ++k)
    if (solve(n, targets, left + k)) {
      left = right = left + k;
      break;
    }
  while (left < right) {
    int mid = left + (right - left) / 2;
    if (solve(n, targets, mid)) {
      right = mid;
    } else {
      left = mid + 1;
    }
  }
  solve(n, targets, left, true);
  return 0;
}
