#include <cassert>// c
#include <iostream>// io
#include <iomanip>
#include <fstream>
#include <sstream>
#include <vector>// container
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <stack>
#include <algorithm>// other
#include <complex>
#include <numeric>
#include <functional>
#include <random>
#include <regex>
using namespace std;

typedef int32_t i32;typedef int64_t i64;typedef i64 ll;typedef uint32_t uint;typedef uint64_t ull;

#define ALL(c) (begin(c)),(end(c))
#define REP(i,n) FOR(i,0,n)
#define REPr(i,n) FORr(i,0,n)
#define FOR(i,l,r) for(int i=(int)(l);i<(int)(r);++i)
#define FORr(i,l,r) for(int i=(int)(r)-1;i>=(int)(l);--i)
#define EACH(it,o) for(auto it = (o).begin(); it != (o).end(); ++it)
#define IN(l,v,r) ((l)<=(v) && (v)<(r))

//debug
#define DUMP(x)  cerr << #x << " = " << (x)
#define DUMPLN(x)  DUMP(x) <<endl
#define DEBUG(x) DUMP(x) << LINE() << " " << __FILE__
#define DEBUGLN(x) DEBUG(x)<<endl
#define LINE()    cerr<< " (L" << __LINE__ << ")"
#define LINELN()    LINE()<<endl
#define CHECK(exp,act)  if(exp!=act){DUMPLN(exp);DEBUGLN(act);}
#define STOP(e)  CHECK(e,true);if(!(e)) exit(1);

class range {
private:
	struct Iter{
		int v;
		int operator*(){return v;}
		bool operator!=(Iter& itr) {return v < itr.v;}
		void operator++() {++v;}
	};
	Iter i, n;
public:
	range(int n) : i({0}), n({n}) {}
	range(int i, int n) : i({i}), n({n}) {}
	Iter& begin() {return i;}
	Iter& end() {return n;}
};

//output
template<typename T> ostream& operator << (ostream& os, const vector<T>& as){for(int i:range(as.size())){if(i!=0)os<<" "; os<<as[i];}return os;}
template<typename T> ostream& operator << (ostream& os, const vector<vector<T>>& as){for(int i:range(as.size())){if(i!=0)os<<endl; os<<as[i];}return os;}
template<typename T1,typename T2> ostream& operator << (ostream& os, const pair<T1,T2>& p){os<<p.first<<" "<<p.second;return os;}
template<typename K,typename V> ostream& operator << (ostream& os, const map<K,V>& m){bool isF=true;for(auto& p:m){if(!isF)os<<endl;os<<p;isF=false;}return os;}
template<typename T1> ostream& operator << (ostream& os, const tuple<T1>& t){os << get<0>(t);return os;}
template<typename T1,typename T2> ostream& operator << (ostream& os, const tuple<T1,T2>& t){os << get<0>(t)<<" "<<get<1>(t);return os;}
template<typename T1,typename T2,typename T3> ostream& operator << (ostream& os, const tuple<T1,T2,T3>& t){os << get<0>(t)<<" "<<get<1>(t)<<" "<<get<2>(t);return os;}
template<typename T1,typename T2,typename T3,typename T4> ostream& operator << (ostream& os, const tuple<T1,T2,T3,T4>& t){os << get<0>(t)<<" "<<get<1>(t)<<" "<<get<2>(t)<<" "<<get<3>(t);return os;}
template<typename T1,typename T2,typename T3,typename T4,typename T5> ostream& operator << (ostream& os, const tuple<T1,T2,T3,T4,T5>& t){os << get<0>(t)<<" "<<get<1>(t)<<" "<<get<2>(t)<<" "<<get<3>(t)<<" "<<get<4>(t);return os;}
template<typename T1,typename T2,typename T3,typename T4,typename T5,typename T6> ostream& operator << (ostream& os, const tuple<T1,T2,T3,T4,T5,T6>& t){os << get<0>(t)<<" "<<get<1>(t)<<" "<<get<2>(t)<<" "<<get<3>(t)<<" "<<get<4>(t)<<" "<<get<5>(t);return os;}
template<typename T1,typename T2,typename T3,typename T4,typename T5,typename T6,typename T7> ostream& operator << (ostream& os, const tuple<T1,T2,T3,T4,T5,T6,T7>& t){os << get<0>(t)<<" "<<get<1>(t)<<" "<<get<2>(t)<<" "<<get<3>(t)<<" "<<get<4>(t)<<" "<<get<5>(t)<<" "<<get<6>(t);return os;}

