#include <bits/stdc++.h>
using namespace std;
const int N = int(3e5) + 10;
const int INF = int(2e9) + 5;
const long long INF64 = 1e18;
int dp[N][26], in_degree[N];
vector<int> adj[N];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  string s;
  cin >> s;
  for (int i = 1; i <= m; i++) {
    int x, y;
    cin >> x >> y;
    adj[x].push_back(y);
    in_degree[y]++;
  }
  queue<int> q;
  for (int i = 1; i <= n; i++) {
    if (in_degree[i] == 0) {
      dp[i][s[i - 1] - 'a'] = 1;
      q.push(i);
    }
  }
  int cnt = 0;
  while (!q.empty()) {
    int t = q.front();
    q.pop();
    cnt++;
    for (auto x : adj[t]) {
      for (int i = 0; i < 26; i++) {
        int y = (s[x - 1] - 'a') == i;
        dp[x][i] = max(dp[x][i], dp[t][i] + y);
      }
      in_degree[x]--;
      if (in_degree[x] == 0) q.push(x);
    }
  }
  if (cnt == n) {
    int ans = 0;
    for (int i = 1; i <= n; i++) {
      for (int j = 0; j < 26; j++) ans = max(ans, dp[i][j]);
    }
    cout << ans << endl;
  } else {
    cout << -1 << endl;
  }
  return 0;
}
