module mod_stack
  implicit none
  type t_node
    private
    integer(8) :: item
    type(t_node), pointer :: prev => null()
    type(t_node), pointer :: next => null()
  end type t_node
  type t_stack
    private
    integer :: num = 0
    type(t_node), pointer :: head => null()
    type(t_node), pointer :: tail => null()
  contains
    procedure :: push => push
    procedure :: pop => pop
    procedure :: peek => peek
    procedure :: clear => clear
    procedure :: size => size_of
  end type t_stack
contains
  function new_node(item) result(node)
    integer(8), intent(in) :: item
    type(t_node), pointer :: node
    allocate(node)
    node%item = item
  end
  subroutine push(this,item)
    class(t_stack), intent(inout) :: this
    integer(8), intent(in) :: item
    type(t_node), pointer :: node
    node => new_node(item)
    if (associated(this%head)) then
      node%prev => this%tail
      this%tail%next => node
    else
      this%head => node
    end if
    this%tail => node
    this%num = this%num+1
  end
  function pop(this) result(item)
    class(t_stack), intent(inout) :: this
    integer(8) :: item
    type(t_node), pointer :: node
    item = this%tail%item
    node => this%tail%prev
    deallocate(this%tail)
    this%tail => node
    if (associated(node)) then
      node%next => null()
    else
      this%head => null()
    end if
    this%num = this%num-1
  end
  function peek(this) result(item)
    class(t_stack), intent(in) :: this
    integer(8) :: item
    item = this%tail%item
  end
  subroutine clear(this)
    class(t_stack), intent(inout) :: this
    type(t_node), pointer :: node, prev
    if (.not.associated(this%tail)) return
    node => this%tail
    do while (associated(node%prev))
      prev => node%prev
      deallocate(node)
      node => prev
    end do
    this%head => null()
    this%tail => null()
    this%num = 0
  end
  integer function size_of(this)
    class(t_stack), intent(in) :: this
    size_of = this%num
  end
end module mod_stack
program sequential_operations_on_sequence
  use mod_stack
  implicit none
  type(t_stack) :: stack
  integer :: n, q, i, j, x
  integer(8) :: tmp1, tmp2, p(100000) = 0_8, k, l, r, m
  integer(8) :: t(100000) = 0_8, ans(0:100001) = 0_8
  read(*,*) n, q
  call stack%push(int(n,8))
  do i = 1, q
    read(*,*) tmp1
    do while (stack%size() > 0 .and. stack%peek() >= tmp1)
      tmp2 = stack%pop()
    end do
    call stack%push(tmp1)
  end do
  q = stack%size()
  do i = q, 1, -1
    p(i) = stack%pop()
  end do
  t(q) = 1_8
  do i = q, 2, -1
    j = i-1
    t(j) = t(j)+t(i)*(p(i)/p(j))
    k = mod(p(i),p(j))
    do while (k >= p(1))
      r = j
      l = 1
      do while (r-l > 1)
        m = (l+r)/2
        if (p(m) > k) then
          r = m
        else
          l = m
        end if
      end do
      j = l
      t(j) = t(j)+t(i)*(k/p(j))
      k = mod(k,p(j))
    end do
    x = int(k,4)
    ans(x) = ans(x)+t(i)
  end do
  x = int(p(1),4)
  ans(x) = ans(x)+t(1)
  do i = n, 1, -1
    ans(i) = ans(i)+ans(i+1)
  end do
  do i = 1, n
    write(*,'(i0)') ans(i)
  end do
end program sequential_operations_on_sequence