#include <bits/stdc++.h>
using namespace std;
int n;
vector<vector<int> > adj;
vector<int> ord;
vector<int> visited;
bool dfs(int u) {
  visited[u] = -1;
  for (int v : adj[u]) {
    if (visited[v] == 0) {
      if (!dfs(v)) {
        return false;
      }
    } else if (visited[v] == -1) {
      return false;
    }
  }
  visited[u] = 1;
  ord.push_back(u);
  return true;
}
bool t_sort() {
  for (int i = 0; i < n; i++) {
    if (!visited[i]) {
      if (!dfs(i)) {
        return false;
      }
    }
  }
  reverse(ord.begin(), ord.end());
  return true;
}
int main() {
  ios_base::sync_with_stdio(0);
  int m;
  cin >> n >> m;
  string s;
  cin >> s;
  adj.resize(n);
  visited.resize(n);
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    adj[u].push_back(v);
  }
  if (!t_sort()) {
    cout << "-1\n";
    return 0;
  }
  vector<vector<int> > dp(n, vector<int>(26));
  for (int u : ord) {
    dp[u][s[u] - 'a']++;
    for (int v : adj[u]) {
      for (int j = 0; j < 26; j++) {
        dp[v][j] = max(dp[v][j], dp[u][j]);
      }
    }
  }
  int res = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 26; j++) {
      res = max(dp[i][j], res);
    }
  }
  cout << res << '\n';
}
