#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int tsize, n, hashTable[10100];
bool isprime(int a){
if(a==1)return false;
for(int i=2;i*i<=a;i++){
if(a%i==0) return false;
}
return true;
}
void insert(int key){
for(int step=0;step<tsize;step++){
int index=(key+step*step)%tsize;
if(hashTable[index]==0){
hashTable[index]=1;
cout<<index%tsize;
return;
}
}
cout<<'-';
}
int main() {
cin>>tsize>>n;
while (!isprime(tsize)) tsize++;
for(int i=0;i<n;i++){
int key;
cin>>key;
if(i!=0)cout<<" ";
insert(key);
}
system("pause");
return 0;
}