#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cassert>
#include<climits>
#include<vector>
#include<algorithm>
#include<deque>
 
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define IINF (INT_MAX)
#define MAX 20
 
using namespace std;
 
typedef pair<int,int> ii;
 
int n,m;// n : the number of the space
deque<int> car,TIME;
deque<int> space[MAX];// tyusya space
deque<int> Index[MAX];
deque<ii> waiting;
vector<int> ANS; 
 
bool Insert1(int cindex,int cTIME){
  rep(i,n){
    if(space[i].size() >= 2)continue;
    if(space[i].empty()){
      space[i].push_back(cTIME);
      Index[i].push_back(cindex);
      return true;
    }
  }
  return false;
}
 
bool Insert2(int cindex,int ctime,int cTIME){
  int pos = -1;
  bool found = false;
  rep(i,n){
    assert(!space[i].empty());
    if(space[i].size() >= 2)continue;
    int remain = space[i].front() - ctime;
    assert(remain>=0);
    //if(remain < cTIME)continue;
    if(remain >= cTIME)found = true;
    else continue;
    if(pos == -1)pos = i;
    else {
      if( abs((space[ i ].front()-ctime)-cTIME) < 
      abs((space[pos].front()-ctime)-cTIME) ){
    pos = i;
      }
    }
  }
 
  if(pos == -1 || !found)return false;
 
  space[pos].push_front(ctime+cTIME);
  Index[pos].push_front(cindex);
  return true;
}
 
bool Insert3(int cindex,int ctime,int cTIME){
  int pos = -1;
 
  rep(i,n){
    assert(!space[i].empty());
    if(space[i].size() >= 2)continue;
    int remain = space[i].front() - ctime;
    assert(remain>=0);
    if(remain >= cTIME){
      return false;
    }
 
    if(pos == -1)pos = i;
    else {
      if( abs((space[ i ].front()-ctime)-cTIME) < 
	  abs((space[pos].front()-ctime)-cTIME) ){
	pos = i;
      }
    }
  }
 
  if(pos == -1)return false;
 
  space[pos].push_front(ctime+cTIME);
  Index[pos].push_front(cindex);
  return true;
}
 
 
void compute(){
  int ctime = 0;
  while(true){
 
    // out
    rep(i,n)while(!space[i].empty() && space[i].front() <= ctime){
      ANS.push_back(Index[i].front());
      space[i].pop_front(), Index[i].pop_front();
    }
 
    // IN
 
 
    if(!car.empty() && ctime%10 == 0){
      waiting.push_back(ii(car.front(),TIME.front()));
      car.pop_front(),TIME.pop_front();
    }
 
 
    while(true){
      deque<ii> next;
      deque<ii> tmp = waiting;
      while(!waiting.empty()){
    int cindex = waiting.front().first;
    int cTIME  = waiting.front().second; 
    waiting.pop_front();
     
    if(Insert1(cindex,cTIME+ctime)){
      continue;
    }
     
    if(Insert2(cindex,ctime,cTIME)){
      continue;
    }
    if(Insert3(cindex,ctime,cTIME)){
      continue;
    }
    // it cannot be possible to insert the car
    next.push_back(ii(cindex,cTIME));
     
      }
 
      waiting = next;
      if(tmp == next)break;
      if(waiting.empty())break;
    }
 
    bool finish = true;
    rep(i,n)if(!space[i].empty()){
      finish = false;
      break;
    }
 
    if(car.empty() && finish){
      assert(waiting.empty());
      break;
    }
 
    ctime += 1;
 
  }
}
 
int main(){
 
  while(cin >> n >> m,n|m){
    waiting.clear(), ANS.clear(), TIME.clear(),car.clear();
    rep(i,MAX)space[i].clear(),Index[i].clear();
 
    rep(i,m){
      int tm;
      cin >> tm;
      car.push_back(i);
      TIME.push_back(tm);
    }
 
 
 
    compute();
 
    rep(i,ANS.size()){
      if(i)cout << " ";
      cout << ANS[i]+1;
    } cout << endl;
 
  }
 
  return 0;
}

Measured memory_bytes: 1256