#[allow(dead_code)]
fn getline() -> String {
    let mut res = String::new();
    std::io::stdin().read_line(&mut res).ok();
    res
}

#[allow(unused_macros)]
macro_rules! readl {
    ($t: ty) => {
        {
            let s = getline();
            s.trim().parse::<$t>().unwrap()
        }
    };
    ($( $t: ty),+ ) => {
        {
            let s = getline();
            let mut iter = s.trim().split(' ');
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
}

#[allow(unused_macros)]
macro_rules! readlvec {
    ($t: ty) => {
        {
            let s = getline();
            let iter = s.trim().split(' ');
            iter.map(|x| x.parse().unwrap()).collect::<Vec<$t>>()
        }
    }
}

#[allow(unused_macros)]
macro_rules! debug { ($x: expr) => { println!("{}: {:?}", stringify!($x), $x) } }
// macro_rules! debug { ($x: expr) => () }

#[allow(dead_code)]
fn show<T>(iter: T) -> String
where
    T: Iterator,
    T::Item: std::fmt::Display
{
    let mut res = iter.fold(String::new(), |sum, e| sum + &format!("{} ", e));
    res.pop();
    res
}

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BinaryHeap, HashMap, HashSet};
#[allow(unused_imports)]
use std::collections::btree_map::Entry::{Occupied, Vacant};

struct Random {
    x: i32,
    y: i32,
    z: i32,
    w: i32,
    t: i32,
}

impl Random {
    fn new() -> Random {
        Random {
            x: 400,
            y: 362436069,
            z: 521288629,
            w: 886751233,
            t: 1,
        }
    }

    fn next(&mut self) -> i32 {
        self.t = self.x^(self.x << 11);
        self.x = self.y;
        self.y = self.z;
        self.z = self.w;
        self.w = (self.w ^ (self.w>>19)) ^ (self.t ^ (self.t>>8));
        self.w&0x7fffffff
    }
}

fn check(s: Vec<Vec<u8>>) -> bool {
    let h = s.len();
    let w = s[0].len();

    let mut used = vec![false; h];
    let mut cnt = 0;
    // let comp = |x: &Vec<_>, y: &Vec<_>| {
    //     for (&x, &y) in x.iter().zip(y.iter().rev()) {
    //         if x != y {
    //             return false;
    //         }
    //     }
    //     true
    // };
    'out: for i in 0..h {
        if used[i] {
            continue;
        }
        for j in i+1..h {
            if used[j] {
                continue;
            }
            if s[i] == s[j].iter().cloned().rev().collect::<Vec<u8>>() {
                used[i] = true;
                used[j] = true;
                cnt += 2;
                continue 'out;
            }
        }
    }
    if h%2 == 0 {
        if cnt != h {
            return false;
        }
    } else {
        if cnt+1 != h {
            return false;
        }
        for i in 0..h {
            if !used[i] {
                let mut t = s[i].clone();
                t.reverse();
                if t != s[i] {
                    return false;
                }
            }
        }
    }

    true
}


fn shuffle<T>(v: &mut Vec<T>, rnd: &mut Random) {
    for i in (1..v.len()).rev() {
        let j = rnd.next()%i as i32;
        let j = j as usize;
        v.swap(i, j);
    }
}

fn transpose<T>(v: &Vec<Vec<T>>) -> Vec<Vec<T>> 
where
    T: Default + Clone
{
    let n = v.len();
    let m = v[0].len();
    let mut ret = vec![vec![T::default(); n]; m];
    for i in 0..n {
        for j in 0..m {
            ret[j][i] = v[i][j].clone();
        }
    }
    ret
}

fn main() {
    use std::io::Write;
    let out = std::io::stdout();
    let mut out = std::io::BufWriter::new(out.lock());
    macro_rules! printf { ($($arg:tt)*) => (write!(out, $($arg)*).unwrap()); }
    macro_rules! printfln { () => (writeln!(out).unwrap()); ($($arg:tt)*) => (writeln!(out, $($arg)*).unwrap()); }
    let (h, w) = readl!(usize, usize);
    let mut s: Vec<_> = (0..h).map(|_| readl!(String).into_bytes()).collect();

    let mut rnd = Random::new();
    for _ in 0..1_000_00 {
        shuffle(&mut s, &mut rnd);
        let mut t = transpose(&s);
        if check(t) {
            printfln!("YES");
            return;
        }
    }
    printfln!("NO");
}


Measured memory_bytes: 4476