program main
    implicit none
    integer n, l
    character(:), allocatable, dimension(:) :: s
    read *, n, l
    allocate(character(l) :: s(n))
    read *, s
    call bubblesort(s, smallerDict)
    print *, s
    !    write (*, fmt='(a)', advance='no') s

contains
    logical function smallerDict(str1, str2)
        character(*), intent(in) :: str1, str2

        integer minLength, i
        logical :: determined = .false.

        minLength = min(len_trim(str1), len_trim(str2))

        if ( len_trim(str2) == 0 ) then
            smallerDict = .false.
        endif

        if ( len_trim(str1) == 0 ) then
            smallerDict = .true.
        endif

        do i=1, minLength
            if ( iachar(str1(i:i)) < iachar(str2(i:i)) ) then
                smallerDict = .true.
                determined = .true.
                exit
            else if ( iachar(str1(i:i)) > iachar(str2(i:i)) ) then
                smallerDict = .false.
                determined = .true.
                exit
            endif
        enddo
        if ( .not. determined ) then
            smallerDict = .false.
        endif
        end function

        subroutine bubblesort(array, compareFunction)
            character(*), dimension(:), intent(inout) :: array

            interface
                logical function compareFunction(str1, str2)
                    implicit none
                    character(*), intent(in) :: str1, str2
                end function
            end interface

            integer i
            character(len(array(1))) temp
            logical update

            do
                update = .false.
                do i=1, size(array) - 1
                    if ( .not. compareFunction(array(i), array(i + 1)) ) then
                        temp = array(i)
                        array(i) = array(i + 1)
                        array(i + 1) = temp
                        update = .true.
                    endif
                end do
                if ( .not. update ) then
                    exit
                endif
            end do
        end subroutine
    end program main
