#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
const int maxn = 300000 + 5;
const int INF = 0x3f3f3f3f;
const int P = 1000000007;
const double PI = acos(-1.0);
template <typename T>
inline T read(T &x) {
  x = 0;
  int _f = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') _f |= (ch == '-'), ch = getchar();
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  return x = _f ? -x : x;
}
template <class T1, class T2>
inline void gmax(T1 &a, T2 b) {
  if (b > a) a = b;
}
template <class T1, class T2>
inline void gmin(T1 &a, T2 b) {
  if (b < a) a = b;
}
int i, j, n, m, u, v, ans, ret, dp[maxn], in[maxn];
bool vis[maxn];
vector<int> G[maxn];
char s[maxn];
void umax(int &a, int b) {
  if (a < b) a = b;
}
bool topsort() {
  queue<int> Q;
  for (int i = 1; i <= n; i++)
    if (in[i] == 0) Q.push(i);
  int sum = 0, i;
  while (!Q.empty()) {
    int x = Q.front();
    Q.pop();
    sum++;
    for (i = 0; i < (int)G[x].size(); i++) {
      int v = G[x][i];
      if (--in[v] == 0) Q.push(v);
    }
  }
  return sum == n;
}
void dfs(int u, int sign) {
  if (vis[u]) return;
  for (int i = 0; i < (int)G[u].size(); i++) {
    int v = G[u][i];
    dfs(v, sign);
    umax(dp[u], dp[v]);
  }
  dp[u] += (((s[u] - 'a') == sign) ? 1 : 0);
  umax(ans, dp[u]);
  vis[u] = true;
}
int main() {
  read(n), read(m);
  scanf("%s", s + 1);
  for (i = 1; i <= m; i++) {
    read(u), read(v);
    G[u].push_back(v);
    in[v]++;
  }
  if (!topsort()) return puts("-1"), 0;
  for (i = 0; i < 26; i++) {
    memset(dp, 0, sizeof(dp));
    memset(vis, false, sizeof(vis));
    for (j = 1; j <= n; j++)
      if (!vis[j]) {
        dfs(j, i);
      }
  }
  printf("%d\n", ans);
  return 0;
}
