#include <fstream>
using namespace std;
ifstream cin("nrcuv.in");
ofstream cout("nrcuv.out");
bool a[26][26];
int d[1001][26];
int main()
{
int i,j,n,c=0,m,t,k;
char x, y;
cin>>n>>m>>ws;
for(i=1; i<=m; i++)
{
cin >> x >> ws >> y >> ws;
a[x-'a'][y-'a'] = a[y-'a'][x-'a'] = true;
}
for (j = 0; j < 26; j++)
d[1][j] = 1;
for(i=2; i<=n; i++)
for(j = 0; j < 26; j++)
for(k = 0; k < 26; k++)
if (!a[k][j])
{
d[i][j]+=d[i-1][k];
d[i][j]%=104659;
}
c = 0;
for (j = 0; j < 26; j++)
{
c += d[n][j];
c %= 104659;
}
cout << c;
return 0;
}