#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse2")
using namespace std;
int n, i, j, k, l, sum = 0, flag = 0, ans = 1, m, visited[300005] = {0},
                   inc[300005] = {0}, a[300005][26] = {0};
vector<long long int> v[300005];
string s;
void dfs(int node) {
  visited[node] = 1;
  for (auto j : v[node]) {
    if (!visited[j]) {
      dfs(j);
    }
    for (int i = 0; i < 26; i++) a[node][i] = max(a[j][i], a[node][i]);
  }
  a[node][s[node - 1] - 'a']++;
}
queue<int> q;
queue<int> st;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  cin >> s;
  for (i = 0; i < m; i++) {
    cin >> j >> k;
    v[j].push_back(k);
    if (j == k) {
      cout << -1;
      return 0;
    }
    inc[k]++;
  }
  for (i = 1; i <= n; i++)
    if (inc[i] == 0) q.push(i);
  while (!q.empty()) {
    int c = q.front();
    q.pop();
    st.push(c);
    for (auto j : v[c]) {
      inc[j]--;
      if (inc[j] == 0) q.push(j);
    }
  }
  if (st.size() < n) {
    cout << "-1\n";
    return 0;
  }
  while (!st.empty()) {
    int p = st.front();
    if (!visited[p]) {
      dfs(st.front());
    }
    st.pop();
  }
  for (i = 1; i <= n; i++) {
    for (j = 0; j < 26; j++) ans = max(ans, a[i][j]);
  }
  cout << ans << '\n';
  return 0;
}
