#include <bits/stdc++.h>
using namespace std;
int n, m;
int dp[303030][30];
int u, v;
int in[303030];
vector<int> adj[303030];
char s[303030];
int main() {
  scanf("%d %d", &n, &m);
  scanf("%s", s);
  for (int i = 0; i < m; ++i) {
    scanf("%d %d", &u, &v);
    --u;
    --v;
    adj[u].push_back(v);
    in[v]++;
  }
  queue<int> q;
  for (int i = 0; i < n; ++i) {
    if (in[i] == 0) {
      q.push(i);
    }
  }
  int cnt = 0;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    ++cnt;
    dp[u][s[u] - 'a']++;
    for (int v : adj[u]) {
      if (--in[v] == 0) {
        q.push(v);
      }
      for (int i = 0; i < 26; ++i) {
        dp[v][i] = max(dp[v][i], dp[u][i]);
      }
    }
  }
  if (cnt == n) {
    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);
  } else {
    printf("-1\n");
  }
  return 0;
}
