#include <stdio.h>
#include <iostream>
#include <memory.h>
#include <algorithm>
#include <queue>
#include <vector>
#include <map>
#include <math.h>
#include <stack>
#include <limits.h>
#include <iomanip>
using namespace std;
#define zero(x) memset(x,0,sizeof(x))
#define mone(x) memset(x,-1,sizeof(x))
#define ll long long
#define base 31
#define mod 1000000007
#define X first
#define Y second
#define fo(i,n) for(i=0;i<n;i++)
#define foo(i,n) for(i=1;i<=n;i++)
#define fa(i,I,n) for(i=I;i<n;i++)
#define sz(x) x.size()
#define pb push_back
const int inf=(1<<28);
int n,m,i,j,k,l,t,K;
namespace max_flow{
const int M=300,oo=(1<<28);
vector<int>g[M];
//p[i][j] capacidad de la arista (i,j)
//r[i][j] camino recidual
int r[M][M],p[M][M],path[M];
bool mar[M];
void init(){
zero(p);
for(int i=0;i<M;i++)g[i].clear();
}
void add(int a,int b,int v){
g[a].push_back(b);
p[a][b]=v;
}
int bfs(int no,int nof){
queue<int>q,q2;
q.push(no);q2.push(oo);
zero(mar);zero(path);
mar[no]=1;
path[nof]=path[no]=-1;
while(!q.empty()){
int nn=q.front(),pp=q2.front(),i;
q.pop();q2.pop();
fo(i,sz(g[nn])){
int hi=g[nn][i],cc=p[nn][hi]-r[nn][hi];
if(cc>0&&!mar[hi]){
mar[hi]=1;
path[hi]=nn;
if(hi==nof)return min(pp,cc);
q.push(hi);q2.push(min(pp,cc));
}
}
}
return 0;
}
int flow(int ini,int fin){
int sol=0,val,po;zero(r);
while(val=bfs(ini,fin)){
sol+=val;
po=fin;
while(path[po]!=-1){
r[path[po]][po]+=val;
r[po][path[po]]-=val;
po=path[po];
}
}
return sol;
}
}
int graph[55][55],paths[4005][2];
int main(){
while(1){
scanf("%d%d%d",&n,&m,&K);
if(n+m+K==0)break;
max_flow::init();
fo(i,n)fo(j,n)graph[i][j]=(i==j?0:inf);//init floy
fo(i,m){
int u,v;
scanf("%d%d",&u,&v);u--;v--;
paths[i][0]=u;
paths[i][1]=v;
graph[u][v]=1;
}
fo(k,n)fo(i,n)fo(j,n)//floy
graph[i][j]=min(graph[i][k]+graph[k][j],graph[i][j]);
fo(i,n){
max_flow::add(i,i+n,(i>0&&i<n-1?1:inf));
max_flow::add(i+n,i,0);
}
fo(i,m){
int u=paths[i][0],v=paths[i][1];
if(u==v)continue;
if(graph[0][u]+1+graph[v][n-1]<=K){
max_flow::add(u+n,v,1);
max_flow::add(v,u+n,0);
}
}
printf("%d\n",max_flow::flow(0,n-1));
}
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxpb3N0cmVhbT4KI2luY2x1ZGUgPG1lbW9yeS5oPgojaW5jbHVkZSA8YWxnb3JpdGhtPgojaW5jbHVkZSA8cXVldWU+CiNpbmNsdWRlIDx2ZWN0b3I+CiNpbmNsdWRlIDxtYXA+CiNpbmNsdWRlIDxtYXRoLmg+CiNpbmNsdWRlIDxzdGFjaz4KI2luY2x1ZGUgPGxpbWl0cy5oPgojaW5jbHVkZSA8aW9tYW5pcD4KCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CiNkZWZpbmUgemVybyh4KSBtZW1zZXQoeCwwLHNpemVvZih4KSkKI2RlZmluZSBtb25lKHgpIG1lbXNldCh4LC0xLHNpemVvZih4KSkKI2RlZmluZSBsbCBsb25nIGxvbmcKI2RlZmluZSBiYXNlIDMxCiNkZWZpbmUgbW9kIDEwMDAwMDAwMDcKI2RlZmluZSBYIGZpcnN0CiNkZWZpbmUgWSBzZWNvbmQKI2RlZmluZSBmbyhpLG4pIGZvcihpPTA7aTxuO2krKykKI2RlZmluZSBmb28oaSxuKSBmb3IoaT0xO2k8PW47aSsrKQojZGVmaW5lIGZhKGksSSxuKSBmb3IoaT1JO2k8bjtpKyspCiNkZWZpbmUgc3ooeCkgeC5zaXplKCkKI2RlZmluZSBwYiBwdXNoX2JhY2sKY29uc3QgaW50IGluZj0oMTw8MjgpOwppbnQgbixtLGksaixrLGwsdCxLOwpuYW1lc3BhY2UgbWF4X2Zsb3d7CiAgICBjb25zdCBpbnQgTT0zMDAsb289KDE8PDI4KTsKICAgIHZlY3RvcjxpbnQ+Z1tNXTsKICAgIC8vcFtpXVtqXSBjYXBhY2lkYWQgZGUgbGEgYXJpc3RhIChpLGopCiAgICAvL3JbaV1bal0gY2FtaW5vIHJlY2lkdWFsCiAgICBpbnQgcltNXVtNXSxwW01dW01dLHBhdGhbTV07CiAgICBib29sIG1hcltNXTsKICAgIHZvaWQgaW5pdCgpewogICAgICAgIHplcm8ocCk7CiAgICAgICAgZm9yKGludCBpPTA7aTxNO2krKylnW2ldLmNsZWFyKCk7CiAgICB9CiAgICB2b2lkIGFkZChpbnQgYSxpbnQgYixpbnQgdil7CiAgICAgICAgZ1thXS5wdXNoX2JhY2soYik7CiAgICAgICAgcFthXVtiXT12OwogICAgfQogICAgaW50IGJmcyhpbnQgbm8saW50IG5vZil7CiAgICAgICAgcXVldWU8aW50PnEscTI7CiAgICAgICAgcS5wdXNoKG5vKTtxMi5wdXNoKG9vKTsKICAgICAgICB6ZXJvKG1hcik7emVybyhwYXRoKTsKICAgICAgICBtYXJbbm9dPTE7CiAgICAgICAgcGF0aFtub2ZdPXBhdGhbbm9dPS0xOwogICAgICAgIHdoaWxlKCFxLmVtcHR5KCkpewogICAgICAgICAgICBpbnQgbm49cS5mcm9udCgpLHBwPXEyLmZyb250KCksaTsKICAgICAgICAgICAgcS5wb3AoKTtxMi5wb3AoKTsKICAgICAgICAgICAgZm8oaSxzeihnW25uXSkpewogICAgICAgICAgICAgICAgaW50IGhpPWdbbm5dW2ldLGNjPXBbbm5dW2hpXS1yW25uXVtoaV07CiAgICAgICAgICAgICAgICBpZihjYz4wJiYhbWFyW2hpXSl7CiAgICAgICAgICAgICAgICAgICAgbWFyW2hpXT0xOwogICAgICAgICAgICAgICAgICAgIHBhdGhbaGldPW5uOwogICAgICAgICAgICAgICAgICAgIGlmKGhpPT1ub2YpcmV0dXJuIG1pbihwcCxjYyk7CiAgICAgICAgICAgICAgICAgICAgcS5wdXNoKGhpKTtxMi5wdXNoKG1pbihwcCxjYykpOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHJldHVybiAwOwogICAgfQogICAgaW50IGZsb3coaW50IGluaSxpbnQgZmluKXsKICAgICAgICBpbnQgc29sPTAsdmFsLHBvO3plcm8ocik7CiAgICAgICAgd2hpbGUodmFsPWJmcyhpbmksZmluKSl7CiAgICAgICAgICAgIHNvbCs9dmFsOwogICAgICAgICAgICBwbz1maW47CiAgICAgICAgICAgIHdoaWxlKHBhdGhbcG9dIT0tMSl7CiAgICAgICAgICAgICAgICByW3BhdGhbcG9dXVtwb10rPXZhbDsKICAgICAgICAgICAgICAgIHJbcG9dW3BhdGhbcG9dXS09dmFsOwogICAgICAgICAgICAgICAgcG89cGF0aFtwb107CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcmV0dXJuIHNvbDsKICAgIH0KfQppbnQgZ3JhcGhbNTVdWzU1XSxwYXRoc1s0MDA1XVsyXTsKaW50IG1haW4oKXsKICAgIHdoaWxlKDEpewogICAgICAgIHNjYW5mKCIlZCVkJWQiLCZuLCZtLCZLKTsKICAgICAgICBpZihuK20rSz09MClicmVhazsKICAgICAgICBtYXhfZmxvdzo6aW5pdCgpOwogICAgICAgIGZvKGksbilmbyhqLG4pZ3JhcGhbaV1bal09KGk9PWo/MDppbmYpOy8vaW5pdCBmbG95CiAgICAgICAgZm8oaSxtKXsKICAgICAgICAgICAgaW50IHUsdjsKICAgICAgICAgICAgc2NhbmYoIiVkJWQiLCZ1LCZ2KTt1LS07di0tOwogICAgICAgICAgICBwYXRoc1tpXVswXT11OwogICAgICAgICAgICBwYXRoc1tpXVsxXT12OwogICAgICAgICAgICBncmFwaFt1XVt2XT0xOwogICAgICAgIH0KICAgICAgICBmbyhrLG4pZm8oaSxuKWZvKGosbikvL2Zsb3kKICAgICAgICAgICAgZ3JhcGhbaV1bal09bWluKGdyYXBoW2ldW2tdK2dyYXBoW2tdW2pdLGdyYXBoW2ldW2pdKTsKICAgICAgICBmbyhpLG4pewogICAgICAgICAgICBtYXhfZmxvdzo6YWRkKGksaStuLChpPjAmJmk8bi0xPzE6aW5mKSk7CiAgICAgICAgICAgIG1heF9mbG93OjphZGQoaStuLGksMCk7CiAgICAgICAgfQogICAgICAgIGZvKGksbSl7CiAgICAgICAgICAgIGludCB1PXBhdGhzW2ldWzBdLHY9cGF0aHNbaV1bMV07CiAgICAgICAgICAgIGlmKHU9PXYpY29udGludWU7CiAgICAgICAgICAgIGlmKGdyYXBoWzBdW3VdKzErZ3JhcGhbdl1bbi0xXTw9Syl7CiAgICAgICAgICAgICAgICBtYXhfZmxvdzo6YWRkKHUrbix2LDEpOwogICAgICAgICAgICAgICAgbWF4X2Zsb3c6OmFkZCh2LHUrbiwwKTsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBwcmludGYoIiVkXG4iLG1heF9mbG93OjpmbG93KDAsbi0xKSk7CiAgICB9CiAgICByZXR1cm4gMDsKfQ==