#include <bits/stdc++.h>
using namespace std;
const int L = 3e5 + 10;
vector<int> ad[L];
int dp[L][26];
int ans = 0;
int in[L];
char s[L];
long long int n, m;
vector<int> tp;
bool topo() {
  queue<int> q;
  for (int i = 1; i <= n; i++) {
    if (in[i] == 0) {
      q.push(i);
    }
  }
  int cnt = 0;
  while (!q.empty()) {
    int u = q.front();
    tp.push_back(u);
    q.pop();
    ++cnt;
    for (int v : ad[u]) {
      if (--in[v] == 0) {
        q.push(v);
      }
    }
  }
  if (cnt == n)
    return true;
  else
    return false;
}
int main() {
  scanf("%lld %lld %s", &n, &m, s + 1);
  int u, v;
  while (m--) {
    scanf("%d%d", &u, &v);
    ad[u].push_back(v);
    in[v]++;
  }
  if (!topo()) {
    printf("-1\n");
    exit(0);
  }
  for (int i = n - 1; i >= 0; i--) {
    u = tp[i];
    for (int v : ad[u]) {
      for (int j = 0; j < 26; j++) {
        dp[u][j] = max(dp[v][j], dp[u][j]);
        ans = max(ans, dp[u][j]);
      }
    }
    dp[u][s[u] - 'a']++;
    ans = max(ans, dp[u][s[u] - 'a']);
  }
  printf("%d\n", ans);
  return 0;
}
