using static System.Math;
using System.Linq;
using System.Collections.Generic;
using System;

public class P
{
    public int uc { get; set; }
    public int dc { get; set; }
    public int a { get; set; }
    public int ut { get; set; }
    public int dt { get; set; }
}

public class C
{
    public int c { get; set; }
    public int rt { get; set; }
}

public class hello
{
    public static void Main()
    {
        while (true)
        {
            string[] line = Console.ReadLine().Trim().Split(' ');
            var m = int.Parse(line[0]);
            var n = int.Parse(line[1]);
            if (m == 0 && n == 0) break;
            var q = new Queue<C>();
            for (int i = 0; i < n; i++)
                q.Enqueue(new C { c = i + 1, rt = int.Parse(Console.ReadLine().Trim()) });
            goSim(m, q);
        }
    }
    static void goSim(int m, Queue<C> q)
    {
        var ps = new P[m];
        var oc = new List<int>();
        for (int i = 0; i < m; i++) ps[i] = new P { };
        var q2 = new Queue<C>();
        var x = q.Dequeue();
        ps[0].a = 1; ps[0].dc = 1; ps[0].dt = x.rt;
        var t = 0;
        while (true)
        {
            if (IsEmpty(m, ps)) break;
            t++;
            outCar(m, ps, oc);
            if (t % 10 == 0 && q.Count() > 0) q2.Enqueue(q.Dequeue());
            inCar(m, ps, q2);
        }
        Console.WriteLine(string.Join(" ", oc));
    }
    static void inCar(int m, P[] ps, Queue<C> q2)
    {
        while (q2.Count() > 0)
        {
            var w = q2.Peek();
            var kt1 = 999; var ki1 = 0;
            var kt2 = 999; var ki2 = 0;
            for (int i = 0; i < m; i++)
            {
                if (ps[i].a == 0) { ps[i].a = 1; ps[i].dc = w.c; ps[i].dt = w.rt; q2.Dequeue(); goto next; }
                else if (ps[i].a == 1)
                    if (w.rt <= ps[i].dt)
                    {
                        if (Abs(w.rt - ps[i].dt) <= kt1) { kt1 = Abs(w.rt - ps[i].dt); ki1 = i; }
                    }
                    else
                    {
                        if (Abs(w.rt - ps[i].dt) <= kt2) { kt2 = Abs(w.rt - ps[i].dt); ki2 = i; }
                    }
            }
            if (kt1 != 999) { ps[ki1].uc = ps[ki1].dc; ps[ki1].ut = ps[ki1].dt; ps[ki1].dc = w.c; ps[ki1].dt = w.rt; q2.Dequeue(); ps[ki1].a = 2; }
            else if (kt2 != 999) { ps[ki2].uc = ps[ki2].dc; ps[ki2].ut = ps[ki2].dt; ps[ki2].dc = w.c; ps[ki2].dt = w.rt; q2.Dequeue(); ps[ki2].a = 2; }
            else return;
            next:;
        }
    }
    static void outCar(int m, P[] ps, List<int> oc)
    {
        for (int i = 0; i < m; i++)
        {
            if (ps[i].a == 1)
            {
                ps[i].dt--;
                if (ps[i].dt == 0) { oc.Add(ps[i].dc); ps[i].a = 0; }
            }
            else if (ps[i].a == 2)
            {
                if (ps[i].dt != 0) ps[i].dt--;
                if (ps[i].ut != 0) ps[i].ut--;
                if (ps[i].dt == 0 && ps[i].ut == 0) { oc.Add(ps[i].dc); oc.Add(ps[i].uc); ps[i].a = 0; }
                else if (ps[i].dt == 0) { oc.Add(ps[i].dc); ps[i].a = 1; ps[i].dc = ps[i].uc; ps[i].dt = ps[i].ut; }
            }
        }
    }
    static bool IsEmpty(int m, P[] ps)
    {
        for (int i = 0; i < m; i++)
            if (ps[i].a != 0) return false;
        return true;
    }
}



Measured memory_bytes: 16608