#include using namespace std; typedef long long ll; typedef pair P; #define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0) #define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0) struct UnionFind { private: vector par,depth; public: UnionFind (int n) { par.resize(n); depth = vector(n,0); for (int i = 0;i < n;++i) par[i] = i; } int find(int x) { if (par[x] == x) return x; else return par[x] = find(par[x]); } void unite(int x,int y) { x = find(x); y = find(y); if (x == y) return; par[y] = x; if (depth[x] == depth[y]) depth[x]++; else depth[x] = max(depth[x],depth[y]); } bool same(int x,int y) { return find(x) == find(y); } }; int main() { int n,m; cin >> n; vector a(n),b(n); map mp; for (int i = 0;i < n;++i) cin >> a[i] >> b[i]; for (int i = 0;i < n;++i) mp[a[i]]++; for (int i = 0;i < n;++i) if (mp[b[i]] == 0) { cout << b[i] << "\n"; mp[b[i]]++; } }