program sequential_operations_on_sequence
  implicit none
  integer :: n, q, i, j, u = 1, l, r, m, x
  integer(8) :: p(0:100000) = 0_8, k, t(100000) = 0_8, a(100001) = 0_8, ans = 0_8
  read(*,*) n, q
  p(1) = int(n,8)
  do i = 1, q
    read(*,*) k
    do while (k <= p(u))
      u = u-1
    end do
    u = u+1
    p(u) = k
  end do
  t(u) = 1_8
  do i = u, 1, -1
    k = p(i)
    j = idx(k,i-1)
    do while (j > 0)
      t(j) = t(j)+t(i)*(k/p(j))
      k = mod(k,p(j))
      j = idx(k,j-1)
    end do
    x = int(k,4)
    a(1) = a(1)+t(i)
    a(x+1) = a(x+1)-t(i)
  end do
  do i = 1, n
    ans = ans+a(i)
    write(*,'(i0)') ans
  end do
contains
  integer function idx(v,i)
    integer(8), intent(in) :: v
    integer, intent(in) :: i
    integer :: l, r, m
    l = 1
    r = i
    idx = 0
    do while (l <= r)
      m = (l+r)/2
      if (p(m) <= v) then
        idx = m
        l = m+1
      else
        r = m-1
      end if
    end do
  end
end program sequential_operations_on_sequence