import sys
import math
import bisect
from sys import stdin, stdout
from math import gcd, floor, sqrt, log2, ceil
from collections import defaultdict
from bisect import bisect_left as bl, bisect_right as br
from collections import Counter
from collections import deque
 
ip = lambda : int(stdin.readline())
inp = lambda: map(int,stdin.readline().split())
ips = lambda: stdin.readline().rstrip()

q,x = inp()
arr = []
dic = {0:0,1:0,2:0}
c = [0,1,2]
for _ in range(q):
    x = ip()
    dic[x%3] += 1
    ch = min(list(dic.values()))
    sam = dict(dic)
    ans = 3*ch
    for i in c:
        sam[i] -= ch
    for i in c:
        if sam[i]>0:
            ans += 1
        else:
            break
    print(ans)
            
            
            
        
