#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
const int NN = 5000020;
bool ac[NN], fl[NN];
int head[NN];
int vst[NN], low[NN], ins[NN], st[NN], bel[NN];
int id, top, cnt, d, ne;
vector<int> road[NN];
pii edge[NN];
void tarjan(int u) {
  vst[u] = low[u] = ++id;
  ins[u] = 1;
  st[++top] = u;
  for (int i = head[u]; i < head[u + 1]; i++) {
    int v = edge[i].second;
    if (!vst[v])
      tarjan(v), low[u] = min(low[u], low[v]);
    else if (ins[v])
      low[u] = min(low[u], vst[v]);
  }
  if (vst[u] == low[u]) {
    while (1) {
      bel[st[top]] = cnt;
      ins[st[top]] = 0;
      if (st[top--] == u) break;
    }
    ++cnt;
  }
}
int ID(int u, int i) { return u * d + i; }
int main() {
  int n, m;
  cin >> n >> m >> d;
  int N = n * d;
  for (int i = 1, l, r; i <= m; i++) {
    scanf("%d %d", &l, &r);
    l--;
    r--;
    for (int j = 0; j < d; j++) edge[ne++] = pii(ID(l, j), ID(r, (j + 1) % d));
  }
  sort(edge, edge + ne);
  int crr = 0;
  for (int i = 0; i < ne; i++) {
    while (crr <= edge[i].first) head[crr++] = i;
  }
  while (crr <= N) head[crr++] = ne;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < d; j++) scanf("%1d", &ac[ID(i, j)]);
  }
  for (int i = 0; i < N; i++) {
    if (!vst[i]) tarjan(i);
  }
  memset(vst, 0, sizeof vst);
  memset(low, 0, sizeof low);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < d; j++) {
      int first = ID(i, j);
      if (!ac[first]) continue;
      first = bel[first];
      if (fl[first]) continue;
      vst[first]++;
      fl[first] = 1;
    }
    for (int j = 0; j < d; j++) {
      int first = ID(i, j);
      if (!ac[first]) continue;
      first = bel[first];
      fl[first] = 0;
    }
  }
  for (int u = 0; u < N; u++) {
    for (int j = head[u]; j < head[u + 1]; j++) {
      int v = edge[j].second;
      int U = bel[u];
      int V = bel[v];
      if (U != V) {
        road[U].push_back(V);
      }
    }
  }
  for (int i = 0; i < cnt; i++) {
    for (int j : road[i]) {
      low[i] = max(low[i], low[j]);
    }
    low[i] += vst[i];
  }
  cout << low[bel[0]] << endl;
  return 0;
}
