#include <bits/stdc++.h>
using namespace std;
const int mn = 5e6 + 5;
const int mod = 1e9 + 7;
int n, m, k;
inline int gethash(int x, int d) { return (x - 1) * k + d; }
namespace scc_Tarjan {
vector<int> g[100005];
int pre[mn], lowlink[mn], sccno[mn], dfsc, sccc;
stack<int> s;
inline void dfs(int u) {
  pre[u] = lowlink[u] = ++dfsc;
  s.push(u);
  int w = (u - 1) / k + 1;
  for (int i = 0; i < g[w].size(); i++) {
    int nxtd = (u - 1) % k + 2;
    if (nxtd == k + 1) nxtd -= k;
    int v = gethash(g[w][i], nxtd);
    if (!pre[v]) {
      dfs(v);
      lowlink[u] = min(lowlink[u], lowlink[v]);
    } else if (!sccno[v]) {
      lowlink[u] = min(lowlink[u], pre[v]);
    }
  }
  if (lowlink[u] == pre[u]) {
    sccc++;
    while (1) {
      int x = s.top();
      s.pop();
      sccno[x] = sccc;
      if (x == u) break;
    }
  }
}
void find_scc(int n) {
  dfsc = sccc = 0;
  memset(sccno, 0, sizeof(sccno));
  memset(pre, 0, sizeof(pre));
  dfs(1);
}
}  // namespace scc_Tarjan
using namespace scc_Tarjan;
int c[mn];
set<int> h;
char S[55];
vector<int> exg[mn];
int d[mn];
int deg[mn];
queue<int> q;
int main() {
  scanf("%d%d%d", &n, &m, &k);
  for (int i = 1; i <= m; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    g[u].push_back(v);
  }
  find_scc(n * k);
  for (int i = 1; i <= n; i++) {
    scanf("%s", S + 1);
    h.clear();
    for (int j = 1; j <= k; j++) {
      if (S[j] == '1') {
        int u = sccno[gethash(i, j)];
        if (!h.count(u)) h.insert(u), c[u]++;
      }
    }
  }
  for (int i = 1; i <= n * k; i++) {
    int u = sccno[i];
    if (u == 0) continue;
    int w = (i - 1) / k + 1;
    for (auto &j : g[w]) {
      int nxtd = (i - 1) % k + 2;
      if (nxtd == k + 1) nxtd -= k;
      int v = sccno[gethash(j, nxtd)];
      if (v != u) exg[v].push_back(u), deg[u]++;
    }
  }
  for (int i = 1; i <= sccc; i++) {
    if (deg[i] == 0) q.push(i);
  }
  int ans = 0;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    d[u] += c[u];
    for (auto &i : exg[u]) {
      deg[i]--;
      d[i] = max(d[i], d[u]);
      if (deg[i] == 0) q.push(i);
    }
  }
  printf("%d\n", d[sccno[1]]);
  return 0;
}
