#include<stdio.h>
#include<string.h>
#include<stdbool.h>
#define N 100010
#define M 1000010
#define INF 0x3f3f3f3f
int n, p, c, m;
int dist[N];
int que[N], head, tail;
bool inQue[N];
int h[N], cnt;
struct edge{
int to;
int next;
int time;
}E[M*2];
void add(int v, int w, int time){
E[++cnt].next = h[v];
E[cnt].to = w;
E[cnt].time = time;
h[v] = cnt;
}
void spfa(){
memset(dist, 0x3f, sizeof dist);
dist[c] = 1;
que[++tail] = c, inQue[c] = true;
while(head != tail){
int t = que[++head];
tail %= N;
inQue[t] = false;
for(int i = h[t]; i != -1; i = E[i].next){
int u = E[i].to;
if(dist[u] > dist[t] + E[i].time){
dist[u] = dist[t] + E[i].time;
if(!inQue[u]){
que[++tail] = u;
tail %= N;
inQue[u] = true;
}
}
}
}
}
int main(){
scanf("%d %d %d %d", &n, &p, &c, &m);
memset(h, -1, sizeof h);
for(int i = 1; i <= p; i++){
int a, b;
scanf("%d %d", &a, &b);
add(a, b, 1), add(b, a, 1);
}
spfa();
int max = -INF;
for(int i = 1; i <= n; i++)
if(dist[i] != INF && dist[i] > max)
max = dist[i];
printf("%d", max + m);
return 0;
}