#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<int> adj[300005];
int dp[300005][28];
char s[300005];
bool visited[300005];
bool visited1[300005];
void sol(int x) {
  if (visited[x] == true) {
    puts("-1");
    exit(0);
  }
  visited[x] = true;
  for (int i : adj[x]) {
    if (!visited1[i]) sol(i);
  }
  for (int i : adj[x]) {
    for (int j = 0; j < 28; j++) {
      dp[x][j] = max(dp[x][j], dp[i][j]);
    }
  }
  dp[x][s[x] - 'a']++;
  visited[x] = false;
  visited1[x] = true;
}
int main() {
  scanf("%d %d %s", &n, &m, s);
  for (int i = 0; i < m; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    adj[a - 1].push_back(b - 1);
  }
  for (int i = 0; i < n; i++) {
    if (!visited1[i]) sol(i);
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 26; j++) {
      ans = max(ans, dp[i][j]);
    }
  }
  printf("%d\n", ans);
  return 0;
}
