use std::io::*;
use std::str::FromStr;
use std::collections::HashMap;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

struct Solver {
    h: usize,
    w: usize,
    field: Vec<Vec<char>>,
    ycnts: Vec<HashMap<char, usize>>,
    xcnts: Vec<HashMap<char, usize>>,
    ycenter: Vec<bool>,
    xcenter: Vec<bool>,
}

impl Solver {
    fn new() -> Solver {
        let h: usize = read();
        let w: usize = read();
        let mut field = vec![vec![]; h];
        for y in 0..h {
            field[y] = read::<String>().chars().collect::<Vec<_>>();
        }
        let mut ycnts = vec![HashMap::<char, usize>::new(); h];
        let mut xcnts = vec![HashMap::<char, usize>::new(); w];
        let mut ycenter = vec![false; h];
        let mut xcenter = vec![false; w];
        for y in 0..h {
            for x in 0..w {
                let c = field[y][x];
                *ycnts[y].entry(c).or_insert(0) += 1;
            }
            if ycnts[y].values().filter(|v| *v % 2 == 1).count() == w % 2 {
                ycenter[y] = true;
            }
        }
        for x in 0..w {
            for y in 0..h {
                let c = field[y][x];
                *xcnts[x].entry(c).or_insert(0) += 1;
            }
            if xcnts[x].values().filter(|v| *v % 2 == 1).count() == h % 2 {
                xcenter[x] = true;
            }
        }
        Solver {
            h: h,
            w: w,
            field: field,
            ycnts: ycnts,
            xcnts: xcnts,
            ycenter: ycenter,
            xcenter: xcenter,
        }
    }
    fn is_valid(&self, ypairs: &Vec<(usize, usize)>, xpairs: &Vec<(usize, usize)>) -> bool {
        // println!("{:?} {:?}", ypairs, xpairs);
        for yp in ypairs.iter() {
            for xp in xpairs.iter() {
                if self.field[yp.0][xp.0] != self.field[yp.1][xp.1]
                    || self.field[yp.0][xp.1] != self.field[yp.1][xp.0]
                {
                    return false;
                }
            }
        }
        true
    }
    fn xdfs(
        &self,
        rest: usize,
        ypairs: &Vec<(usize, usize)>,
        xpairs: &mut Vec<(usize, usize)>,
    ) -> bool {
        if rest == 0 {
            return self.is_valid(ypairs, xpairs);
        }
        if xpairs.len() == 0 && self.w % 2 == 1 {
            for x in 0..self.w {
                if !self.xcenter[x] {
                    continue;
                }
                let nrest = rest ^ (1 << x);
                xpairs.push((x, x));
                if self.xdfs(nrest, ypairs, xpairs) {
                    return true;
                }
                xpairs.pop();
            }
        } else {
            let x1 = rest.trailing_zeros() as usize;
            for x2 in x1 + 1..self.w {
                if (rest & (1 << x2)) == 0 || self.xcnts[x1] != self.xcnts[x2] {
                    continue;
                }
                // println!("{} {} {}", rest, x1, x2);
                let nrest = rest ^ (1 << x1) ^ (1 << x2);
                assert!(nrest < rest);
                xpairs.push((x1, x2));
                if self.xdfs(nrest, ypairs, xpairs) {
                    return true;
                }
                xpairs.pop();
            }
        }
        false
    }
    fn ydfs(&self, rest: usize, pairs: &mut Vec<(usize, usize)>) -> bool {
        if rest == 0 {
            return self.xdfs((1 << self.w) - 1, pairs, &mut vec![]);
        }
        if pairs.len() == 0 && self.h % 2 == 1 {
            for y in 0..self.h {
                if !self.ycenter[y] {
                    continue;
                }
                let nrest = rest ^ (1 << y);
                pairs.push((y, y));
                if self.ydfs(nrest, pairs) {
                    return true;
                }
                pairs.pop();
            }
        } else {
            let y1 = rest.trailing_zeros() as usize;
            for y2 in y1 + 1..self.h {
                if (rest & (1 << y2)) == 0 || self.ycnts[y1] != self.ycnts[y2] {
                    continue;
                }
                // println!("{} {} {}", rest, y1, y2);
                let nrest = rest ^ (1 << y1) ^ (1 << y2);
                assert!(nrest < rest);
                pairs.push((y1, y2));
                if self.ydfs(nrest, pairs) {
                    return true;
                }
                pairs.pop();
            }
        }
        false
    }
    fn solve(&mut self) {
        if self.ydfs((1 << self.h) - 1, &mut vec![]) {
            println!("YES");
        } else {
            println!("NO");
        }
    }
}

fn main() {
    let mut solver = Solver::new();
    solver.solve();
}


Measured memory_bytes: 4352