#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int count[256];
int field[22][22];
int m, n;

void init()
{
	for (int i=0; i<=n+1; i++)
		for (int j=0; j<=m+1; j++)
			field[i][j] = 0;
}

int x, y;

int fitting()
{
	return ((field[y][x-1] & 0x0c) << 4) | ((field[y-1][x] & 0x30) >> 4);
}

inline inv2(int n)
{
	return n == 0 ? 0 : (3 - n);
}

//int invert(int p)
//{
//	return (inv2(p % 4) << 4) | (inv2((p / 4) % 4) << 6) | inv2((p / 16) % 4) | (inv2((p / 64) % 4) << 2);
//}

int next(int g0)
{
// odkomentuj ak chces vidiet postup riesenia
//	view->DrawPuzzlePiece(x, y, g0, RGB(0, 255, 0));
	count[g0]--;
//	int h0 = invert(g0);
//	count[h0]--;
	field[y][x] = g0;
	if (++x > m) {
		y++; x = 1;
	}

	int f = fitting();
	int g;

	if (y == n) {
		if (x == m) {
			if (count[f]) {
				field[y][x] = f;
				return 1;
			} else
				goto koniec;
		}
		g = f | 4;
		if (count[g])
			if (next(g))
				return 1;
		g = f | 8;
		if (count[g])
			if (next(g))
				return 1;

	} else if (x < m) {
		g = f | 4 | 16;
		if (count[g])
			if (next(g))
				return 1;
		g = f | 8 | 16;
		if (count[g])
			if (next(g))
				return 1;

		g = f | 4 | 32;
		if (count[g])
			if (next(g))
				return 1;
		g = f | 8 | 32;
		if (count[g])
			if (next(g))
				return 1;
	} else {
		g = f | 16;
		if (count[g])
			if (next(g))
				return 1;
		g = f | 32;
		if (count[g])
			if (next(g))
				return 1;
	}

koniec:
	if (--x == 0) {
		y--; x = m;
	}
	count[g0]++;
//	count[h0]++;

// odkomentuj ak chces vidiet postup riesenia
//	view->DrawPuzzlePiece(x, y, g0, RGB(255, 255, 255));

	return 0;
}

int decode(const char* s)
{
	int p = 0;

	switch (s[0]) {
		case 'O': p |= 1; break;
		case 'I': p |= 2; break;
	}
	switch (s[1]) {
		case 'O': p |= 4; break;
		case 'I': p |= 8; break;
	}
	switch (s[2]) {
		case 'O': p |= 32; break;
		case 'I': p |= 16; break;
	}
	switch (s[3]) {
		case 'O': p |= 128; break;
		case 'I': p |= 64; break;
	}

	return p;
}

int solve()
{
	x = 0;
	y = 1;
	return next(0);
}

void initialize()	
{
	char buffer[100];
	int p;
	FILE *fin, *fout;
	fin = stdin;
	fout = stdout;
	while (1) {
		fscanf(fin, "%d%d", &n, &m);

		if (m == 0)
			break;

		for (int i=0; i<256; i++)
			count[i] = 0;
		
		for (i=0; i<n; i++)
			for (int j=0; j<m; j++) {
				fscanf(fin, "%s", buffer);
				p = decode(buffer);
				count[p]++;
//				count[invert(p)]++;
			}

		if (solve()) fprintf(fout,"YES\n");
		else fprintf(fout,"NO\n");
	}
	fclose(fin);
	fclose(fout);
}

int main()
{
	initialize();

	return 0;
}
