#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


struct Info{
    int length;
};

struct Data{
    Data(){
        car_id = time = 0;
    }

    Data(int arg_time,int arg_car_id){
        time = arg_time;
        car_id = arg_car_id;
    }
    int car_id,time;
};

struct PARK{
    int floor_1,floor_2,out_1,out_2;
};

int M,N;
bool is_out[15000];

void func(){

    Info info[N];
    PARK park[M];
    bool is_FULL;

    for(int i = 0; i < 15000; i++)is_out[i] = false;

    for(int i = 0; i < M; i++){
        park[i].floor_1 = -1;
        park[i].floor_2 = -1;
        park[i].out_1 = 200;
        park[i].out_2 = 200;
    }

    queue<Data> IN_Q;

    int tmp;
    for(int i = 0; i < N; i++){
        scanf("%d",&tmp);
        info[i].length = tmp;
        IN_Q.push(Data(10*i,i));
    }

    Data current;
    bool FLG;

    int min_index,minimum;

    is_FULL = false;

    int now_time = 0,out_num = 0;

    vector<int> ANS;

    while(out_num < N){

       if(is_out[now_time]){
            for(int i = 0; i < M; i++){
                if(park[i].floor_1 != -1 && park[i].out_1 <= now_time){

                    ANS.push_back(park[i].floor_1);
                    park[i].floor_1 = -1;
                    out_num++;

                    if(park[i].floor_2 != -1 && park[i].out_2 <= now_time){
                        ANS.push_back(park[i].floor_2);
                        park[i].floor_2 = -1;
                        out_num++;
                    }else{
                        park[i].floor_1 = park[i].floor_2;
                        park[i].out_1 = park[i].out_2;
                        park[i].floor_2 = -1;
                    }
                }
            }
        }

       if(out_num == N)break;

        while(IN_Q.empty() == false && IN_Q.front().time <= now_time && is_FULL == false){

            current = IN_Q.front();

            FLG = false;

            for(int i = 0; i < M; i++){
                if(park[i].floor_1 == -1){
                    park[i].floor_1 = current.car_id;
                    park[i].out_1 = now_time + info[current.car_id].length;
                    is_out[park[i].out_1] = true;
                    IN_Q.pop();
                    FLG = true;
                    break;
                }
            }
            if(FLG)continue;

            minimum = BIG_NUM;
            for(int i = 0; i < M; i++){
                if(park[i].floor_2 != -1)continue;
                if(park[i].out_1 >= now_time+info[current.car_id].length){
                    tmp = park[i].out_1 - (now_time+info[current.car_id].length);
                    if(tmp < minimum){
                        minimum = tmp;
                        min_index = i;
                    }
                }
            }

            if(minimum != BIG_NUM){
                park[min_index].floor_2 = park[min_index].floor_1;
                park[min_index].out_2 = park[min_index].out_1;
                park[min_index].floor_1 = current.car_id;
                park[min_index].out_1 = now_time + info[current.car_id].length;
                is_out[park[min_index].out_1] = true;
                IN_Q.pop();
                continue;
            }

            for(int i = 0; i < M; i++){
                if(park[i].floor_2 != -1)continue;
                if(park[i].out_1 < now_time+info[current.car_id].length){
                    tmp = now_time+info[current.car_id].length - park[i].out_1;
                    if(tmp < minimum){
                        minimum = tmp;
                        min_index = i;
                    }
                }
            }

            if(minimum != BIG_NUM){
                park[min_index].floor_2 = park[min_index].floor_1;
                park[min_index].out_2 = park[min_index].out_1;
                park[min_index].floor_1 = current.car_id;
                park[min_index].out_1 = now_time + info[current.car_id].length;
                is_out[park[min_index].out_1] = true;
                IN_Q.pop();
                continue;
            }

            is_FULL = true;
        }
        now_time++;
    }

    printf("%d",ANS[0]+1);
    for(int i = 1; i < ANS.size(); i++){
        printf(" %d",ANS[i]+1);
    }
    printf("\n");
}

int main(){

    while(true){
        scanf("%d %d",&M,&N);
        if(M == 0 && N == 0)break;

        func();
    }

    return 0;
}