#include <bits/stdc++.h>
using namespace std;
struct note {
  int y, next;
} e[300001];
int mapp[300001];
int dist[300001];
long long ans = 0;
bool vist[300001], in[300001];
char s[300001];
long long tj[26][300001];
queue<int> eq;
int t = 0;
void calc(int x, int y) {
  for (int i = 0; i < 26; i++) {
    if (s[y] - 'a' == i)
      tj[i][y] = max(tj[i][y], tj[i][x] + 1);
    else
      tj[i][y] = max(tj[i][x], tj[i][y]);
    if (tj[i][y] > ans) ans = tj[i][y];
  }
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  scanf("%s", s + 1);
  int all = 0;
  memset(mapp, 0, sizeof(mapp));
  for (int i = 1; i <= m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    e[++all].y = y;
    e[all].next = mapp[x];
    mapp[x] = all;
    dist[y]++;
  }
  bool flag = false;
  int sum = 0;
  for (int i = 1; i <= n; i++) {
    tj[s[i] - 'a'][i] = 1;
    if (dist[i] == 0) eq.push(i);
  }
  while (!eq.empty()) {
    sum++;
    int x = eq.front();
    eq.pop();
    int nowe = mapp[x];
    while (nowe) {
      int y = e[nowe].y;
      calc(x, y);
      dist[y]--;
      if (!dist[y]) eq.push(y);
      nowe = e[nowe].next;
    }
  }
  if (sum < n)
    printf("-1\n");
  else
    printf("%I64d\n", ans);
  return 0;
}
