#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
inline int read() {
  char c = getchar();
  int x = 0;
  bool f = 0;
  for (; !isdigit(c); c = getchar()) f ^= !(c ^ 45);
  for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
  if (f) x = -x;
  return x;
}
int n, m, k;
long long sta[1000005];
struct edge {
  int to, nxt;
} e[100005 * 50], e2[100005 * 50];
int tot, tot2, head[100005 * 50], head2[100005 * 50];
inline void adde(int u, int v) {
  e[++tot] = (edge){v, head[u]};
  head[u] = tot;
}
inline void adde2(int u, int v) {
  if (u == v) return;
  e2[++tot2] = (edge){v, head2[u]};
  head2[u] = tot2;
}
int idx, scc, bel[100005 * 50], dfn[100005 * 50], low[100005 * 50];
int f[100005 * 50], val[100005 * 50];
bool ins[100005 * 50], vis[100005 * 50];
stack<int> s, q;
inline void tarjan(const int u) {
  int v;
  dfn[u] = low[u] = ++idx, ins[u] = true, s.push(u);
  for (int i = head[u]; i; i = e[i].nxt) {
    if (!dfn[v = e[i].to]) {
      tarjan(v), low[u] = min(low[u], low[v]);
    } else if (ins[v]) {
      low[u] = min(low[u], dfn[v]);
    }
  }
  if (dfn[u] == low[u]) {
    ++scc;
    do {
      v = s.top();
      s.pop(), ins[v] = false;
      bel[v] = scc;
      if (!vis[(v - 1) % n + 1] && (sta[(v - 1) % n + 1] >> (v - 1) / n) & 1) {
        ++val[scc], vis[(v - 1) % n + 1] = true, q.push((v - 1) % n + 1);
      }
    } while (v ^ u);
    for (; !q.empty(); vis[q.top()] = false, q.pop())
      ;
  }
}
inline int P(int i, int j) { return j * n + i; }
int dfs(int u) {
  if (vis[u]) return f[u];
  vis[u] = 1;
  for (int i = head2[u]; i; i = e2[i].nxt) {
    int v = e2[i].to;
    f[u] = max(f[u], dfs(v));
  }
  return f[u] += val[u];
}
int main() {
  n = read(), m = read(), k = read();
  int qu, qv;
  for (register int i = (1); i <= (m); ++i) {
    int u = read(), v = read();
    if (i == 1) qu = u, qv = v;
    for (register int j = (0); j <= (k - 1); ++j)
      adde(P(u, j), P(v, (j + 1) % k));
  }
  char ch;
  for (register int i = (1); i <= (n); ++i)
    for (register int j = (0); j <= (k - 1); ++j) {
      while (!isdigit(ch = getchar()))
        ;
      sta[i] |= 1ll * (ch - '0') << j;
    }
  tarjan(1);
  for (register int i = (1); i <= (n * k); ++i) {
    if (!dfn[i]) continue;
    int u = bel[i];
    for (int j = head[i]; j; j = e[j].nxt) {
      int v = e[j].to;
      if (!dfn[v]) continue;
      v = bel[v];
      if (u != v) adde2(u, v);
    }
  }
  cout << dfs(bel[1]);
  return 0;
}
