#include <bits/stdc++.h>
using namespace std;
vector<int> v[300001];
int cou[300001][26];
int cur_vi[300001];
string s;
vector<int> dp(300001, -1);
void dfs(int so, int *p) {
  if (dp[so] == -1 && (*p != 100000000)) {
    cur_vi[so] = 1;
    int temp_max = 0;
    for (auto i : v[so]) {
      if (cur_vi[i] == 1) {
        *p = 100000000;
        break;
      }
      dfs(i, p);
      for (int j = 0; j < 26; j++) {
        cou[so][j] = max(cou[so][j], cou[i][j]);
      }
    }
    cou[so][s[so] - 'a']++;
    int temp = 0;
    for (int j = 0; j < 26; j++) {
      if (cou[so][j] > temp_max) {
        temp_max = cou[so][j];
        temp = j;
      }
    }
    dp[so] = temp;
    cur_vi[so] = 0;
    *p = max(*p, cou[so][dp[so]]);
  } else {
    *p = max(*p, cou[so][dp[so]]);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n, m;
  cin >> n >> m;
  cin >> s;
  int x, y;
  while (m--) {
    cin >> x >> y;
    x--;
    y--;
    if (x == y) {
      return !printf("-1");
    }
    v[x].push_back(y);
  }
  int maxx = 0;
  for (int i = 0; i < n; i++) {
    if (dp[i] == -1) {
      dfs(i, &maxx);
    } else {
      maxx = max(maxx, cou[i][dp[i]]);
    }
  }
  if (maxx == 100000000)
    cout << "-1";
  else
    cout << maxx;
}
