#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>

using namespace std;

#define INF (1<<29)

struct Parking{
  int t1, t2; // t1 = bottom, t2 = top
  int car1, car2;
  int n;
  
  Parking() : t1(0), t2(0), car1(-1), car2(-1), n(0){}
};

int main(){
  int n, m;
  while(cin >> m >> n, m|n){
    vector<Parking> P(m);
    
    for(int i = 0 ; i < m ; i++){
      P[i].car1 = P[i].car2 = -1;
      P[i].t1 = P[i].t2 = 0;
    }
    
    vector<int> ans;
    
    int t;
    for(int CAR = 0 ; CAR < n ; CAR++){      
      // exit
      for(int i = 0 ; i < m ; i++){
	if(P[i].car1 != -1) P[i].t1 -= 10;
	if(P[i].car2 != -1) P[i].t2 -= 10;
      }
      
      while(true){
	int Mintime1 = INF, pos1 = -1, car1 = -1; // bottom
	
	for(int i = 0 ; i < m ; i++){
	  if(Mintime1 > P[i].t1 && P[i].car1 != -1){
	    Mintime1 = P[i].t1;
	    pos1 = i;
	    car1 = P[i].car1;
	  }
	  
	  else if( (Mintime1 > P[i].t2 && P[i].car2 != -1) && P[i].car1 == -1 ){
	    Mintime1 = P[i].t2;
	    pos1 = i;
	    car1 = P[i].car2;
	  }
	  
	  /*
	  if(Mintime2 > P[i].t2){
	    Mintime2 = P[i].t2;
	    pos2 = i;
	    car2 = P[i].car2;
	  }
	  */  
	}
	
	if(Mintime1 == INF) break;
	
	bool flag = false;
	
	// leave car
	if(Mintime1 <= 0){
	  flag = true;
	  
	  if(P[pos1].car1 != -1){
	    ans.push_back(P[pos1].car1);
	    
	    P[pos1].n = max(P[pos1].n-1, 0);
	    
	    P[pos1].t1 = 0;
	    P[pos1].car1 = -1;
	    
	    if(P[pos1].t2 <= 0 && P[pos1].car2 != -1){
	      ans.push_back(P[pos1].car2);
	      
	      P[pos1].n = max(P[pos1].n-1, 0);
	      
	      P[pos1].t2 = 0;
	      P[pos1].car2 = -1;
	    }	  
	  }
	  
	  else{
	    ans.push_back(P[pos1].car2);
	    
	    P[pos1].n = max(P[pos1].n-1, 0);
	    
	    P[pos1].t2 = 0;
	    P[pos1].car2 = -1;	    
	  }
	  
	}
	
	if(!flag) break; // while 10 minutes, no exit car
      }
      
      bool f = false;
      for(int i = 0 ; i < m ; i++){
	if(P[i].n != 2){
	  f = true;
	  break;
	}
      }
      
      // not empty parking area
      if(!f){
	//cout << "came" << endl;
	
	int Mintime = INF;
	int pos, car;
	
	for(int i = 0 ; i < m ; i++){
	  if(Mintime > P[i].t1 && P[i].car1 != -1){
	    Mintime = P[i].t1;
	    pos = i;
	    car = P[i].car1;
	  }
	  
	  else if( (Mintime > P[i].t2 && P[i].car2 != -1) && P[i].car1 == -1 ){
	    Mintime = P[i].t2;
	    pos = i;
	    car = P[i].car2;
	  }
	} 
	
	//if(Mintime == INF) break;
	
	for(int j = 0 ; j < m ; j++){
	  P[j].t1 -= Mintime;
	  if(P[j].t1 < 0) P[j].t1 = 0;
	  P[j].t2 -= Mintime;
	  if(P[j].t2 < 0) P[j].t2 = 0;
	}
	
	if(P[pos].n == 2 && P[pos].car2 <= P[pos].car1){
	  int tmp1, tmp2;
	  tmp1 = P[pos].car1;
	  tmp2 = P[pos].car2;
	  //if(tmp1 > tmp2) swap(tmp1, tmp2);
	  ans.push_back(tmp1);
	  ans.push_back(tmp2);
	  P[pos].n = 0;
	  
	  P[pos].car1 = P[pos].car2 = -1;
	  P[pos].t1 = P[pos].t2 = 0;
	  
	  goto END2;
	}
	
	ans.push_back(car);
	
	if(P[pos].car1 != -1){	
	  P[pos].t1 = 0;
	  P[pos].car1 = -1;
	  P[pos].n = max(P[pos].n-1, 0);
	}
	else{
	  P[pos].t1 = 0;
	  P[pos].car1 = -1;
	  P[pos].n = max(P[pos].n-1, 0);
	  
	  P[pos].t2 = 0;
	  P[pos].car2 = -1;
	  P[pos].n = max(P[pos].n-1, 0);
	}
      }

    END2:;
      
      int index = -1;
      int diff = INF;
      
      // in          
      cin >> t;

      // parfect empty parking area
      for(int i = 0 ; i < m ; i++){
	if( P[i].n == 0 ){
	  P[i].t1 = t;
	  P[i].car1 = CAR;
	  P[i].n++;
	  goto END;
	}
      }
      
      // one empty parking area

      for(int i = 0 ; i < m ; i++){
	if(P[i].n == 1){
	  if(P[i].car1 != -1){
	    if(diff > abs(P[i].t1 - t)){
	      diff = abs(P[i].t1 - t);
	      index = i;
	    }
	  }
	  else if(P[i].car2 != -1){
	    if(diff > abs(P[i].t2 - t)){
	      diff = abs(P[i].t2 - t);
	      index = i;
	    }
	  }
	}	
      }
      
      for(int i = 0 ; i < m ; i++){
	if(i != index) continue;
	
	if( P[i].n == 1 ){
	  P[i].n++;
	  if(P[i].t2 > 0){
	    P[i].t1 = t;
	    P[i].car1 = CAR;
	    goto END;
	  }
	  if(P[i].t1 > 0){
	    P[i].t2 = P[i].t1;
	    P[i].car2 = P[i].car1;
	    
	    P[i].t1 = t;
	    P[i].car1 = CAR;
	    goto END;
	  }
	}
      }
     
    END:;
      
      
      /*
      for(int i = 0 ; i < m ; i++){
	printf("%d : bottom = %d, t1 = %d | top = %d, t2 = %d\n", i+1, P[i].car1+1, P[i].t1, P[i].car2+1, P[i].t2);
	//cout << i+1 << " : bottom = " << P[i].car1 << ", top = " << P[i].car2 << endl;
      }
      cout << endl;
      */

    }
    
    while(true){
      int Mintime = INF;
      int pos, car;
      
      for(int i = 0 ; i < m ; i++){
	if(Mintime > P[i].t1 && P[i].car1 != -1){
	  Mintime = P[i].t1;
	  pos = i;
	  car = P[i].car1;
	}
	
	else if( (Mintime > P[i].t2 && P[i].car2 != -1) && P[i].car1 == -1 ){
	  Mintime = P[i].t2;
	  pos = i;
	  car = P[i].car2;
	}
      } 
      
      if(Mintime == INF) break;
      
      
      for(int j = 0 ; j < m ; j++){
	P[j].t1 -= Mintime;
	if(P[j].t1 < 0) P[j].t1 = 0;
	P[j].t2 -= Mintime;
	if(P[j].t2 < 0) P[j].t2 = 0;
      }
      
      if(P[pos].n == 2 && P[pos].car2 <= P[pos].car1){
	int tmp1, tmp2;
	tmp1 = P[pos].car1;
	tmp2 = P[pos].car2;
	//if(tmp1 > tmp2) swap(tmp1, tmp2);
	ans.push_back(tmp1);
	ans.push_back(tmp2);
	P[pos].n = 0;
	
	P[pos].car1 = P[pos].car2 = -1;
	P[pos].t1 = P[pos].t2 = 0;
	
	continue;
      }
      
      
      ans.push_back(car);
      
      if(P[pos].car1 != -1){	
	P[pos].t1 = 0;
	P[pos].car1 = -1;
	P[pos].n = max(P[pos].n-1, 0);
      }
      else{
	P[pos].t2 = 0;
	P[pos].car2 = -1;
	P[pos].n = max(P[pos].n-1, 0);
      }
    }
    
    for(int i = 0 ; i < ans.size() ; i++){
      cout << ans[i]+1;
      if(i != ans.size()-1) cout << ' ';
    }
    cout << endl;
  }
  return 0;
}