#include <bits/stdc++.h>
using namespace std;
vector<int> adj[300005];
int indeg[300005];
queue<int> q;
int dp[300005][26], ma = 1;
string s;
int n, m, x, y, cnt = 0;
bool co = 1;
int main() {
  cin >> n >> m;
  cin >> s;
  for (int i = 0; i < m; i++) {
    cin >> x >> y;
    x--;
    y--;
    indeg[y]++;
    adj[x].push_back(y);
  }
  for (int i = 0; i < n; i++) {
    if (indeg[i] == 0) {
      q.push(i);
      dp[i][s[i] - 'a']++;
    }
  }
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int v : adj[u]) {
      for (int j = 0; j < 26; j++) {
        dp[v][j] = max(dp[v][j], dp[u][j] + (s[v] - 'a' == j));
      }
      indeg[v]--;
      if (indeg[v] == 0) q.push(v);
    }
    cnt++;
  }
  if (cnt < n) {
    cout << "-1\n";
  } else {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < 26; j++) {
        if (dp[i][j] > ma) ma = dp[i][j];
      }
    }
    cout << ma << "\n";
  }
}
