#include <bits/stdc++.h>
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using namespace std;
const int N = 1e5 + 3, V = N * 50;
int n, m, D, low[V], num[V], ntar, cc[V], ncc, dp[V], second[V], ssz = 0;
ll s[N];
vector<int> g[N];
bool in[N];
inline void tarjan(int u) {
  low[u] = num[u] = ++ntar;
  second[ssz++] = u;
  for (int v : g[u / D]) {
    v = v * D + (u + 1) % D;
    if (!num[v]) {
      tarjan(v);
      low[u] = min(low[u], low[v]);
    } else
      low[u] = min(low[u], num[v]);
  }
  if (low[u] == num[u]) {
    ncc++;
    int v = 0, cnt = 0;
    vector<int> change;
    cc[u] = ncc;
    if (s[u / D] >> (u % D) & 1) {
      in[u / D] = 1;
      change.emplace_back(u / D);
      cnt++;
    }
    do {
      v = second[--ssz];
      int vv = v / D;
      if (s[vv] >> (v % D) & 1) {
        if (!in[vv]) cnt++, change.emplace_back(vv), in[vv] = 1;
      }
      cc[v] = ncc;
      low[v] = num[v] = V;
      for (int x : g[vv]) {
        x = x * D + (v + 1) % D;
        if (cc[x] && cc[x] < ncc) dp[ncc] = max(dp[ncc], dp[cc[x]]);
      }
    } while (u != v);
    dp[ncc] += cnt;
    for (int x : change) in[x] = 0;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n >> m >> D;
  for (int i = (1); i <= (m); ++i) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    g[u].emplace_back(v);
  }
  for (int i = (0); i <= (n - 1); ++i) {
    string t;
    cin >> t;
    for (int j = (0); j <= (D - 1); ++j)
      if (t[j] == '1') s[i] |= (1LL << j);
  }
  tarjan(0);
  cout << dp[ncc];
  return 0;
}
