program sequential_operations_on_sequence
  implicit none
  integer :: n, q, i, j, u = 1, l, r, m, x
  integer(8) :: p(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
    u = u+1
    read(*,*) p(u)
    do while (u > 1 .and. p(u-1) >= p(u))
      p(u-1) = p(u)
      u = u-1
    end do
  end do
  t(u) = 1_8
  do i = u, 1, -1
    k = p(i)
    j = i-1
    do while (j > 0)
      t(j) = t(j)+t(i)*(k/p(j))
      k = mod(k,p(j))
      r = j-1
      l = 1
      j = 0
      do while (l <= r)
        m = (l+r)/2
        if (p(m) <= k) then
          j = m
          l = m+1
        else
          r = m-1
        end if
      end do
    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
end program sequential_operations_on_sequence