#include <bits/stdc++.h>
using namespace std;
/*
Coded by 秦惜梦
The most attractive girl in the world
.........   `;!!!!!!!!!;;;;;;;;::::::'''''''``''''''''````````````````````....`:;;;;;:'.....`:|$$$$$$$|;;;:`.    ..........`''``...`''``.   ........   ...  ...   ....  ...   ...  '
........     '!!!!!!!!!;;;;;;;:::::::::''''':::''''`````````````````````......`:;;;;;!%$$%!'.....`:|$%!;;;'....   .....`....`'''`...```..    ........  ..   ...    ..   ...  ...   '
........     .:!!!!!!!!;;;;;;;:::::::::::::::'''''''`````````..```````........`:;!%$$$$$$$$$$$%!'.....`:|!'````..   .........`''``.......    ........  ...  ...   ...   ..   ..   .'
.......       `;!!!!!!;;;;;;;;::::::::::::::::'''''```````````.``````...       .`';|%$$$$$&&$$$$$$%%;'..`'':'''``..  ...``.....```.   ....    .......  ...  ...   ...  ...  ...   .'
.......      . '!!!!!!;;;;;;;:::'''''''''::::::'''```````````````````.........':'`.......`:!%%|||%$$$$$&%;'::::''``.   .```..   ....   ....   .......   ..  ...   ..   ...  ...  ..'
......      '::'''':::::::::::::'''''''''''::::''''``````````````````.........'!$$$$$$%!:`.......`:!%&&&|'``':::'''``.....```.   ....   ...    ......   .......   ..   ..  ...   ..'
``...       .`.``'::::::::;;;;:::::'''''''`'''''`````````````..```````........'!$$$$$$$$$$$$$$%!;'`.....`'`..`'::''''`.....```..  ....   ...   ......   ........ .... .......  ....'
````.      .````.`;!!!;;;;;;;;::'''''''``'''''`````````````````````````.. ....`:!|%$$$&&&&&&&$%%$&&&&@&$|::'`.`''''''''`....````.  ....   ...   ......   .  .....```..``.....  ... '
````      .````.  `;!!;;;;;;;:::::'''''':::'''''````````````........`````.... ........````........``'::::::::'``.``'''''``...````.. ....   ...  ......   .  ......``.```....   ..  '
```.      .```.  .`';!!;;;;;;;:::::::::::::'''''``````````..........````````...`;$$$$&&&&&&$%%||||!|!;;::::::::'`...`'''''`....````.  .... ...   .....   .   .. .``..```....  ..   '
``.       .``.  .`'`';!;;;;;;;;:::::::::::'''''`````````...........`````````....'!|%%%%%%%%%%%%%%%%%%$&&&|:'''''''`...`'''''`....```.  .... ...   .....  .   ..  ..  ......   .   .'
`.        .`.  `''''`';!;;;;;;;::::::::::'''''''```````..........````````````....:|%%%%%%%%%%%%%%%%%%%%%%|:`''''''''`...`''''`....```.. ...   ..  .....  ..  .   ..  .. ...  ..  ..'
`         .  .`'''''``';!;;;;;;;:::::::''''''''''```.``........```````````````````!%%%%%%%%%%||!;:''`.........`'''''''`...`''''`...````.....  ..   ....  ..  .   .   .  ..  ..  ...'
            .''''''````';!;;;;;;;:::::'''''''''''```````````````````````````.........``````...  ...```':;!!:....`'''''''``..`'''`....```.  ... ..  ....      ..  .   .  ..  ..  ...'
         .`''''''''``````;!;;;;;;:::::'''''''''''``````````'''''''''``....```````````````````````````':!||%|;``....`''''''``..`''``....`..  ...     ...   .  .   .  .. ..  .   ... '
        .'''''''''````````:;;;;:::'''''':::::::::::::''''''''''''``..``````....```````````````````````````:!!'`'`.....`'''''``...```.  .........    ....     .  ..  .  .  ..  ...  '
        `'''''''''````';;;:::::::::::::::::::::::''''```````````..........```````````````````````````````````'`.``'``....`''''``.. .`.. ..... ...    ...        .  .. ..  .   ..   '
       .'''''''''```````';;:::::''''''''''''''''''`''```````.`````.....````````````````````````````````''``````....``''`...``''```......  ........   ...     .     .  .  .   ..    '
       `''''''''````'''`````.`::::::::'''''''''''''''''``.``.```........````````````''''`````````````````''''''''`....``'``...``````...... ........   ..     .  .  . .   .  ..     '
      .`'''''''```'''''````````':::::::''''''''''''''``.``.`............`````````'''''''''''''''``````````'''''''''`.....````....```...  ..  ......    .                .   .     .'
      `'''''''`''''''''````````.`::::::'''''''''''''`.```..............``````````'''''''''''''''''````````''''''''''``.......```.........  .  ....     .     ........              '
     .`''''''`''''''''``````````.`:::::::'''''''''``.`..............```````'''''''''''''''''''''''''``````'''''''''''''.........``... .....  .  ...     ..`:::::::::::::'`.        '
      .'''''`''''''''``````````````':::::''''''''``..````````````````````''''''''''''''''''':''''''```''````''''::''''''`.```..........  .....   ....    `'::::::::::::::::`.      '
     ....`''''''''''```````````````.`':::::'''''`...``````````''''''''''''''''''''''''''''''';:'''``''`::````';:''''''''''.....``......... .....   ...   `::::::::::::::::::'`.....'
    ......`''''''''``````````````````.':::::::'`...``'''````''''''''''''''''''''''''''''''';!:;:'''':!;::'```````''''''''''`   ........ ..... ...    ..  ....`':::':::::::::::'... '
    .......`'''''`````````````````````.`':::'```.`''''''````''''''''':'''::'''::''':;::!!!;:;!;;:```````::`````````'''''''''`.     ............  ..   ..          .':::::::::''`   '
   ........`''`````````````````````````..`':''`:;:'':''':''''''''''''::'':;:'''''''''::'''''':;;;:``````:;'```''``````'``'''''`.... ...........    ..                 `::::::'`.   '
  ..........`````````````````````````'::::''':;!!!!;:'::':!;;;:::'''';;'''::::''''':'''::'''''''::'`````':''``''````::`':'''''''''.         ......                      .''`....   '
.`'`.......```````````````````````````````'':!;:::::::::':;::::::::''::''`''::::'`''''':::'':''`:;'`````':'```''`````::`````'''''':;'..................                 .......  . '
`'''''```````````````````````````````````.`;!:::::::::::'''::::::::''::''``'::::'``'''''::''''''':'````````````'`````''````````````:!!;'................              ..........   '
'''''`````````````````````````````````````;!;;;:':::''::''''::::;;:'':::'```'::'````''''''''''''':'```````````''````````````````````';!!!;'....  ......               .......      '
''''````````````````````````````````````';!;;;:'::::':''`''':::;;;:'''':'``'':'````.```''''''''`':'````````````'`````````..``....`...`:!!!!:`.`.....                    .          '
'''````````````````````````````````````':;!;;:`'::':'''``''':::;;;:''``'```'':'``....''`'''''''`''`.`````````````.````````.............';;'.`:;;;'`.                 .....   ...   '
''````````````````````````````````````'':!;::'`::':::''`''''':;;;;:```````'''''```...''`'''''''`''`.``.````````````````````............... `;;;;;;;;;:`.                ....   ....'
''''''''````````````````````````````''`:!;;:''':''::''`'':''':;;;;'```'```''''''`.`'``:'''::''''''```````````````````````````.............`:;;;;;;;;;;;'.      .         ....    ..'
:::::::''''````````````````````````''`'!!;:''''''':''`''''''':;;;:```::``'''':'''`';:';:'::::':`''`''`````````````````'``````````..........`:;;;;;;;;;:.     `'..          .....   '
|%$$%%!;;:'''````````````````````''``';!;:'''':'``'''`'':''':::;:'``:!:``':::::::`:!;';;':::::''`''::````'''''````````''`````````...........`:;;;;;;;'.    .':` `;;;;:. ..   ..... '
@@@@@@@@$|;:''`````````````````''```';!;:::::::'``````'':''::::::'`'!|:`':::;:::'';|!:;;'''''''::::;:``'::''`'````````''````````````.........`:;;;;;`     .:;'..';;;;;;;;;:` ......'
@@@@@@@@@@$|;:''`````````````:'`````;;;:';;;;::'`'````'':''::::::'`;!!;':::::::'`.';!;;;:::::';!!::;'`':::'``'`.``````''````````.......... ..``';;:`     .';;` `:;;;;;;;;;:` `;;;;;;
@@@@@@@@@@@&|;:'``````````''```````;;::':;;;;:'`''```'':'::::;;;:':;|!!;:'''''::::!||!!!!;!!!!||;:!'`:::::'````..``````''`````.......... .  ..`':;`     .';;:` ';;;;;;;;;;:. ';;;;;;
@@@@@@@@@@#@$!:''`````````````````::```';;;;::``'''``'::':::;;;::;;!|||!::;;!!!;;;:'``````'':!!!!|:``':::'`````:;:`.``````.............   . ..`';'     .';;;'..:;;;;;;;;;;'..';;;;;;
@@@@@@@@@@@@$|;:'````````````````::````:;;;::'.`''```''''':::;:::;||%|||%%%%%|!:''''`...`'':!;:;|;```:::'``''`';!;'..`````..............  . ..`''.    .';;;:` `;;;;;;;;;;;' .:;;;;;;
@@@@@@@@@@@&%!;:'```````````````''````':;;;::'..''```````:::::';||%%%%%%$$&&&%!;!|$&%:..';!%%!!|!'`;::::'``''';!;;'...````..............  ....``..   .';;;;'..';;;;;;;;;;;` `:;;;;;;
@@@@@@@@@#@%!!;:'````````````````````.'''::::`..````'''::!||||%%%%&&&&&&&&&&&&&$&&&%||||!|%%%%|!:';;;;!;``''`:;;;:`....`...................`....```. .`':::` `:;;;;;;;;;;:` `;;;;;;;
@@@@@@##@$|!!;:''```````````````````````':'```..`````':!;:''''':!%$&&&&&&&&&&&&$$$|!;;!|%%%%%%|;':;''::'`'''`:!;:`........................```..````........  .':;;;;;;;;;'. ';;;;;;;
!%$$$$%%|!!!;:''``````````````````````````````````````';!:'::'``':|$&&&&&&&&&&&&$$$$$$$$%%%%%|!:```''::'''''```...........................``..`'''`........   ......'::;;'..';;;;;;;
;!!!!!!!!!!;:''``````````````````````````````..````````'!%!;!;;!!%$%$&&&&&&&&&&&&$$$$$$$$$$%%||;``'''':''''``..`....    ... .................`'''````.....   .....`.......  `::;;;;;
::;!!!!!;;:''````````````````````````````````...````````'!%|!|%$$$$%$&&&&&&&&&&&&&&$$$$$$$$%|||:``''''''''```..`....      ..    ...     ....`'''`''```....   .'|%%;......    .... .'
``'::::'''````````````````````````````````````..`...```'`'|&$$$$$$$%$&&&&&&&&&&&&&&$$$$$$$$%%%|:`'''''''''```..`....                    ....`''```''```... .:%%%%|:......   .......'
 .````````````````````````````````````````````.``..```````:|&$$$$$$|%$&&&&&&&&&&&&&&&&&$$$$%%%|:'`'''''''````..`....                      .``'`````''````. :%%%%%;`....... ........'
  .``````````````````````````````````````````..`..`````````:%&&&&&&$%|%$&&&&&&&&&&&&&&&&$$$%$%|:'`'''''''````.``.....                    .``'`````'`'':|:.'!%%%%|'.`````.   .......'
  .```````````````````````````````````````````'`..`````````.:$&&&&&&&&&&&&&&&&&&&&&&&&&&&$$$$%|;'```''''```````.......                  .``'```'``':|%%|'.'|%%%%;```````...........'
  .`````````````````````````````````````````:'`..''````````..!&&&&&&&&&&&&&&&&&&&&&&&&&&&$$&$%%;''```''````````....   .                .'''`.`'``'`;%%%;``;%%$%!'..................'
  .``````````````````````````````````````;|:.``.`''''`````...`|&&&&&&&&&&&&&&&&&&&&&&&&&&$$&&$%!:'```````````.``..                    .`''```;;'''';%%%:.:%&&$|:...................:
  .```````````````````````````````````'!!```'`.`:!:''`````. ..`|&&&&&&&&&&&$%%$$$%|%$$&&&$$&&&$%;'`.``..`......`.                   ..`''''!;''''':|%$|'`!&&$|:...................`:
   .````````````````````````````````;|:````'::`'!;::''''`.  ...`!&&&&&&&&&&&&&&$&&&&&&&&&&$&&&&$|:'```.``.........        .`.    ....`'''```''''';$&&&;`:!;`......................`:
   .`````````````````````````````:|;`````'';:'`';:'''```.. ......'|&&&&&&&&&&&%%%$&&&&&&&$$&&&&&%;'`'`..```........         ``  `;:`''''``'```'!$&&&%!'.....................```````:
   .``````````````````````````:|;``````'':;:'``':'''`````. ........`:%&&&&&&&&&&&&&&&&&&&$&&&&|!!!;'''`....``......`.        .;%%;`''''';|||!;:''::;;' ..``......``````````````````:
   .```````````````````````!%:````````'':;:'```'':''````.. ............'|&@&&&&&&&&&&&&&&&$$|;!!!!!;:'``'`....``...````..      `:;;:'''!%;::::::::;;`. .````````'''````````````````:
   .```````````````````:%!'``````````'::::'````'''''````.  .............```;$&@&&&&&&&&&&$|;;!!!!!!!!;```::`  ...``.';;'```.    `:::'';$$|;:::::!;'`....``````''''''''````''''`````:
   .```````````````:%|'`````````````'::::'`````'''''''``.  .....  ....`````````;$&&&&@&|::!!;!!!!!!!!|!'```';'..  ....'!%%|!::``'':'':|$&&$|!!;:;:'`. .```````':::::''''''''''''''':
   .``````````;||:```````````````''::'::'````.`'''''''`.. .......  ..`````````````';:`````';!!!!!!!||||!;'```';!:`... ..`:|%%!'''''`:!%$&&&$$$!:;;;:'``'```''::::::::''''':::::'''';
   ..``';;:'```````````````````'''::'':'```````'''::''`..  .......   ..``````````````````. '||!!!|||||||!!;'````'!|;'``````````'''`';:'`'%&&&&&&|;!;:;!!!;;::;;::::::''''::::::::::;
``...``````````````````````''''''::''''`````````':::''``. .........  ....```````````...   .:!||||||%%%|||!!!!;'````'!||;'```.`'''`.`.`''`.;$&&&$:  .``'::::;!|%$$%|;:''':::::::::::;
    .````````````````````'''''''::```'````````.`:::'''```. .......... .............    `!%|!!||||%%||||!!!!!|%%%!:````````..`'''..``''`.....':. .   ..`':;;;;;;;::::;!%&%!;;;;:::::;
    .`````````````````''''''''''''''::'''````..`::''''`````. ........``............ .;%%%|!!!||%%%%%%%|!!!|%%%%%%||%%%%%%!'`'''`````....``.....       ..  .`':;;;;;;:::::;!%%!;;;;;;
    .`````````````'''''''''''```''''::'''''``..`''''''```````........````````.....:%%%$%||!|||%%%%%%%||!|%%%%%%%%%%%%|||!'`'''';%%|;`````......'`.      ..      `':::::::;;;;;|%!;;;
    .``````````''''''''''```````'```''''````..`.`'''''````````....  ..```....  `|%%%%$%|||!|%%%%%%%%%|!|%%%%%%%%%%%%%%%|:`'''`;%%%%!:.:!|%$$$$|;:'`...   .``..  .`.  '::::;;;;;;!%!;
%!'..```````''''''''''``````````'```'````````.``.`'''''```````.......       .;%%%%%%%|!!!||%%%%%|!!!!!|%%%%%%%%%%%%%%%%:`''''!%%%!!!:`:!|%$$$$$$$$$%|'`.  .```'`.``.  ..     .':::|%
%%%%%%;```''''''''```````````````'``''``````.````.`''''`..'````.......`'''';|%%%%%%%%||%%%%%%%%%%%|!!%%%%%%%%%%%%%%%%%:`'''';%%||||:`:!|%$$$$$$$$$$$$$%;``. .``''`.                '
$$$%%%%%$$|:''````````````````````''''``````.`````.`'''''`...      .`':|%$$%%%%%%%%%|!|%%%%%%%%%%|||%%$$%%%%%%%%%%%%%:`'''';%||%%%;.:||%$$$$$$$$$$$$$$&&&%:...````''`              '
$$$$$$$$$$%%%%%;`.``````````````````':'``````.`````.`'''''`......`''':!%%%%%%%%%%%%|!!%%%%|||%%|!|%%%%%%%%%%%%%%%%%%:`'''';||%%%|:`;||%$$$$$$$$$$$$&&&&&&&$|'...```'''`            '
|%%$$%%$$$$$%%%%%%%;`..`.`````````````':'````.``.```..`''````''''':|!:|%%%%%%%%%%%%|!!|%|||%||!!%%%%%%%%%%%%%%%%%%%:`'''':|%%%%;``;|%%$$$$$$$$$$&&&&&&&&&&&$$;...`````''`          '
@$|||||%%%%%%%%%%%%%%%%|:`....```````.`''``'''`````````.````''':;|%|;:|%%%%%%%%%%||!!|||||||!!|%%%%%%%%%%%%%%%%%%%:`'''';|%%%%:.'!|%$$$$$$$$$$$$$&&&&&&&&&&&&$!`..``````''`        '
||||&@&%|!|||%%%%%%%%%%%%%%|:.....```````'````.........`!%%%%%%%%|||;:|%%%%%%%%%%||!!|%|%|!!||%%%%%%%%%%%%%%%%%%%:`'''';|%%%!'`;||%$$$$$$$&&$$$$$&&&&&&@&&&&&$$!`..``````````.     '
|||||!|!|$@&%|!|||%%%%%%%%%%%%%:. ...`````''``........:|%%%%%%%%%||%;:|%%%%%%%$%%%%!;|||!!||||%%%%%%%%%%%%%%%%%%:`'''';||%|:`:||%%$$$&&&&&$$%%$$&&&&@######&&$$$!`..``..```````.   '
||||||||!|!!!!|%$%|||||%$%%%%%%%%%!`.....````'`......'|%%%%%%%%%%|%$|;%&&&&&&&&$$$$|!|!!%$$$$&&&&&&&&&$$$$$$$$%;`''':;|||;``;||%$$&&&&&&&$$%%$$&&&&&@######&$$$$%:.....``````````. '
||%%||||||!!|!!|||!|%$%|||%%%%%%%%%%%|:.....`.`'`...'|%%%%%%%%%$$$$&|:|&&&&&&&&$$$$|;!|$$$$&&&&&&&&&&&&&&&&@&$;`''':;||;``!||%$&$$$&&&&$%%%%%$&#####@@###@&$$&$$$!`.......`````````:
   .:!|%%|||||||||||||||!|||||%%%%$%%%%%;`.......``:%&&&&&&&&&&&&$$$%;;$&&&&&&&&&&$||$$$&&@@@@@@@@@@@@@@@@@@&!'''':;!:`'!||%$&$$$$$&&&$%%|%%$@######@&&&&&$$$$$$$%;..`...`...`````':
    .....`;|%%%%%|||!|||!|||!!!||%%%%%%%%%%;`.....:%&&&&&&&&&&&&$$$&$|'!$&&&&&&&$$%$$$&&@@@@@@@@@@@@@@@@@@@@!'::':'`.'|||%$$&&$$$$$&&$%%||%$@#########@@&&$$$$&$%$!`..`...```..````:
    ..........'!|%|%|||||!||||||||||%%%%%%%%%:...'|&&&&&&&&&&&&&$$&&&$;'|&&&&&$%%$$$&&@@@@@@@@@@@@@@@@@##@@!'::::'`:|%%%$$$&&&$$$$$$$%%|%&@@##########@@@@&&&$$$$$%;..``....````.``:
    .....```......`;|%|%%||||||||||||||%%%%%%|!:`!&&&&&&&&&&&&&&$$$&&$%::%&$$%%$$&&&@@@@@@@@@@@@@@@@@@@#@&|::::::;|%%$$$$&&&&&$$$$$$%%%%&@@@###########@@@@&&&&&$$$!`..`.....`````.'
    ..................`;|%%%|%%|||!|||||||%%%|||$&&&&&&&&&&&@&&&$$$&&&$%;;%%%$$&&@@@@@@@@@@@@@@@@@##@#@&$;':::::!%%$$$$&&&&&&&$$$%%%%%|$@@@@##@#########@@@@@&&&&$$|:...`.....`````:
    ............``..```...`;|%|||%||!!|||||||||%&&&&&&&&&&@@@@&&$$$&&&&$%;;%$$&@@@@@@@@@@@@@@@@@@#@@&$!`.`:::::!%$$$&&&&&&&&$$$$$$%%%||&@@@@##@@@@########@@@@&&&&$$!`...`.....````:
    ...................```...`:|%||||||||!||||%&&&&&&&&&&&@@@@@&$%&&$$$%%%;:!$&@@@@@@@@@@@@@@#@@&&%;``;|;:::::!$$$&&&&&&&&&&$$$$$%%%%||&@@@@@@@@@@##@#####@@@@@&&&&&$:..```.....```:
    .....................``.`...`;|%|||||||||%&&&&&&&&&&&&@@@@@@$$&$$%%$$$%!::|&@@@@@####@@@&$%;'':|%|!::::::!$$&&&&&@&&&&&&$$$$$$%%|||$@@@@@@@@@@@@@@@####@@@@@&&&&&%'.```..`...``:
    ...........................``..'!%|||||!%$&&&&&&&&&&&&@@@@@&$$$%%$$@@@&$%!::|&&&&&&&&$|;::;||||%%|::::::!$$&&&&@@@&&&&&&$$$$$$%%|||$@@@@&&&&&&&@@@@@@@@@@@@@@&&&$$|'.```.......:
    ...........................```...`;||||%$&&&&&&&&&&&&@@@@@&$%%$$&@@@@&&&&$|!!;;!||;:;!|%%||%$&&$|;:::::!$$&&&@@@@@@@&&&&$$$$$$%%%%|%&@@@&&&&&&&&&&&&&&&&&@@@&&&&$$$!`.``.......:
*/

