// Author: Adrian Kuegel
// Date: 4. 6. 20007

#include <stdio.h>
#include <algorithm>
#include <map>
#include <vector>
#include <assert.h>
using namespace std;

// This is a randomized solution which seems to work good on random test
// cases. It is quite hard to create a test case which
// can't be solved by brute force or generating random permutations

#define MAXN 100000

int a[MAXN],ind[MAXN];

bool comp(int i, int j) {
	return a[i] < a[j];
}

typedef map<int,int> MII;
typedef vector<int> VI;
VI sol;

void backtrack(const MII &c, MII::iterator it, int r, int mod) {
	if (it == c.end())
		return;
	sol.push_back(0);
	int cnt = it->second; 
	int a = it->first;
	++it;
	for (int i=0; i<=cnt; ++i) {
		backtrack(c,it,r,mod);
		++sol.back();
		r = (r+a)%mod;
		if (i < cnt && r == 0) throw 42;
	}
	sol.pop_back();
}

int main() {
	int c,n,maxcnt = 0;
//	freopen("halloween.in","r",stdin);
	while(scanf("%d %d",&c,&n) == 2 && (n || c)) {
		MII ca;
		for (int i=0; i<n; ++i) {
			scanf("%d",&a[i]);
			a[i] %= c;
			++ca[a[i]];
			ind[i] = i;
		}
		long long poss = 1;
		for (MII::iterator it=ca.begin(); it!=ca.end(); ++it) {
			poss *= (it->second+1);
			if (poss > 1000000) break;
		}
		sort(ind,ind+n,comp);
		if (poss <= 1000000) {
			sol.clear();
			try {
				backtrack(ca, ca.begin(), 0, c);
			}catch(int){};
			for (int i=0,j=0; j<(int)sol.size(); ++j) {
				if (!sol[j]) ++i;
				while(sol[j]--) {
					assert(i < n);
					printf("%d ",ind[i++]+1);
				}
				while(i<n && a[ind[i]] == a[ind[i-1]])
					++i;
			}
			puts("");
			continue;
		}
		int cnt = 0;
		while(1) {
			int sum = 0;
			bool found = false;
			for (int i=0; i<n; ++i) {
				sum = (sum + a[ind[i]])%c;
				if (sum == 0) {
					found = true;
					for (int j=0; j<=i; ++j) {
						if (j) printf(" ");
						printf("%d",ind[j]+1);
					}
					puts("");
					break;
				}
			}
			if (found) break;
			++cnt;
			if (cnt == 1) reverse(ind,ind+n);
			else random_shuffle(ind, ind+n);
		}
		maxcnt = max(maxcnt,cnt);
	}
//	printf("maxcnt = %d\n",maxcnt);
	return 0;
}
