#include #include #include #include #include #include #include #include #include #include static const int MOD = 1000000007; using ll = long long; using u32 = uint32_t; using namespace std; template constexpr T INF = ::numeric_limits::max()/32*15+208; int main() { int n; cin >> n; vector a(n), b(n); for (int i = 0; i < n; ++i) { cin >> a[i] >> b[i]; } int cnt = 0; map id; map invid; map ok; for (int i = 0; i < n; ++i) { if(!id.count(a[i])){ invid[cnt] = a[i]; id[a[i]] = cnt++; } if(!id.count(b[i])){ invid[cnt] = b[i]; id[b[i]] = cnt++; } ok[id[a[i]]] -= 100000; ok[id[b[i]]]++; } for (auto &&i : invid) { if(ok[i.first] > 0){ cout << i.second << "\n"; } } return 0; }