#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  string s;
  cin >> s;
  s = '#' + s;
  int dp[n + 1][26], d[n + 1];
  queue<int> q;
  memset(dp, 0, sizeof(dp));
  vector<int> v[n + 1];
  memset(d, 0, sizeof(d));
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    v[a].push_back(b);
    d[b]++;
  }
  for (int i = 1; i <= n; i++) {
    if (!d[i]) {
      q.push(i);
      dp[i][s[i] - 'a'] = 1;
    }
  }
  int r = n;
  while (!q.empty()) {
    r--;
    int t = q.front();
    q.pop();
    for (auto i : v[t]) {
      for (int j = 0; j < 26; j++) {
        dp[i][j] = max(dp[i][j], dp[t][j] + (s[i] - 'a' == j));
      }
      d[i]--;
      if (!d[i]) {
        q.push(i);
      }
    }
  }
  if (r) {
    cout << -1 << "\n";
  } else {
    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;
  }
  return 0;
}
