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

#[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>>,
}

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<_>>();
        }
        Solver {
            h: h,
            w: w,
            field: field,
        }
    }
    fn is_valid(&self, ypairs: &Vec<(usize, usize)>, xp: &(usize, usize)) -> bool {
        // println!("{:?} {:?}", ypairs, xpairs);
        for yp in ypairs.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)>) -> bool {
        if rest == 0 {
            return true;
        }
        if rest == (1 << self.w) - 1 && self.w % 2 == 1 {
            for x in 0..self.w {
                if !self.is_valid(ypairs, &(x, x)) {
                    continue;
                }
                let nrest = rest ^ (1 << x);
                if self.xdfs(nrest, ypairs) {
                    return true;
                }
            }
        } else {
            let x1 = rest.trailing_zeros() as usize;
            for x2 in x1 + 1..self.w {
                if (rest & (1 << x2)) == 0 || !self.is_valid(ypairs, &(x1, x2)) {
                    continue;
                }
                // println!("{} {} {}", rest, x1, x2);
                let nrest = rest ^ (1 << x1) ^ (1 << x2);
                assert!(nrest < rest);
                if self.xdfs(nrest, ypairs) {
                    return true;
                }
            }
        }
        false
    }
    fn ydfs(&self, rest: usize, pairs: &mut Vec<(usize, usize)>) -> bool {
        if rest == 0 {
            return self.xdfs((1 << self.w) - 1, pairs);
        }
        if pairs.len() == 0 && self.h % 2 == 1 {
            for y in 0..self.h {
                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 {
                    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