#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m;
  string input;
  cin >> n >> m;
  vector<vector<int> > nodes(n, vector<int>(26));
  vector<vector<int> > G(n);
  int indegree[n];
  memset(indegree, 0, sizeof(indegree));
  cin >> input;
  for (int j = 0; j < n; j++) {
    int ascii = input[j] - 'a';
    nodes[j][ascii]++;
  }
  for (int i = 0; i < m; i++) {
    int s, e;
    cin >> s >> e;
    G[s - 1].push_back(e - 1);
    indegree[e - 1]++;
  }
  queue<int> q;
  for (int i = 0; i < n; i++) {
    if (indegree[i] == 0) {
      q.push(i);
    }
  }
  int cycle = 0;
  int answer = 0;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    cycle++;
    if (G[u].size() == 0) {
      int curr = -1;
      for (int i = 0; i < 26; i++) {
        if (nodes[u][i] > curr) {
          curr = nodes[u][i];
        }
      }
      if (curr > answer) {
        answer = curr;
      }
    }
    for (int nodeIndex : G[u]) {
      for (int j = 0; j < 26; j++) {
        if (j == input[nodeIndex] - 'a') {
          if (nodes[nodeIndex][j] < nodes[u][j] + 1) {
            nodes[nodeIndex][j] = nodes[u][j] + 1;
          }
        } else {
          if (nodes[nodeIndex][j] < nodes[u][j]) {
            nodes[nodeIndex][j] = nodes[u][j];
          }
        }
      }
      indegree[nodeIndex]--;
      if (indegree[nodeIndex] == 0) {
        q.push(nodeIndex);
      }
    }
  }
  if (cycle != n) {
    cout << -1 << '\n';
  } else {
    cout << answer << '\n';
  }
}
