#include <bits/stdc++.h>
using namespace std;
int n, m;
int namenod[300007];
vector<vector<int>> adj;
vector<int> topological;
int color[300007] = {0};
string s;
int dp[300007][29];
bool nocyc(int x) {
  bool b = true;
  for (auto nxt : adj[x]) {
    if (color[nxt] == 0)
      color[nxt] = 1, b &= nocyc(nxt);
    else if (color[nxt] == 1) {
      return 0;
    }
  }
  color[x] = 2;
  return b;
}
int dfs(int nod, int c) {
  if (adj[nod].size() == 0)
    return s[nod] - 'a' == c ? dp[nod][c] = 1 : dp[nod][c] = 0;
  if (dp[nod][c] != -1) return dp[nod][c];
  int greed = 0;
  for (auto nxt : adj[nod]) {
    greed = max(greed, dfs(nxt, c));
  }
  return s[nod] - 'a' == c ? dp[nod][c] = greed + 1 : dp[nod][c] = greed;
}
int main() {
  memset(dp, -1, sizeof dp);
  cin >> n >> m;
  adj.resize(n + 3);
  cin >> s;
  s = "0" + s;
  int x, y;
  for (int i = 0; i < m; ++i) {
    scanf("%d%d", &x, &y);
    adj[x].push_back(y);
  }
  for (int r = 1; r <= n; ++r) {
    if (!nocyc(r)) return puts("-1"), 0;
  }
  int ans = 0;
  for (int c = 0; c < 26; ++c) {
    for (int i = 1; i <= n; ++i) {
      ans = max(ans, dfs(i, c));
    }
  }
  cout << ans;
}
