#include <bits/stdc++.h>
using namespace std;
const int maxn = 300005;
const long long mod = 1e9 + 7;
const long long INF = 1e9;
const double eps = 1e-9;
int n, m;
int degree[maxn];
char s[maxn];
int dp[maxn];
vector<int> vec[maxn];
vector<int> mp;
bool check() {
  mp.clear();
  queue<int> q;
  for (int i = 1; i <= n; i++) {
    if (degree[i] == 0) q.push(i);
  }
  while (q.size()) {
    int u = q.front();
    q.pop();
    mp.push_back(u);
    for (int i = 0; i < vec[u].size(); i++) {
      degree[vec[u][i]]--;
      if (degree[vec[u][i]] == 0) q.push(vec[u][i]);
    }
  }
  return mp.size() == n;
}
int solve(int x) {
  memset((dp), (0), sizeof(dp));
  char c = x + 'a';
  int cnt = 0;
  for (int i = mp.size() - 1; i >= 0; i--) {
    int u = mp[i];
    for (int j = 0; j < vec[u].size(); j++) {
      dp[u] = max(dp[u], dp[vec[u][j]]);
    }
    if (s[u - 1] == c) dp[u]++;
    cnt = max(cnt, dp[u]);
  }
  return cnt;
}
int main() {
  while (~scanf("%d%d", &n, &m)) {
    for (int i = 1; i <= n; i++) vec[i].clear();
    scanf("%s", s);
    memset((degree), (0), sizeof(degree));
    for (int i = 0; i < m; i++) {
      int x, y;
      scanf("%d%d", &x, &y);
      vec[x].push_back(y);
      degree[y]++;
    }
    if (!check()) {
      puts("-1");
      continue;
    }
    int ans = 0;
    for (int i = 0; i < 26; i++) {
      ans = max(ans, solve(i));
    }
    printf("%d\n", ans);
  }
}
