program symmetric_grid
  implicit none
  integer :: h, w, a(12,12), i, j, x, y
  integer :: b(12,12), c(12,12)
  character(12) :: s
  a = 0
  b = 0
  c = 0
  read(*,*) h, w
  do i = 1, h
    read(*,*) s
    s = trim(adjustl(s))
    do j = 1, w
      a(i,j) = ichar(s(j:j))-96
    end do
  end do
  do i = 1, h
    do j = i, h
      b(1:h,1:w) = a(1:h,1:w)
      b(i,1:w) = a(j,1:w)
      b(j,1:w) = a(i,1:w)
      if (check(h,w,b(1:h,1:w))) then
        write(*,'(a)') "YES"
        stop
      end if
      do x = 1, w
        do y = x, w
          c(1:h,1:w) = b(1:h,1:w)
          c(1:h,x) = b(1:h,y)
          c(1:h,y) = b(1:h,x)
          if (check(h,w,c(1:h,1:w))) then
            write(*,'(a)') "YES"
            stop
          end if
        end do
      end do
    end do
  end do
  write(*,'(a)') "NO"
  stop
contains
  function check(h,w,a) result(y)
    implicit none
    integer, intent(in) :: h, w, a(h,w)
    integer :: i, j
    logical :: y
    y = .false.
    do i = 1, h
      do j = 1, w
        if (a(h-i+1,w-j+1).ne.a(i,j)) return
      end do
    end do
    y = .true.
    return
  end function check
end program symmetric_grid