int n,m;
char s[15][15];
int cnt[15][35];
int tr[15],tc[15];

void colstrs(int now,bool js=m&1){
	if(now==m){
		puts("YES");
		exit(0);
	}
	if(~tc[now]){
		colstrs(now+1,js);
		return;
	}
	if(js){
		bool can=1;
		for(int j=0;j<n;j++){
			can&=(s[j][now]==s[tr[j]][now]);
		}
		if(can){
			tc[now]=now;
			colstrs(now+1,0);
			tc[now]=-1;
		}
	}
	for(int i=0;i<m;i++){
		if(i!=now&&!~tc[i]){
			bool can=1;
			for(int j=0;j<n;j++){
				can&=(s[j][now]==s[tr[j]][i]);
			}
			if(!can){
				continue;
			}
			tc[now]=i;
			tc[i]=now;
			colstrs(now+1,js);
			tc[now]=tc[i]=-1;
		}
	}
}

void rowstrs(int now,bool js=n&1){
	if(now==n){
		memset(tc,-1,sizeof(tc));
		colstrs(0);
		return;
	}
	if(~tr[now]){
		rowstrs(now+1,js);
		return;
	}
	if(js){
		tr[now]=now;
		rowstrs(now+1,0);
		tr[now]=-1;
	}
	for(int i=0;i<n;i++){
		if(i!=now&&!~tr[i]){
			bool can=1;
			for(int j=0;j<26;j++){
				can&=(cnt[now][j]==cnt[i][j]);
			}
			if(!can){
				continue;
			}
			tr[now]=i;
			tr[i]=now;
			rowstrs(now+1,js);
			tr[now]=tr[i]=-1;
		}
	}
}

int main(){
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++){
		scanf("%s",s[i]);
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			cnt[i][s[i][j]-'a']++;
		}
	}
	memset(tr,-1,sizeof(tr));
	rowstrs(0);
	puts("NO");
	return 0;
}

Measured memory_bytes: 256