#include <bits/stdc++.h>
using namespace std;
int fn(int N, int M, string S, int *x, int *y) {
  vector<vector<int>> adj(N);
  vector<int> inDeg(N);
  for (int i = 0; i < M; i++) {
    int x1, y1;
    x1 = x[i], y1 = y[i];
    x1--, y1--;
    adj[x1].push_back(y1);
    inDeg[y1]++;
  }
  vector<int> q;
  q.reserve(N);
  for (int i = 0; i < N; i++) {
    if (inDeg[i] == 0) q.push_back(i);
  }
  vector<array<int, 26>> dp(N, array<int, 26>({
                                   0,
                               }));
  int ans = 0;
  for (int z = 0; z < int(q.size()); z++) {
    int cur = q[z];
    ans = max(ans, ++dp[cur][S[cur] - 'a']);
    for (int nxt : adj[cur]) {
      for (int v = 0; v < 26; v++) {
        dp[nxt][v] = max(dp[nxt][v], dp[cur][v]);
      }
      if (!--inDeg[nxt]) {
        q.push_back(nxt);
      }
    }
  }
  if (q.size() >= N) {
    return ans;
  } else {
    return -1;
  }
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(nullptr);
  int N, M;
  cin >> N >> M;
  string S;
  cin >> S;
  int arr1[M], arr2[M];
  for (int i = 0; i < M; i++) {
    cin >> arr1[i] >> arr2[i];
  }
  cout << fn(N, M, S, arr1, arr2) << '\n';
  return 0;
}
