#include <bits/stdc++.h>
#define pb push_back
#define pii pair<int,int>
#define endl "\n"
#define vi vector<int>
#define io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
vi parent;
int n,m;
inline void init(){
parent.resize(n+2);
for(int i=1;i<=n;i++){
parent[i]=i;
}
}
inline int findtree(int k){
if(k==parent[k])return k;
else{
int root=findtree(parent[k]);
parent[k]=root;
return root;
}
}
inline void merge(int x,int y){
x=findtree(x),y=findtree(y);
if(x!=y){
if(x<y)swap(x,y);
parent[x]=y;
}
}
int main(){
io
while(cin>>n>>m){
init();
int x,y;
for(int i=0;i<m;i++){
cin>>x>>y;
merge(x,y);
}
int k;cin>>k;
cout<<findtree(k)<<endl;
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNkZWZpbmUgcGIgcHVzaF9iYWNrIAojZGVmaW5lIHBpaSBwYWlyPGludCxpbnQ+IAojZGVmaW5lIGVuZGwgIlxuIgojZGVmaW5lIHZpIHZlY3RvcjxpbnQ+CiNkZWZpbmUgaW8gaW9zX2Jhc2U6OnN5bmNfd2l0aF9zdGRpbyhmYWxzZSk7Y2luLnRpZSgwKTtjb3V0LnRpZSgwKTsKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCnZpIHBhcmVudDsKaW50IG4sbTsKCmlubGluZSB2b2lkIGluaXQoKXsKICAgIHBhcmVudC5yZXNpemUobisyKTsKCiAgICBmb3IoaW50IGk9MTtpPD1uO2krKyl7CiAgICAgICAgcGFyZW50W2ldPWk7CiAgICB9Cn0KCgppbmxpbmUgaW50IGZpbmR0cmVlKGludCBrKXsKICAgIGlmKGs9PXBhcmVudFtrXSlyZXR1cm4gazsKICAgIGVsc2V7CiAgICAgICAgaW50IHJvb3Q9ZmluZHRyZWUocGFyZW50W2tdKTsKICAgICAgICBwYXJlbnRba109cm9vdDsKICAgICAgICByZXR1cm4gcm9vdDsKICAgIH0KfQoKaW5saW5lIHZvaWQgbWVyZ2UoaW50IHgsaW50IHk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