#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
using namespace std;
const double pi =
    3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int MR = 1e5 + 10;
const int MS = 60;
vector<int> g[MR], rev[MR], gscc[MR], ktore[MR];
int srt[MR], cnt;
bool done[MR];
void dfs(int nr, vector<int> *g) {
  done[nr] = 1;
  for (int p : g[nr])
    if (!done[p]) dfs(p, g);
  srt[cnt++] = nr;
}
int sccNr, scc[MR];
void dfs(int nr) {
  scc[nr] = sccNr;
  for (int p : rev[nr])
    if (!scc[p]) dfs(p);
}
void go(int nr) {
  for (int p : g[nr])
    if (scc[p] != scc[nr]) gscc[scc[nr]].push_back(scc[p]);
}
int d;
char s[MS];
int dp[MR][MS];
long long check[MR], museum[MR];
int resSCC[MR * MS], bestSCC[MR * MS];
int state[MR][MS];
vector<pair<int, int> > visited;
void dfsSCC(int nr, char k) {
  {
    bool prev = museum[nr] & check[nr];
    check[nr] += 1LL << k;
    if (!prev && (museum[nr] & check[nr])) resSCC[cnt]++;
  }
  state[nr][k] = cnt;
  visited.push_back(make_pair(nr, k));
  int nxt = (k + 1) % d;
  for (int i : g[nr])
    if (!state[i][nxt] && scc[nr] == scc[i]) dfsSCC(i, nxt);
}
int main() {
  int n, m;
  scanf("%d%d%d", &n, &m, &d);
  for (int i = 0; i < (m); ++i) {
    int u, v;
    scanf("%d%d", &u, &v);
    u--;
    v--;
    g[u].push_back(v);
    rev[v].push_back(u);
  }
  for (int i = 0; i < (n); ++i) {
    scanf("%s", s);
    for (int j = 0; j < (d); ++j)
      if (s[j] == '1') museum[i] += 1LL << j;
  }
  for (int i = 0; i < (n); ++i)
    if (!done[i]) dfs(i, g);
  reverse(srt, srt + n);
  for (int i = 0; i < (n); ++i)
    if (!scc[srt[i]]) {
      sccNr++;
      dfs(srt[i]);
    }
  for (int i = 0; i < (n); ++i) scc[i]--;
  for (int i = 0; i < (n); ++i) go(i);
  cnt = 0;
  memset(done, 0, sizeof(done));
  for (int i = 0; i < (sccNr); ++i)
    if (!done[i]) dfs(i, gscc);
  for (int i = 0; i < (n); ++i) ktore[scc[i]].push_back(i);
  cnt = 0;
  for (int i = 0; i < (sccNr); ++i) {
    for (int nr : ktore[srt[i]])
      for (int k = 0; k < (d); ++k) {
        if (!state[nr][k]) {
          cnt++;
          dfsSCC(nr, k);
          while (!visited.empty()) {
            check[visited.back().first] = 0;
            visited.pop_back();
          }
        }
        int nxt = (k + 1) % d;
        for (int p : g[nr])
          if (scc[nr] != scc[p])
            bestSCC[state[nr][k]] = max(bestSCC[state[nr][k]], dp[p][nxt]);
      }
    for (int nr : ktore[srt[i]])
      for (int k = 0; k < (d); ++k)
        dp[nr][k] = bestSCC[state[nr][k]] + resSCC[state[nr][k]];
  }
  printf("%d\n", dp[0][0]);
  return 0;
}
