#include<fstream>
using namespace std;
ifstream f("roata.in");
ofstream g("roata.out");
short n, Last;
bool k;
int matrice[2][100001];
int p, i, j, Valoare;
long long suma = 0;
int main()
{
f >> n >> p;
for (i = 1; i <= p; i++)
{
f >> matrice[0][i];
matrice[1][i] = i;
suma += matrice[0][i];
}
g << suma << '\n';
i = n;
while (i <= p + n - 1)
{
Valoare = 100000;
for (j = 1; j <= n; j++)
{
if (matrice[0][j] < Valoare && matrice[0][j]>0)
{
Valoare = matrice[0][j];
}
}
for (j = 1; j <= n; j++)
{
if (i == p + n - 1)
Last = j;
matrice[0][j] -= Valoare;
if (matrice[0][j] ==0 && i < p)
{
g << matrice[1][j] << ' ';
matrice[0][j] = matrice[0][++i];
matrice[1][j] = matrice[1][i];
}
if (matrice[0][j] ==0 && i >= p)
{
g << matrice[1][j] << ' ';
i++;
}
}
}
g << '\n' << Last<< '\n';
/*
29
3 5 2 4 1 7 6
3
*/
}