#include <iostream>
#include <vector>
#include <set>
#include <queue>
using namespace std;

typedef pair<int, int> P;
const int INF = 1000000000;

int M, N;
vector<int> t;

bool input() {
  cin >> M >> N;
  if (!M && !N) {
    return false;
  }
  t.resize(N);
  for (int i = 0; i < N; ++i) {
    cin >> t[i];
  }
  return true;
}

bool exec_tyusha(int time, int car_id, vector<P> &park, vector<int> &space, const vector<int> &shukko_time) {
  for (int i = 0; i < M; ++i) {
    if (park[i].first == -1 && park[i].second == -1) {
      park[i].second = car_id;
      space[car_id] = 2 * i + 1;
      return true;
    }
  }
  int my_shukko_time = time + t[car_id];
  int min_d = INF;
  int min_id = -1;
  bool machi_flag = true;
  for (int i = 0; i < M; ++i) {
    if (park[i].first != -1 && park[i].second != -1) {
      continue;
    }
    int d = shukko_time[park[i].second] - my_shukko_time;
    if (d > 0) {
      if (machi_flag) {
        min_d = d;
        min_id = i;
        machi_flag = false;
      } else {
        if (min_d > d) {
          min_d = d;
          min_id = i;
        }
      }
    } else {
      if (min_d > -d) {
        min_d = -d;
        min_id = i;
      }
    }
  }
  if (min_id != 1) {
    park[min_id].first = car_id;
    space[car_id] = 2 * min_id;
    return true;
  }
  return false;
}

void solve() {
  vector<P> park;
  vector<int> space;
  vector<int> answer;
  priority_queue<P, vector<P>, greater<P> > tyusha;
  priority_queue<P, vector<P>, greater<P> > shukko;
  vector<int> shukko_time;
  queue<int> tyusha_machi;
  set<int> shukko_machi;
  park.resize(M);
  space.resize(N);
  shukko_time.resize(N);
  for (int i = 0; i < M; ++i) {
    park[i].first = park[i].second = -1;
  }
  for (int i = 0; i < N; ++i) {
    tyusha.push(P(i * 10, i));
  }

  priority_queue<P, vector<P>, greater<P> > shukko_buf;
  while (!tyusha.empty() || !shukko.empty()) {
    int st = INF;
    int tt = INF;
    if (!shukko.empty()) {
      st = shukko.top().first;
    }
    if (!tyusha.empty()) {
      tt = tyusha.top().first;
    }
    if (st < tt) {
      while (!shukko.empty() && shukko.top().first == st) {
        int id = shukko.top().second;
        shukko_buf.push(P(space[id], id));
        shukko.pop();
      }
      while (!shukko_buf.empty()) {
        int space_id = shukko_buf.top().first >> 1;
        bool is_second = shukko_buf.top().first & 1;
        int car_id = shukko_buf.top().second;
        shukko_buf.pop();
        if (is_second) {
          if (park[space_id].first == -1) {
            answer.push_back(car_id);
            park[space_id].second = -1;
          } else {
            shukko_machi.insert(car_id);
          }
        } else {  // first floor
          answer.push_back(car_id);
          park[space_id].first = -1;
          if (shukko_machi.find(park[space_id].second) != shukko_machi.end()) {
            answer.push_back(park[space_id].second);
            park[space_id].second = -1;
            shukko_machi.erase(car_id);
          }
        }
      }
      while (!tyusha_machi.empty()) {
        int car_id = tyusha_machi.front();
        bool success = exec_tyusha(st, car_id, park, space, shukko_time);
        if (success) {
          tyusha_machi.pop();
          shukko_time[car_id] = st + t[car_id];
          shukko.push(P(shukko_time[car_id], car_id));
        } else {
          break;
        }
      }
    } else {
      int car_id = tyusha.top().second;
      tyusha.pop();
      bool success = exec_tyusha(tt, car_id, park, space, shukko_time);
      if (success) {
        shukko_time[car_id] = tt + t[car_id];
        shukko.push(P(shukko_time[car_id], car_id));
      } else {
        tyusha_machi.push(car_id);
      }
    }
  }

  for (int i = 0; i < N; ++i) {
    if (i) cout << " ";
    cout << answer[i] + 1;
  }
  cout << endl;
}

int main() {
  while (input()) {
    solve();
  }
  return 0;
}