#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 4;
struct pt{int L, R;}Left[N], Right[N];
int n, m, x, Lmin, Rmax, pl, pr;
bool vis[N];
priority_queue<int, vector<int>, greater<int> > ans;
bool cmp1(pt A, pt B){return A.R <= B.R;}
bool cmp2(pt A, pt B){return A.L <= B.L;}
void Push(int X){if(!vis[X]) ans.push(X), vis[X] = 1;};
int main(){
int i, j, l, r; scanf("%d %d %d", &n, &m, &x);
vis[x] = 1;
for(i = 1;i <= m;i ++){
scanf("%d %d", &l, &r);
if(l <= x && r >= x){Push(l), Push(r); Lmin = min(Lmin, l); Rmax = max(Rmax, r);}
else if(r < x) Left[++ pl].L = l, Left[pl].R = r;
else Right[++ pr].L = l, Right[pr].R = r;
}
sort(Left + 1, Left + pl + 1, cmp1);
for(i = 1;i <= pl;i ++) if(Left[i].R >= Lmin) Push(Left[i].L), Lmin = Left[i].L;
sort(Right + 1, Right + pr + 1, cmp2);
for(i = 1;i <= pr;i ++) if(Right[i].L <= Rmax) Push(Right[i].R), Rmax = Right[i].R;
while(!ans.empty()) printf("%d ", ans.top()), ans.pop();
return 0;
}