#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <tuple>
#include <memory>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cfloat>
#include <cassert>
#include <random>
#include <set>

struct Parking {
	int car_id, out_time;
};
struct Car {
	int id, duration;
};
class Park {
	std::vector<std::vector<Parking>> space;
	bool has_empty_space() const {
		return std::any_of(space.begin(), space.end(), [](const std::vector<Parking>& vec) {return vec.empty(); });
	}
	void push_to_empty_space(int time, Car car) {
		std::find_if(space.begin(), space.end(), [](const std::vector<Parking>& vec) {return vec.empty(); })->push_back(Parking{ car.id, time + car.duration });
	}
	bool has_second_space() const {
		return std::any_of(space.begin(), space.end(), [](const std::vector<Parking>& vec) {return vec.size() == 1; });
	}
	bool has_over_time(int out_time) const {
		return std::any_of(space.begin(), space.end(), [out_time](const std::vector<Parking>& vec) {return vec.size() == 1 && vec.back().out_time >= out_time; });
	}
	void push_to_second_space(int time, Car car) {
		const auto out_time = time + car.duration;
		if (has_over_time(out_time)) {
			auto min = std::min_element(space.begin(), space.end(), [out_time](const std::vector<Parking>& a, const std::vector<Parking>& b) {return ((a.size() != 1 || a.back().out_time < out_time) ? INT_MAX : a.back().out_time) < ((b.size() != 1 || b.back().out_time < out_time) ? INT_MAX : b.back().out_time); });
			min->push_back(Parking{ car.id, out_time });
		}
		else {
			auto max = std::max_element(space.begin(), space.end(), [](const std::vector<Parking>& a, const std::vector<Parking>& b) {return (a.size() != 1 ? INT_MIN : a.back().out_time) < (b.size() != 1 ? INT_MIN : b.back().out_time); });
			max->push_back(Parking{ car.id, out_time });
		}
	}

public:
	Park(int size) : space(size) {};
	int park_count() const {
		return std::accumulate(space.begin(), space.end(), 0, [](int acc, const std::vector<Parking>& vec) {return acc + vec.size(); });
	}
	int next_out() const {
		if (park_count() == 0) return INT_MAX;
		return std::min_element(space.begin(), space.end(), [](const std::vector<Parking>& a, const std::vector<Parking>& b) {return (a.empty() ? INT_MAX : a.back().out_time) < (b.empty() ? INT_MAX : b.back().out_time); })->back().out_time;
	}
	int pop_car() {
		auto min = std::min_element(space.begin(), space.end(), [](const std::vector<Parking>& a, const std::vector<Parking>& b) {return (a.empty() ? INT_MAX : a.back().out_time) < (b.empty() ? INT_MAX : b.back().out_time); });
		const auto result = min->back();
		min->pop_back();
		if (!min->empty()) min->back().out_time = std::max(min->back().out_time, result.out_time);
		return result.car_id;
	}
	bool has_space() const {
		return has_empty_space() || has_second_space();
	}
	void park_car(int time, Car car) {
		if (has_empty_space()) push_to_empty_space(time, car);
		else push_to_second_space(time, car);
	}
};
int main() {
	while (true) {
		int m, n; std::cin >> m >> n; if (m == 0 && n == 0) break;
		std::vector<Car> cars; cars.reserve(n);
		for (auto i = 0; i < n; ++i) {
			int t; std::cin >> t;
			cars.push_back(Car{ i, t });
		}
		Park park(m);
		std::queue<Car> waiting;
		std::vector<int> out_id; out_id.reserve(n);
		for (auto i = 0; i < n; ++i) {
			const int time = i * 10;
			while (park.next_out() <= time) {
				const auto current_time = park.next_out();
				while (park.next_out() == current_time) {
					out_id.push_back(park.pop_car());
				}
				while (park.has_space() && !waiting.empty()) {
					park.park_car(current_time, waiting.front());
					waiting.pop();
				}
			}
			if (park.has_space()) {
				park.park_car(time, cars[i]);
			}
			else {
				waiting.push(cars[i]);
			}
		}
		while (park.park_count() != 0) {
			const auto current_time = park.next_out();
			while (park.next_out() == current_time) {
				out_id.push_back(park.pop_car());
			}
			while (park.has_space() && !waiting.empty()) {
				park.park_car(current_time, waiting.front());
				waiting.pop();
			}
		}
		for (auto i = 0; i < n; ++i) {
			if (i != 0) std::cout << ' ';
			std::cout << out_id[i] + 1;
		}
		std::cout << '\n';
	}
}

