#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("avx")
using namespace std;
const int MAXV = 5e6 + 87;
const int N = 1e5 + 87;
int V, d;
vector<int> el[N];
int dfn[MAXV], did;
bool ins[MAXV];
int st[MAXV], stn, scc[MAXV], scn, vs[MAXV], vsn;
int tarjan(int u) {
  if (dfn[u]) return 1e9 + 10;
  int low = dfn[u] = ++did;
  st[stn++] = (u);
  ins[u] = true;
  const int& k = (u + 1) % d;
  for (const int& x : el[u / d]) {
    const int& v = x * d + k;
    if (!dfn[v]) {
      low = min(low, tarjan(v));
    } else if (ins[v]) {
      low = min(low, dfn[v]);
    }
  }
  if (dfn[u] == low) {
    int v;
    do {
      v = st[--stn];
      scc[v] = scn;
      vs[vsn++] = v;
      ins[v] = false;
    } while (v != u);
    scn++;
  }
  return low;
}
int n, m;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m >> d;
  V = n * d;
  for (int i = 0; i < m; ++i) {
    int u, v;
    cin >> u >> v;
    --u, --v;
    el[u].push_back(v);
  }
  tarjan(0);
  bool* ok = ins;
  for (int i = 0; i < n; ++i) {
    string s;
    cin >> s;
    for (int j = 0; j < d; ++j) ok[i * d + j] = s[j] == '1';
  }
  int* dp = dfn;
  int* tmp = st;
  int la = 0;
  for (int u = 0; u < scn; ++u) {
    dp[u] = 0;
    int tmpn = 0;
    for (; la < vsn && scc[vs[la]] == u; ++la) {
      int i = vs[la];
      int k = (i + 1) % d;
      if (ok[i]) tmp[tmpn++] = (i / d);
      for (const int& j : el[i / d]) {
        int v = scc[j * d + k];
        if (v == u) continue;
        dp[u] = max(dp[u], dp[v]);
      }
    }
    sort(tmp, tmp + tmpn);
    dp[u] += unique(tmp, tmp + tmpn) - tmp;
  }
  cout << dp[scc[0]] << endl;
}
