#include <bits/stdc++.h>
using namespace std;
inline void fast() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
const int N = (int)(3e5) + 5;
int n, m, x, y;
vector<int> adj[N];
int in[N];
int dp[N][26];
int mx = 0;
string s;
int main() {
  scanf("%d %d", &n, &m);
  cin >> s;
  for (int i = 1; i <= m; i++) {
    scanf("%d %d", &x, &y);
    x--;
    y--;
    adj[x].push_back(y);
    in[y] += 1;
  }
  queue<int> q;
  for (int i = 0; i < n; i++) {
    if (in[i] == 0) {
      dp[i][(s[i] - 'a')] = 1;
      q.push(i);
    }
  }
  while (!q.empty()) {
    int v = q.front();
    q.pop();
    for (int i = 0; i < 26; i++) {
      mx = max(mx, dp[v][i]);
    }
    for (auto it : adj[v]) {
      in[it]--;
      for (int i = 0; i < 26; i++) {
        dp[it][i] = max(dp[it][i], dp[v][i] + ((s[it] - 'a') == i));
      }
      if (in[it] == 0) {
        q.push(it);
      }
    }
  }
  bool fl = 0;
  for (int i = 0; i < n; i++) {
    if (in[i] != 0) fl = 1;
  }
  if (fl == 1) {
    cout << "-1";
    return 0;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 26; j++) {
      mx = max(mx, dp[i][j]);
    }
  }
  printf("%d", mx);
}
