#include <bits/stdc++.h>
using namespace std;
int n, m, ans;
char s[400100];
int sum = 0, head[400100], a[400100][27];
struct Node {
  int to, next;
} e[400100];
int d[400100];
void insert(int u, int v) {
  e[++sum].to = v;
  e[sum].next = head[u];
  head[u] = sum;
  d[v]++;
}
stack<int> vec;
void init() {
  cin >> n >> m;
  cin >> s + 1;
  for (int i = 1; i <= n; i++) a[i][s[i] - 'a'] = 1;
  for (int i = 1; i <= m; i++) {
    int tx, ty;
    scanf("%d%d", &tx, &ty);
    insert(tx, ty);
  }
}
int main() {
  init();
  int cnt = 0;
  for (int i = 1; i <= n; i++)
    if (d[i] == 0) vec.push(i);
  while (!vec.empty()) {
    int v = vec.top();
    vec.pop();
    for (int i = head[v]; i; i = e[i].next) {
      d[e[i].to]--;
      if (d[e[i].to] == 0) vec.push(e[i].to);
      for (int j = 0; j < 26; j++)
        if (j != s[e[i].to] - 'a')
          a[e[i].to][j] = max(a[e[i].to][j], a[v][j]);
        else
          a[e[i].to][j] = max(a[e[i].to][j], a[v][j] + 1);
    }
    cnt++;
  }
  if (cnt < n)
    cout << -1 << endl;
  else {
    ans = 0;
    for (int i = 1; i <= n; i++)
      for (int j = 0; j < 26; j++) ans = max(ans, a[i][j]);
    cout << ans << endl;
  }
  return 0;
}
