#include <bits/stdc++.h>
using namespace std;
int const maxn = 1e6 + 10;
struct bkn {
  int next, to;
} e[maxn * 2];
stack<int> st;
int tot = 1, head[maxn], vis[maxn], dfn[maxn], low[maxn], cnt, scc;
int q[maxn];
void add(int hg[], bkn e[], int x, int y) {
  e[tot].to = y, e[tot].next = hg[x], hg[x] = tot++;
}
void tarjan(int x) {
  low[x] = dfn[x] = ++cnt;
  st.push(x);
  vis[x] = 1;
  for (int i = head[x]; i; i = e[i].next) {
    int y = e[i].to;
    if (!dfn[y])
      tarjan(y), low[x] = min(low[x], low[y]);
    else if (vis[y])
      low[x] = min(low[x], low[y]);
  }
  if (low[x] == dfn[x]) {
    scc++;
    while (1) {
      int y = st.top();
      st.pop();
      vis[y] = 0;
      if (x == y) break;
    }
  }
}
void dfs(int x) {
  vis[x] = 1;
  for (int i = head[x]; i; i = e[i].next) {
    int y = e[i].to;
    if (!vis[y]) dfs(y);
  }
  q[++cnt] = x;
}
char s[300300];
int dp[300300][30];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  scanf("%s", s);
  int ok = 1;
  for (int i = 1; i <= m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    if (x == y) ok = 0;
    add(head, e, x, y);
  }
  if (ok == 0) {
    printf("-1\n");
    return 0;
  }
  for (int i = 1; i <= n; i++) {
    if (!dfn[i]) tarjan(i);
  }
  if (scc != n) {
    printf("-1\n");
    return 0;
  }
  cnt = 0;
  for (int i = 1; i <= scc; i++) {
    if (!vis[i]) dfs(i);
  }
  int ans = 0;
  for (int i = cnt; i >= 1; i--) {
    int x = q[i];
    int cc = (int)s[x - 1];
    for (int i = 'a' - 97; i <= 'z' - 97; i++)
      dp[x][i] = max(dp[x][i], cc == i + 97 ? 1 : 0), ans = max(ans, dp[x][i]);
    for (int i = head[x]; i; i = e[i].next) {
      int y = e[i].to;
      int dd = (int)s[y - 1];
      for (int j = 'a' - 97; j <= 'z' - 97; j++) {
        dp[y][j] = max(dp[y][j], dp[x][j] + (dd == j + 97 ? 1 : 0));
      }
    }
  }
  cout << ans << endl;
}
