#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 10;
char s[maxn];
int n, m, x, y;
int dp[maxn][26];
int ans;
struct Edge {
  int to, nxt;
} edge[maxn];
int head[maxn], now;
void add(int u, int v) {
  edge[now].to = v;
  edge[now].nxt = head[u];
  head[u] = now++;
}
int dfs(int u, int c) {
  if (dp[u][c] == -2) {
    puts("-1");
    exit(0);
  }
  if (dp[u][c] != -1) return dp[u][c];
  dp[u][c] = -2;
  int ret = 0;
  for (int i = head[u]; ~i; i = edge[i].nxt) {
    int to = edge[i].to;
    ret = max(ret, dfs(to, c));
  }
  ret += s[u] - 'a' == c;
  return dp[u][c] = ret;
}
int main(void) {
  scanf("%d", &n), scanf("%d", &m), scanf("%s", s + 1);
  memset(head, -1, sizeof head);
  while (m--) {
    scanf("%d", &x), scanf("%d", &y);
    add(x, y);
  }
  memset(dp, -1, sizeof dp);
  int ans = 0;
  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j < 26; ++j) ans = max(ans, dfs(i, j));
  }
  printf("%d\n", ans);
}
