#include <bits/stdc++.h>
using namespace std;
int vals[300010][30];
vector<int> edges[300010];
int indeg[300010];
vector<int> toVis;
int N, E;
char str[300010];
int main() {
  scanf("%d %d", &N, &E);
  fgets(str, 300009, stdin);
  fgets(str, 300009, stdin);
  for (int i = 0; i < E; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    a--;
    b--;
    edges[a].push_back(b);
    indeg[b]++;
  }
  for (int i = 0; i < N; i++) {
    if (indeg[i] == 0) toVis.push_back(i);
  }
  int visno = 0;
  while (visno < toVis.size()) {
    int cur = toVis[visno];
    vals[cur][str[cur] - 'a']++;
    int edgesz = edges[cur].size();
    for (int i = 0; i < edgesz; i++) {
      int to = edges[cur][i];
      for (int j = 0; j < 26; j++) {
        if (vals[cur][j] > vals[to][j]) vals[to][j] = vals[cur][j];
      }
      indeg[to]--;
      if (indeg[to] == 0) toVis.push_back(to);
    }
    visno++;
  }
  if (visno != N) {
    printf("-1\n");
    return 0;
  }
  int bestval = 0;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < 26; j++) {
      if (vals[i][j] > bestval) bestval = vals[i][j];
    }
  }
  printf("%d\n", bestval);
  return 0;
}
