#include <bits/stdc++.h>
using namespace std;
const int MAXL(3 * 1e5);
const int INF(0x3f3f3f3f);
const int mod(1e9 + 7);
int dir[4][2] = {{-1, 0}, {1, 0}, {0, 1}, {0, -1}};
char str[MAXL + 50];
int dp[MAXL + 50][30];
int num[MAXL + 50];
int n, m;
struct node {
  int ed;
} nod;
vector<node> v[MAXL + 50];
int toposort() {
  queue<int> q;
  for (int i = 1; i <= n; i++) {
    if (!num[i]) {
      q.push(i);
      dp[i][str[i] - 'a']++;
    }
  }
  int cnt = 0;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    cnt++;
    for (int i = 0; i < v[u].size(); i++) {
      int t = v[u][i].ed;
      num[t]--;
      if (!num[t]) q.push(t);
      for (int j = 0; j < 26; j++)
        dp[t][j] = (dp[t][j] > dp[u][j] + (str[t] - 'a' == j ? 1 : 0)
                        ? dp[t][j]
                        : dp[u][j] + (str[t] - 'a' == j ? 1 : 0));
    }
  }
  if (cnt < n) return -1;
  int ans = 0;
  for (int i = 1; i <= n; i++)
    for (int j = 0; j < 26; j++) ans = (ans > dp[i][j] ? ans : dp[i][j]);
  return ans;
}
int main() {
  memset(dp, 0, sizeof(dp));
  memset(num, 0, sizeof(num));
  scanf("%d %d", &n, &m);
  scanf("%s", str + 1);
  for (int i = 1; i <= m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    num[y]++;
    nod.ed = y;
    v[x].push_back(nod);
  }
  int ans = toposort();
  printf("%d\n", ans);
}
