#include <bits/stdc++.h>
using namespace std;
const long long M = 1e9 + 7;
vector<vector<int> > g;
int deg[300005];
vector<int> toposort;
int dp[300005];
void solve() {
  int n, m;
  cin >> n >> m;
  string s;
  cin >> s;
  g.resize(n + 1);
  for (int i = 0; i < m; i++) {
    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]) q.push(i);
  int cnt = 0;
  while (!q.empty()) {
    cnt++;
    int x = q.front();
    toposort.push_back(x);
    q.pop();
    for (int y : g[x]) {
      deg[y]--;
      if (!deg[y]) q.push(y);
    }
  }
  if (cnt < n) {
    cout << -1;
    return;
  }
  int ans = 0;
  for (char ch = 'a'; ch <= 'z'; ch++) {
    memset(dp, 0, sizeof(dp));
    for (int x : toposort) {
      if (s[x - 1] == ch) dp[x]++;
      for (int y : g[x]) {
        dp[y] = max(dp[y], dp[x]);
      }
      ans = max(ans, dp[x]);
    }
  }
  cout << ans << "\n";
}
int main() {
  int t = 1;
  while (t--) solve();
  return 0;
}
