#include <bits/stdc++.h>
using namespace std;
int n, m;
int ar[300001];
int visited[300001];
vector<int> adj[300001];
int dp[300001][27];
vector<int> st;
void dfs(int u) {
  visited[u] = 2;
  for (auto &i : adj[u]) {
    if (visited[i] == 0) dfs(i);
    if (visited[i] == 2) {
      cout << -1;
      exit(0);
    }
  }
  visited[u] = 1;
  st.push_back(u);
}
int dfs2(int v, int col) {
  if (dp[v][col] != -1) return dp[v][col];
  int res = 0;
  for (auto &i : adj[v]) {
    res = max(res, dfs2(i, col));
  }
  res += (ar[v] == col);
  return dp[v][col] = res;
}
int main() {
  cin >> n >> m;
  string s;
  cin >> s;
  for (int i = 0; i < s.length(); ++i) {
    ar[i + 1] = s[i] - 'a' + 1;
    visited[i + 1] = 0;
  }
  for (int i = 1; i <= m; ++i) {
    int a, b;
    cin >> a >> b;
    adj[a].push_back(b);
  }
  for (int i = 1; i <= n; ++i) {
    if (visited[i] == 0) dfs(i);
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= 26; ++j) dp[i][j] = -1;
  }
  int m = 0;
  for (int i = 1; i <= 26; ++i) {
    for (int k = st.size() - 1; k >= 0; --k) {
      m = max(m, dfs2(st[k], i));
    }
  }
  cout << m;
  return 0;
}
