program main
implicit none
integer :: n, l
character( len = 100 ), allocatable :: str(:)
character( len = 100 ), allocatable :: res(:)
integer :: i, j

read(*,*) n, l
allocate( str(n) )
allocate( res(n) )
do i = 1, n
   read(*,*) str(i)
end do

do i = 1 , n
   do j = i, n
      if( llt( str(i)(1:l), str(j)(1:l) ) .eqv. .true. ) then
      else
         res(i)(1:l) = str(i)(1:l)
         str(i)(1:l) = str(j)(1:l)
         str(j)(1:l) = res(i)(1:l)
      end if
   end do
end do
do i = 1, n
   write(*,*) str(i)(1:l)
end do


end program main
