#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
vector<int> g[N];
int val[N], deg[N], dp[N][26];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m;
  cin >> n >> m;
  string s;
  cin >> s;
  for (int i = 0; i < s.length(); i++) {
    val[i + 1] = s[i] - 'a';
  }
  while (m--) {
    int u, v;
    cin >> u >> v;
    g[u].push_back(v);
    deg[v]++;
  }
  queue<int> q;
  for (int i = 1; i <= n; i++) {
    if (deg[i] == 0) {
      q.push(i);
      dp[i][val[i]]++;
    }
  }
  int cnt = 0, ans = 0;
  while (!q.empty()) {
    int node = q.front();
    q.pop();
    cnt++;
    for (int i = 0; i < g[node].size(); i++) {
      for (int j = 0; j < 26; j++) {
        dp[g[node][i]][j] =
            max(dp[g[node][i]][j], dp[node][j] + (val[g[node][i]] == j));
        ans = max(ans, dp[g[node][i]][j]);
      }
      deg[g[node][i]]--;
      if (deg[g[node][i]] == 0) {
        q.push(g[node][i]);
      }
    }
    if (cnt > n) {
      break;
    }
  }
  if (cnt != n) {
    cout << -1;
    return 0;
  }
  cout << ans;
  return 0;
}
