#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <cassert>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
typedef pair<int,int> PI;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mp make_pair
#define pb push_back


PI park[10][2]; //goTime,carNo;
int m,n,inpark;//ÔãÌAÔÌAÔêàÌÔÌ

queue<PI> Q;//waitTime,carNo;


//o­·éÔÌÔðÔ·B
int left(int time){
  
  rep(i,m){
    if(park[i][0].first<=time && park[i][0].first>0){
      PI ret=park[i][0];
      park[i][0]=park[i][1];//ãiÌÔðº°éB
      park[i][1]=mp(0,0);
      inpark--;
      return ret.second;
    }
  }
  //o­·éÔªÈ¯êÎ-1
  return -1;
}

//ÔðâßéB
void stop(int cometime,int wait,int no){
  int mini=-1,mint,maxi=-1,maxt;

  //·ÅÉÔÅ êÎL[ÉüêéÄ^[
  if(inpark>=2*m){
    Q.push(mp(wait,no));
    return;
  }
  
  inpark++;
  
  //êiÚªó¢Ä¢êÎ»±ÉüêÄ^[
  rep(i,m){
    if(park[i][0].first==0){
      park[i][0]=mp(cometime+wait,no);
      return;
    }
  }

  //oÉªß¢êiÚðIèB
  rep(i,m){
    if(park[i][1].first)continue;
    if((park[i][0].first<mint || mini==-1) && cometime+wait<=park[i][0].first){
      mint=park[i][0].first;
      mini=i;
    }
    if((park[i][0].first>maxt  || maxi==-1) && cometime+wait>=park[i][0].first){
      maxt=park[i][0].first;
      maxi=i;
    }
  }


  //oÉªüêéÔæèx¢àÌª êÎA»êðãiÉµÄAºiÉüÉB
  if(mini!=-1){
    park[mini][1]=park[mini][0];
    park[mini][0]=mp(cometime+wait,no);
  }else{//»¤ÅÈ¯êÎãiÉÈéÔÌÒ@ÔªêÔZ¢Æ±ëÉüÉ
    park[maxi][1]=park[maxi][0];
    park[maxi][0]=mp(cometime+wait,no);
  }
}


int main(){
  while(cin>>m>>n){
    if(m==0 && n==0)break;
    int time=0,out=0,f=0;//»ÝAoÉµ½ÔA\¦µ½©Ç¤©
    inpark=0;//»ÝÌÔ

    //Ôãú»
    rep(i,10)rep(j,2)park[i][j]=mp(0,0);


    //oÉµ½ÔªüÁÄ­éÔæè­È¢Ô[v
    while(out<n){
      ++time;


      //»ÝÉoÉ·éÔª êÎ»êð\¦B
      while(true){
        int carno=left(time);
        if(carno==-1)break;
        else{
          if(f)cout<<" ";
          cout<<carno;
          f=1;
          ++out;
        }
      }
      
      //ÔÅÈ­AÒ@Ôª éÈçÎ»êðüÉB
      while(!Q.empty() && inpark<2*m){
        int wait=Q.front().first,no=Q.front().second;
        Q.pop();
        stop(time,wait,no);
      }

      //»ÝÉ½Ôª êÎüÉB
      if(time%10==0 && time<=10*n){
        int wait;
        cin>>wait;
        stop(time,wait,time/10);
      }
    }
    cout<<endl;
  }
}