//input
char tmp[1000];
#define nextInt(n) scanf("%d",&n)
#define nextLong(n) scanf("%I64d",&n) //I64d
#define nextDouble(n) scanf("%lf",&n) 
#define nextChar(n) scanf("%c",&n)
#define nextString(n) scanf("%s",tmp);n=tmp

// values
template<class T> T INF(){assert(false);};
template<> int INF<int>(){return 1<<28;};
template<> ll INF<ll>(){return 1LL<<58;};
template<> double INF<double>(){return 1e16;};

//O(V+E)
typedef vector<vector<int>> Graph;
class Bridge{
public:
	int N;Graph g;
	vector<int> ord,low;vector<bool> vis;
	stack<int> roots,st;vector<bool> S;
	void dfs(int v,int p,int &oi,int &gi){
		vis[v]=true;ord[v]=low[v]=oi++;st.push(v);S[v]=true;roots.push(v);
		for(int to:g[v]){
			if(!vis[to]) dfs(to,v,oi,gi);
			else if(to != p && S[to])
				while(ord[roots.top()] > ord[to])roots.pop();
		}
		if(v != roots.top()) return;

		bridges.push_back(make_pair(min(v,p),max(v,p)));
		while(true){
			int w=st.top();st.pop();S[w]=false;
			cmp[w]=gi;
			if(v==w)break;
		}
		gi++;roots.pop();
	}
public:
	vector<int> cmp;
	vector<pair<int,int>> bridges;
	Bridge(int N):N(N){
		g=Graph(N);ord=low=cmp=vector<int>(N);vis=S=vector<bool>(N);
	}
	void add_edge(int f,int t){
		g[f].push_back(t);g[t].push_back(f);
	}
	void bridge(){
		int oi=0,gi=0;REP(v,N)if(!vis[v])dfs(v,-1,oi,gi);
	}
	bool same(int i,int j){return cmp[i]==cmp[j];}
};

class Main{
	public:

	int n,m;
	Graph g;
	vector<int> ch;
	int dfs(int v,int p){
		int res = 0;
		for(int to:g[v])if(to!=p)res += dfs(to,v);
		ch[v] = wmap[v];
		for(int to:g[v])if(to!=p)ch[v] += ch[to];
		res += wmap[v] * ch[v];
		if(p!=-1)return res;

		// v is root
		// Y -> r -> X
		vector<bool> exval(n+1);exval[0]=true;
		for(int to:g[v])if(to!=p){
			REPr(val,n+1)if(IN(0,val-ch[to],n+1))
				exval[val] = exval[val] | exval[val-ch[to]];
		}
		// max(|Y| * |X|)
		int sum = n - wmap[v];
		int Mv = 0;REP(val,n+1)if(exval[val] && val<=sum)Mv=max(Mv,val*(sum-val));
		return res + Mv;
	}

	map<int,int> wmap;
	void run(){
		nextInt(n);nextInt(m);
		map<string,int> stoi;
		REP(i,n){string key;nextString(key);stoi[key]=i;}
		Bridge bg(n);
		REP(i,m){
			string f,t;nextString(f);nextString(t);
			bg.add_edge(stoi[f],stoi[t]);
		}
		bg.bridge();

		//make tree
		REP(v,n)wmap[bg.cmp[v]]++;
		g = Graph(n);
		REP(v,n)for(int to:bg.g[v])if(bg.cmp[v]!=bg.cmp[to]){
			g[bg.cmp[v]].push_back(bg.cmp[to]);
		}
		REP(v,n){
			sort(ALL(g[v]));g[v].erase(unique(ALL(g[v])),g[v].end());
		}

		ch=vector<int>(n);
		// ~W ...reverse graph of W
		// 以下のように向きを揃えた方がよい．
		// count( W <- x -> V ) <= count( ~W -> x -> V )
		// （次数3以上も同様．）
		// count( W,W' <- x -> V ) <= count( ~W,~W' -> x -> V )
		// ∴ rootをfixして、各 child_i について root と child_i の向きを child_i 以降の子に伝搬させて考えてよい．
		int Mv=0;REP(v,n)Mv=max(Mv,dfs(bg.cmp[v],-1));
		cout << Mv <<endl;
	}
};

int main(){
	cout <<fixed<<setprecision(20);
	cin.tie(0);
	ios::sync_with_stdio(false);
	Main().run();
	return 0;
}

Measured memory_bytes: 1384