#include <bits/stdc++.h>
using namespace std;
vector<int> G[300010];
int visit[300010];
int a[300010][27];
char s[300010];
int ans;
bool dfs(int k) {
  visit[k] = -1;
  for (int i = 0; i < G[k].size(); i++) {
    if (visit[G[k][i]] == -1) return 0;
    if (!visit[G[k][i]])
      if (!dfs(G[k][i])) return 0;
    for (int j = 0; j < 26; j++) {
      a[k][j] = max(a[k][j], a[G[k][i]][j]);
    }
  }
  ans = max(++a[k][s[k] - 'a'], ans);
  return visit[k] = 1;
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  memset(visit, 0, sizeof(visit));
  scanf("%s", s + 1);
  int x, y;
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &x, &y);
    G[x].push_back(y);
  }
  for (int i = 1; i <= n; i++) {
    if (!visit[i] && !dfs(i)) {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << ans << endl;
}
