#include <bits/stdc++.h>
using namespace std;
const long long int N = 3e5 + 5;
const long long int INF = 1e18;
const long long int mod = 1e9 + 7;
string s;
long long int dp[N][27];
long long int n, m, u, v;
vector<long long int> g[N];
long long int vis[N], maxi = 0, col[N], visx[N];
void DFS(long long int cur, long long int par) {
  vis[cur] = 1;
  dp[cur][int(s[cur - 1]) - 97]++;
  for (long long int j : g[cur]) {
    if (!vis[j]) {
      DFS(j, cur);
    }
    for (long long int i = 0; i < 26; i++) {
      if (i == int(s[cur - 1]) - 97)
        dp[cur][i] = max(dp[cur][i], dp[j][i] + 1);
      else
        dp[cur][i] = max(dp[cur][i], dp[j][i]);
    }
  }
  for (long long int i = 0; i < 26; i++) {
    maxi = max(maxi, dp[cur][i]);
  }
}
bool DFSX(long long int cur, long long int par) {
  col[cur] = -1;
  for (long long int i : g[cur]) {
    if (col[i] == -1) {
      return true;
    }
    if (col[i] == 0 && DFSX(i, cur)) {
      return true;
    }
  }
  col[cur] = 1;
  return false;
}
int main() {
  cin >> n >> m;
  cin >> s;
  while (m--) {
    cin >> u >> v;
    g[u].push_back(v);
  }
  for (long long int i = 1; i <= n; i++) {
    if (!visx[i]) {
      if (DFSX(i, -1)) {
        cout << -1 << endl;
        exit(0);
      }
    }
  }
  for (long long int i = 1; i <= n; i++) {
    if (!vis[i]) {
      DFS(i, 0);
    }
  }
  cout << maxi << endl;
}
