#include <bits/stdc++.h>
using namespace std;
int n, m;
string s;
char nd[300005];
vector<int> adj[300005];
int deg[300005];
int dp[300005][26];
stack<int> st;
int main() {
  scanf("%d%d", &n, &m);
  cin >> s;
  for (int i = (0); i < (s.length()); ++i) nd[i + 1] = s[i];
  for (int i = (0); i < (m); ++i) {
    int u, v;
    scanf("%d%d", &u, &v);
    adj[u].push_back(v);
    deg[v]++;
  }
  int cnt = 0;
  for (int i = (0); i < (n); ++i) {
    dp[i + 1][nd[i + 1] - 'a'] = 1;
    if (!deg[i + 1]) {
      st.push(i + 1);
      cnt++;
    }
  }
  while (!st.empty()) {
    int cn = st.top();
    st.pop();
    for (int i = (0); i < (adj[cn].size()); ++i) {
      int cadj = adj[cn][i];
      if (--deg[cadj] == 0) st.push(cadj), cnt++;
      for (int i = 0; i < 26; i++)
        dp[cadj][i] = (dp[cadj][i] >= dp[cn][i] ? dp[cadj][i] : dp[cn][i]);
      dp[cadj][nd[cadj] - 'a'] =
          (dp[cadj][nd[cadj] - 'a'] >= dp[cn][nd[cadj] - 'a'] + 1
               ? dp[cadj][nd[cadj] - 'a']
               : dp[cn][nd[cadj] - 'a'] + 1);
    }
  }
  if (cnt != n) {
    cout << -1 << endl;
  } else {
    int ans = 0;
    for (int i = (0); i < (n); ++i)
      for (int j = (0); j < (26); ++j)
        ans = (ans >= dp[i + 1][j] ? ans : dp[i + 1][j]);
    cout << ans << endl;
  }
  return 0;
}
