#include <bits/stdc++.h>
using namespace std;
vector<long long int> adj[300005];
bool visit[300005];
bool cyc[300005];
long long int dp[300005][26], fl = 0;
string s;
void dfs(long long int x) {
  visit[x] = true;
  cyc[x] = true;
  for (auto it : adj[x]) {
    if (cyc[it]) fl = 1;
    if (!visit[it]) dfs(it);
  }
  for (auto it : adj[x]) {
    for (long long int i = 0; i < 26; i++) {
      dp[x][i] = max(dp[x][i], dp[it][i]);
    }
  }
  long long int p = s[x - 1] - 'a';
  dp[x][p]++;
  cyc[x] = false;
}
void solve() {
  long long int n, m;
  cin >> n >> m;
  cin >> s;
  for (long long int i = 0; i < m; i++) {
    long long int x, y;
    cin >> x >> y;
    adj[x].push_back(y);
  }
  for (long long int i = 0; i < 300004; i++) {
    visit[i] = false;
    cyc[i] = false;
    for (long long int j = 0; j < 26; j++) dp[i][j] = 0;
  }
  for (long long int i = 1; i <= n; i++) {
    if (!visit[i]) {
      dfs(i);
    }
  }
  if (fl) {
    cout << -1 << endl;
    return;
  }
  long long int ans = 0;
  for (long long int i = 1; i < n + 1; i++) {
    for (long long int j = 0; j < 26; j++) ans = max(ans, dp[i][j]);
  }
  cout << ans << endl;
}
signed main() {
  ios_base::sync_with_stdio(false);
  long long int t = 1;
  while (t--) solve();
  return 0;
}
