#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;

void func(){

	Info info[N];
	PARK park[M];
	bool is_FULL,is_out[1200];

	for(int i = 0; i < 1200; 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 = BIG_NUM;
		park[i].out_2 = BIG_NUM;
	}

	queue<Data> IN_Q;

	int tmp;
	for(int i = 1; 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].out_1 <= now_time){

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

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

		while(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; //2??????????????????????????°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]);
	for(int i = 1; i < ANS.size(); i++){
		printf(" %d",ANS[i]);
	}
	printf("\n");
}

int main(){

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

		func();
	}

	return 0;
}