#include<iostream>
#include<vector>
#include<queue>
#include<cmath>
#include<cstdlib>
using namespace std;

const int infty = 1<<26;

struct Car{
  int id;
  int reserve;
};

struct ParkingSystem{
  int num;
  int id[2];
  int till[2];

  ParkingSystem(){
    num = 0;
    id[0]=id[1]=-1;
    till[0]=till[1]=-1;
  }
  
  int Out(int t){
    if(num==0)return -1;
    int ret = -1;
    if(num==1&&t>=till[0]){
      id[1]=-1;
      till[1]=-1;
      ret = id[0];
      till[0]=-1;
      id[0]=-1;
      num=0;
      return ret;
    }
    if(num==2&&t>=till[0] ){
      num=1;
      ret=id[0];
      till[0] = till[1];
      id[0] = id[1];
      till[1] = -1;
      id[1] = -1;
      return ret;
    }
    return -1;
  }

  void Park(int t, Car c){ // num <= 1
    if( num == 0 ){
      num = 1;
      id[0] = c.id;
      till[0] = t+c.reserve;
    }else{
      num = 2;
      id[1] = id[0];
      till[1] = till[0];
      id[0] = c.id;
      till[0] = t+c.reserve;
    }
  }
  
  int leftTime(int t){ // num == 1
    if( num == 0 ) return 0;
    else{
      return abs(till[0] - t);
    }
  }
  
};

struct TsurugaParking{
  TsurugaParking(){}
  TsurugaParking(int m):vps(m){}
  vector< ParkingSystem > vps;
  queue< Car > q;
  void Add(Car c){
    q.push(c);
  }
  void Park(int t){
    while( !q.empty() ){
      bool next_car = false;
      bool existSpace = false;

      for(int i = 0; i < vps.size(); ++i){
	if( vps[i].num < 2 ){
	  existSpace = true;
	}
      }
      if(!existSpace) break;

      Car c = q.front();
      q.pop();

      for(int i = 0; i < vps.size(); ++i){
	if( vps[i].num == 0 ){
	  vps[i].Park(t,c);
	  next_car = true;
	  break;
	}
      }
      if( next_car )continue;

      int at = -1;
      int minimum = infty;
      for(int i = 0; i < vps.size(); ++i){
	if( vps[i].num == 1 ){
	  if( vps[i].leftTime(t) >= c.reserve ){
	    int tt = vps[i].leftTime(t) - c.reserve;
	    if( tt < minimum ){
	      minimum = tt;
	      at = i;
	    }
	  }
	}
      }
      if( at != -1 ){
	vps[at].Park( t, c );
	continue;
      }

      at = -1;
      minimum = infty;
      for(int i = 0; i < vps.size(); ++i){
	if( vps[i].num == 1 ){
	  if( vps[i].leftTime(t) < c.reserve ){
	    int tt = c.reserve - vps[i].leftTime(t);
	    if( tt < minimum ){
	      minimum = tt;
	      at = i;
	    }
	  }
	}
      }
      if( at != -1 ){
	vps[at].Park( t, c );
	continue;
      }
    }
  }
  void Out(int t, vector<int> &out){
    for(int i = 0; i < vps.size(); ++i){
      while( true ){
	int s = vps[i].Out( t );
	if( s == -1 ) break;
	out.push_back( s );
      }
    }
  }
  bool isEmpty(){
    for(int i = 0; i < vps.size(); ++i){
      if( vps[i].num > 0 )return false;
    }
    return true;
  }
};

int main()
{
  while(true){
    vector<int> ans;
    queue<Car> qc;
    int t = 0;
    int m,n;
    cin >> m >> n;
    if( m == 0 && n == 0 ) break;
    for(int i = 0; i < n; ++i){
      Car c;
      c.id= i+1;
      cin >> c.reserve;
      qc.push(c);
    }
    TsurugaParking tp(m);
    
    while(true){
      tp.Out(t,ans);
      if( t % 10 == 0 && !qc.empty() ){
	tp.Add( qc.front() );
	qc.pop();
      }
      tp.Park(t);
      ++t;
      if( tp.isEmpty() && qc.empty() ) break;
    }
    for(int i = 0; i < ans.size(); ++i){
      if( i > 0 ) cout << ' ';
      cout << ans[i];
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 0