#include <bits/stdc++.h>
using namespace std;
vector<long long> vis(3e5 + 1, 0), vis1(3e5 + 1, 0);
long long n;
string s;
vector<vector<long long> > v2(3e5 + 1, vector<long long>(26, 0));
vector<vector<long long> > v;
bool flagc = false;
void dfs(long long x) {
  vis[x] = 1;
  for (auto it : v[x]) {
    if (vis[it] == 1) flagc = true;
    if (vis[it] == 0) dfs(it);
  }
  vis[x] = 2;
}
bool checkcycle() {
  for (int i = 1; i <= n; i++)
    if (vis[i] == 0) dfs(i);
}
long long ans = 1;
void tpl(long long x) {
  vis1[x] = 1;
  for (auto it : v[x]) {
    if (vis1[it] == 0) tpl(it);
  }
  for (auto it : v[x]) {
    for (int i = 0; i < 26; i++) {
      v2[x][i] = max(v2[x][i], v2[it][i]);
      ans = max(ans, v2[x][i]);
    }
  }
  v2[x][s[x - 1] - 'a']++;
  ans = max(ans, v2[x][s[x - 1] - 'a']);
}
void topo() {
  for (int i = 1; i <= n; i++)
    if (vis1[i] == 0) tpl(i);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long f, q, i, x, z, y, j, w, l, t, m, k;
  long double dd, aa;
  cin >> n >> m;
  cin >> s;
  v.resize(n + 1);
  for (i = 0; i < m; i++) {
    cin >> x >> y;
    if (x == y) {
      cout << "-1" << endl;
      return 0;
    }
    v[x].push_back(y);
  }
  checkcycle();
  if (flagc) {
    cout << "-1" << endl;
    return 0;
  }
  topo();
  cout << ans << endl;
  return 0;
}
