#include #define rep(i,n) for(int i=0;i<(n);++i) #define all(a) (a).begin(),(a).end() #define dunk(a) cout << (a) << endl using namespace std; typedef long long ll; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector a(n); vector b(n); map ans; rep(i, n) { cin >> a[i] >> b[i]; ans[b[i]] = true; } rep(i, n) { ans[a[i]] = false; } rep(i, n) { if (ans[b[i]]) { dunk(b[i]); ans[b[i]] = false; } } return 0; }