#include <bits/stdc++.h>
using namespace std;
vector<long long int> v[300005];
string h;
stack<long long int> s;
set<long long int> st;
long long int c[300005][26], a[300005], x, y, n, m, res = 0;
bool vis[300005];
void dfs(int pos) {
  vis[pos] = true;
  st.insert(pos);
  for (auto u : v[pos])
    if (st.find(u) != st.end()) {
      cout << -1 << "\n";
      exit(0);
    } else if (!vis[u])
      dfs(u);
  st.erase(pos);
  s.push(pos);
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m >> h;
  for (int i = 0; i < h.size(); i++) a[i + 1] = h[i] - 'a';
  for (int i = 0; i < m; i++) cin >> x >> y, v[x].push_back(y);
  for (int i = 1; i <= n; i++)
    if (!vis[i]) dfs(i);
  while (!s.empty()) {
    x = s.top();
    s.pop();
    c[x][a[x]]++;
    for (auto u : v[x])
      for (int i = 0; i < 26; i++) c[u][i] = max(c[u][i], c[x][i]);
    for (int i = 0; i < 26; i++) res = max(res, c[x][i]);
  }
  cout << res << "\n";
  return 0;
}
