local h, w = io.read("*n", "*n", "*l")
local map = {}
for i = 1, h do
  local str = io.read()
  for j = 1, w do
    map[(i - 1) * w + j] = str:sub(j, j)
  end
end
local vertical = {}
local vmap = {}
for i = 1, w do
  vertical[i] = {}
  for j = 1, h do
    vertical[i][j] = map[(j - 1) * w + i]
  end
  table.sort(vertical[i])
  vertical[i] = table.concat(vertical[i], "")
  local v = vertical[i]
  if vmap[v] then
    vmap[v] = nil
  else
    vmap[v] = true
  end
end
local vrem = 0
for k, v in pairs(vmap) do
  vrem = vrem + 1
end

local horizontal = {}
local hmap = {}
for i = 1, h do
  horizontal[i] = {}
  for j = 1, w do
    horizontal[i][j] = map[(i - 1) * w + j]
  end
  table.sort(horizontal[i])
  horizontal[i] = table.concat(horizontal[i], "")
  local v = horizontal[i]
  if hmap[v] then
    hmap[v] = nil
  else
    hmap[v] = true
  end
end
local hrem = 0
for k, v in pairs(hmap) do
  hrem = hrem + 1
end
local f = vrem <= 1 and hrem <= 1
print(f and "YES" or "NO")
