import java.util.*;
import java.io.*;
public class Task{
/// functions
static long gcd(long a,long b){if(b==0){return a;}return gcd(b,a%b);}
static long Modpow(long a,long p,long m){if(p==1){return a;}long x=Modpow(a,p/2,m);x=(x*x)%m;return (p&1l)!=0? (x*a)%m:x;}
static long Modmul(long a,long b,long m){return ((a%m)*(b%m))%m;}
static long ModInv(long a,long m){return Modpow(a,m-2,m);}
static long nck(int n,int r,long m){if(r>n){return 0l;}return Modmul(f[n],ModInv(Modmul(f[n-r],f[r],m),m),m);}
// end
static long[] f;

public static void main(String[] args) throws FileNotFoundException, IOException{
       Scanner s=new Scanner(System.in);
       BufferedWriter out=new BufferedWriter(new OutputStreamWriter(System.out));
       	StringBuilder sb=new StringBuilder();
       	int q=s.nextInt(),x=s.nextInt();
       	Map<Integer,Integer>map=new HashMap<>();
       	int[][] arr=new int[q+5][3];int i=1,pre=0;
       	while(q--!=0){
       		arr[i][0]=arr[i-1][0];
       		arr[i][1]=arr[i-1][1];
       		arr[i][2]=arr[i-1][2];
       		int cc=s.nextInt()%3;
       		arr[i][cc]++;
       		int tmp=pre;
       		for(int j=tmp;j<i;j++){
       			if(tmp!=j){break;}
       			if(arr[i][0]<=0&&arr[i][1]<=0&&arr[i][2]<=0){break;}
       			int currp=j;
       		  if(arr[i][0]>0&&Math.abs(currp-0)%3==0){
       		  	tmp=currp+1;
       		  	arr[i][0]--;
       		  	continue;
       		  }
       		  else if(arr[i][1]>0&&Math.abs(currp-1)%3==0){
       		  	tmp=currp+1;
       		  	arr[i][1]--;
       		  	continue;
       		  }
       		  else if(arr[i][2]>0&&Math.abs(currp-2)%3==0){
       		  	tmp=currp+1;
       		  	arr[i][2]--;
       		  	continue;
       		  }
       		}
       		pre=tmp;i++;
       			out.write(tmp+"\n");
       		
       		
       	}
       
          out.flush();
       	}
       }
        
  
 