// https://atcoder.jp/contests/arc095/tasks/arc095_c
//
#![allow(unused_imports)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, [ next / $t:tt ]) => {
        {
            let len = read_value!($iter, usize);
            (0..len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
        }
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! dvec {
    ($t:expr ; $len:expr) => {
        vec![$t; $len]
    };

    ($t:expr ; $len:expr, $($rest:expr),*) => {
        vec![dvec!($t; $($rest),*); $len]
    };
}

#[allow(unused_macros)]
macro_rules! ifv {
    ($t:expr, $a:expr, $b: expr) => {
        if $t { $a } else { $b }
    }
}

#[allow(unused_macros)]
macro_rules! fill {
    ($t:expr, $v:expr) => {
        for i in 0..$t.len() {
            $t[i] = $v;
        }
    };
}

#[allow(unused_macros)]
macro_rules! join {
    ($t:expr, $glue:expr) => {
        $t.into_iter().map(|w| w.to_string()).collect::<Vec<_>>().join($glue)
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

type Pairs = Vec<(usize,usize)>;

fn make_pairs(n: usize, left: usize, taken: usize, pairs: Pairs) -> Vec<Pairs> {
    if left <= 1 {
        return vec![pairs];
    }

    let mut w = vec![];
    for i in 0..n {
        if (taken>>i)&1 == 1 {
            continue;
        }
        for j in i+1..n {
            if (taken>>j)&1 == 0 {
                let mut tp = pairs.clone();
                tp.push((i, j));
                let tt = taken|(1<<i)|(1<<j);
                w.append(&mut make_pairs(n, left-2, tt, tp));
            }
        }
        break;
    }
    w
}


fn make_table(s: &Vec<Vec<char>>, pairs: Pairs, center: Option<usize>) -> Vec<Vec<char>> {
    let n = s.len();
    let m = s[0].len();

    let pn = pairs.len();
    let mut col_perm = vec![0; m];
    for i in 0..pn {
        let (l, r) = pairs[i];
        col_perm[i] = l;
        col_perm[m-1-i] = r;
    }
    if let Some(c) = center {
        col_perm[m/2] = c;
    }

    let mut ret = dvec!(' '; n, m);
    for i in 0..n {
        for j in 0..m {
            ret[i][j] = s[i][col_perm[j]];
        }
    }
    ret
}

fn is_reverse(a: &Vec<char>, b: &Vec<char>) -> bool {
    let m = a.len();
    for j in 0..m {
        if a[j] != b[m-1-j] {
            return false;
        }
    }
    true
}

fn is_ok(table: Vec<Vec<char>>) -> bool {
    let n = table.len();
    let m = table[0].len();
    let mut used = vec![false; n];

    let mut no_counterpart = 0;
    for i in 0..n {
        if used[i] {
            continue;
        }
        let mut found = n;
        for ti in i+1..n {
            if is_reverse(&table[i], &table[ti]) {
                found = ti;
                break;
            }
        }
        if found == n {
            if is_reverse(&table[i], &table[i]) {
                no_counterpart += 1;
            } else {
                no_counterpart += 10000;
            }
        } else {
            used[i] = true;
            used[found] = true;
        }
    }
    ifv!(n % 2 == 1, no_counterpart == 1, no_counterpart == 0)
}

fn main() {
    input! {
        h: usize, w: usize,
        s: [chars; h]
    };

    if w % 2 == 1 {
        for lw in 0..w {
            for pairs in make_pairs(w, w, 1<<lw, vec![]) {
                let table = make_table(&s, pairs, Some(lw));
                if is_ok(table) {
                    println!("YES");
                    return;
                }
            }
        }
    } else {
        for pairs in make_pairs(w, w, 0, vec![]) {
            let table = make_table(&s, pairs, None);
            if is_ok(table) {
                println!("YES");
                return;
            }
        }
    }
    println!("NO");
}


Measured memory_bytes: 6396