#include <bits/stdc++.h>
using namespace std;
int n, m, ans;
int p[300005], f[300005][26];
vector<long long> adj[300005];
string s;
queue<int> q;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m >> s;
  while (m--) {
    int u, v;
    cin >> u >> v;
    adj[u].push_back(v);
    p[v]++;
  }
  for (long long i = 1; i < n + 1; ++i)
    if (!p[i]) q.push(i);
  while (!q.empty()) {
    int x = q.front();
    q.pop();
    n--;
    f[x][s[x - 1] - 'a']++;
    for (long long i = 0; i < 26; ++i)
      if (ans < f[x][i]) ans = f[x][i];
    for (long long i = 0; i < (long long)adj[x].size(); ++i) {
      int y = adj[x][i];
      for (long long j = 0; j < 26; ++j) f[y][j] = max(f[y][j], f[x][j]);
      p[y]--;
      if (!p[y]) q.push(y);
    }
  }
  if (n > 0) ans = -1;
  cout << ans;
  return 0;
}
