#include <bits/stdc++.h>
using namespace std;
int n, m, d;
char O[100010][51];
vector<vector<int>> edges;
vector<vector<int>> edges2;
vector<int> S;
bitset<5000100> visited;
int dfsLow[5000100], dfsNum[5000100];
int SCCVal[5000100];
int SCCid[5000100];
int id = 1;
int sid = 1;
int seen[100100];
int DP[5000100];
vector<vector<int>> inSCC;
void setSCC(const int u) {
  inSCC.push_back(vector<int>());
  while (true) {
    int v = S.back();
    S.pop_back();
    visited[v] = 0;
    SCCid[v] = sid;
    inSCC[sid].push_back(v);
    if (u == v) break;
  }
  sid++;
}
void getSCCs(const int u) {
  S.push_back(u);
  visited[u] = 1;
  dfsLow[u] = dfsNum[u] = id++;
  for (auto& e : edges2[u]) {
    if (!dfsNum[e]) getSCCs(e);
    if (visited[e]) dfsLow[u] = min(dfsLow[u], dfsLow[e]);
  }
  if (dfsLow[u] == dfsNum[u]) setSCC(u);
}
void DFS() {
  for (int s = 1; s < sid; s++) {
    int best = 0;
    for (auto& v : inSCC[s])
      for (auto& e : edges2[v])
        if (SCCid[e] != s) best = max(best, DP[SCCid[e]]);
    DP[s] = best + SCCVal[s];
  }
}
int main() {
  int n1, n2;
  scanf("%d %d %d", &n, &m, &d);
  edges.assign(n + 5, vector<int>());
  edges2.assign((n + 1) * d + 5, vector<int>());
  inSCC.assign(1, vector<int>());
  while (m--) {
    scanf("%d %d", &n1, &n2);
    edges[n1].push_back(n2);
  }
  for (int i = 1; i <= n; i++) scanf("%s", O[i]);
  for (int i = 1; i <= n; i++)
    for (int j = 0; j < d; j++)
      for (auto& e : edges[i]) edges2[i * d + j].push_back(e * d + (j + 1) % d);
  edges.clear();
  getSCCs(d);
  for (int i = 1; i < sid; i++) {
    for (auto& v : inSCC[i]) {
      int p = v / d;
      int r = v - p * d;
      if (O[p][r] == '1' && seen[p] != i) seen[p] = i, SCCVal[i]++;
    }
  }
  memset(DP, -1, sizeof(DP));
  DFS();
  printf("%d\n", DP[SCCid[d]]);
  return 0;
}
