#include <bits/stdc++.h>
using namespace std;
/*
* You got a dream, you gotta protect it.
*/
typedef long long ll;
const int N = 100;
vector<int> adj[N], G[50];
int g[N][N], vis[N], qu[N], par[N], vs;
void addEdge(int u, int v) {
if (!g[u][v] && !g[v][u]) {
adj[u].push_back(v);
adj[v].push_back(u);
}
++g[u][v];
}
bool BFS(int src, int sink) {
int s = 0, e = 0;
qu[e++] = src;
vis[src] = ++vs;
while (s < e) {
int v = qu[s++];
for (size_t i = 0; i < adj[v].size(); ++i) {
int u = adj[v][i];
if (vis[u] == vs || !g[v][u])
continue;
vis[u] = vs;
par[u] = v;
qu[e++] = u;
if (u == sink)
return true;
}
}
return false;
}
int maxFlow(int src, int sink) {
int flow = 0;
while (BFS(src, sink)) {
++flow;
for (int u = sink; u != src; u = par[u]) {
int v = par[u];
++g[u][v];
--g[v][u];
}
}
return flow;
}
int main(int argc, char **argv) {
// freopen("a", "r", stdin);
// freopen("b", "w", stdout);
int n, m, k;
while (scanf("%d%d%d", &n, &m, &k) && n) {
for (int i = 0; i < n; ++i)
G[i].clear();
while (m--) {
int u, v;
scanf("%d%d", &u, &v);
--u;
--v;
G[u].push_back(v);
}
int s = 0, e = 0, lev = 0;
qu[e++] = 0;
vis[0] = ++vs;
while (s < e && lev < k) {
int siz = e - s;
while (siz--) {
int v = qu[s++];
for (size_t i = 0; i < G[v].size(); ++i) {
int u = G[v][i];
if (vis[u] == vs)
continue;
if (lev + 1 < k || (lev + 1 == k && u == n - 1))
vis[u] = vs, qu[e++] = u;
}
}
++lev;
}
for (int i = 0; i < n * 2; ++i) {
adj[i].clear();
for (int j = i; j < n * 2; ++j)
g[i][j] = g[j][i] = 0;
}
for (int i = 0; i < e; ++i) {
int u = qu[i];
if (u && u != n - 1)
addEdge(u, u + n);
for (size_t j = 0; j < G[u].size(); ++j)
if (u)
addEdge(u + n, G[u][j]);
else
addEdge(u, G[u][j]);
}
printf("%d\n", maxFlow(0, n - 1));
}
return 0;
}
I2luY2x1ZGUgPGJpd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