/*
* Copyright© 2023 Nostalgia. All rights reserved.
* author: Nostalgia
* Problem: QOJ#6331 火车站
* Tag: 并查集
* Memory Limit: 512MiB
* Time Limit: 1000ms
* Source: 联合省选2023
* Date: 2023-11-04
*/
// Viva los artistas y su amor
// 我将同烟火一般灿烂
// Viva los artistas y su amor
// 我将同河流一般深远
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,sse2,bmi,bmi2,lzcnt,popcnt")
#include <bits/stdc++.h>
using i64 = long long;
constexpr int N = 2e5 + 10;
int fa[N];
int find(int x) {return x == fa[x] ? fa[x] : fa[x] = find(fa[x]);}
std::pair<int, int> seg[N];
int n, m, x;
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
std::cin >> n >> m >> x;
for (int i = 1; i <= m; i++) {
std::cin >> seg[i].first >> seg[i].second;
fa[i] = i;
}
int curl = 0, curr = 0;
std::sort(seg + 1, seg + 1 + m);
for (int i = 1; i <= m; i++) {
if (seg[i].first > curr) {
curl = seg[i].first, curr = seg[i].second;
} else {
curr = std::max(curr, seg[i].second);
fa[i] = find(i - 1);
}
}
int pos = 0;
for (int i = 1; i <= m; i++) {
if (seg[i].first <= x && x <= seg[i].second)
pos = i;
}
if (!pos) {
std::cout << "0" << '\n';
return 0;
}
std::vector<int> vec;
for (int i = 1; i <= m; i++) {
if (find(i) == find(pos)) {
if (seg[i].first >= x)
vec.push_back(seg[i].second);
else if (seg[i].second < x)
vec.push_back(seg[i].first);
else
vec.push_back(seg[i].first), vec.push_back(seg[i].second);
}
}
std::sort(vec.begin(), vec.end());
vec.erase(std::unique(vec.begin(), vec.end()), vec.end());
for (const int &p : vec)
if (p != x)
std::cout << p << ' ';
std::cout << '\n';
return 0;
}