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

// Size of the hash table
#define HASH_TABLE 40343

#define NAME_LEN 20
#define MAX_N 5000
#define MAX_M 30000

// The hash table
char name[HASH_TABLE][NAME_LEN];
int id[HASH_TABLE];

// id of met gossipers for every meeting
int meeting[MAX_M][2];

int hash(char *s)
{
	int i=0, a=47;
	while (s[i])
	{
		a = (7*a + 23*i*s[i]) % HASH_TABLE;
		i++;
	}
	return a;
}

int main(void)
{
	int N, M;
	scanf("%d %d ", &N, &M);

	while (N || M)
	{
		for (int i=0; i<HASH_TABLE; i++) id[i]=-1;

		int h;
		char s[NAME_LEN];

		// Read names and place then to the hash table
		for (int i=0; i<N; i++)
		{
			scanf("%s ", s);
			h = hash(s);
			while (id[h] >= 0) h = (h+1)%HASH_TABLE;
			strcpy(name[h], s);
			id[h]=i;
		}
		// Look up names of met gossipers in the hash table
		for (int i=0; i<M; i++)
		{
			for (int j=0; j<2; j++)
			{
				scanf("%s ", s);
				h = hash(s);
				while (strcmp(s,name[h])) h = (h+1)%HASH_TABLE;
				meeting[i][j] = id[h];
			}
		}

		// Simulate the meetings for each gossip
		int yes=1;
		for (int i=0; yes && i<N; i++)
		{
			int known[MAX_N];
			for (int j=0; j<N; j++) known[j] = 0;
			known[i] = 1;

			for (int j=0; j<M; j++)
			{
				known[meeting[j][0]] = known[meeting[j][1]] =
					known[meeting[j][0]] ||
					known[meeting[j][1]];
			}

			for (int j=0; j<N; j++) yes = yes && known[j];
		}

		printf(yes?"YES\n":"NO\n");
		scanf("%d %d ", &N, &M);
	}

	return 0;
}
