#include <bits/stdc++.h>
using namespace std;
void maximiza(int &a, int b) { a = max(a, b); }
const int limite = 500000;
int n, m;
vector<int> g[limite];
vector<int> ginv[limite];
int maximo[limite][26];
int valor[limite];
int aridad[limite];
queue<int> q;
int sol;
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    char c;
    cin >> c;
    valor[i] = c - 'a';
  }
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    g[u].push_back(v);
    ginv[v].push_back(u);
    aridad[u]++;
  }
  for (int u = 1; u <= n; u++) {
    if (aridad[u] == 0) {
      q.push(u);
      maximo[u][valor[u]] = 1;
    }
  }
  while (not q.empty()) {
    int u = q.front();
    q.pop();
    {
      vector<int> &ar = g[u];
      for (int i = 0; i < int(ar.size()); i++) {
        int v = ar[i];
        for (int c = 0; c < 26; c++)
          maximiza(maximo[u][c], maximo[v][c] + (c == valor[u]));
      }
    }
    {
      vector<int> &ar = ginv[u];
      for (int i = 0; i < int(ar.size()); i++) {
        int v = ar[i];
        aridad[v]--;
        if (aridad[v] == 0) q.push(v);
      }
    }
  }
  for (int u = 1; u <= n; u++) {
    if (aridad[u]) {
      cout << -1 << endl;
      exit(0);
    }
  }
  for (int u = 1; u <= n; u++)
    for (int c = 0; c < 26; c++) maximiza(sol, maximo[u][c]);
  cout << sol << endl;
}
