#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <tuple>
#include <set>
#include <algorithm>
using std::string;
using std::cin;
using std::cout;
using std::stoi;
using std::tuple;
using std::vector;
using std::stringstream;
using std::make_tuple;
using std::tuple_element;
using std::getline;
using std::get;
using std::find;
void debug(vector<int> v) {
for (vector<int>::iterator it = v.begin(); it != v.end(); ++it) {
cout << *it << " ";
}
cout << "\n";
}
int main(int argc, char** argv) {
// input
int n;
string n_s;
string uolevi;
string maija;
getline(cin, n_s);
n = stoi(n_s);
getline(cin, uolevi);
getline(cin, maija);
// parsing input
vector<tuple<int, int, int>> v;
stringstream ss(uolevi);
stringstream ss2(maija);
string sub;
string sub2;
while (getline(ss, sub, ' ') && getline(ss2, sub2, ' ')) {
v.push_back(make_tuple(stoi(sub), stoi(sub2), 0));
}
vector<int> unread;
for (vector<tuple<int, int, int>>::reverse_iterator it = v.rbegin(); it != v.rend(); ++it) {
if (find(unread.begin(), unread.end(), get<0>(*it)) == unread.end()) {
unread.push_back(get<0>(*it));
}
if (find(unread.begin(), unread.end(), get<1>(*it)) == unread.end()) {
unread.push_back(get<1>(*it));
}
}
stringstream result_ss;
for (vector<tuple<int, int, int>>::iterator it = v.begin(); it != v.end(); ++it) {
for (vector<int>::iterator it2 = unread.begin(); it2 != unread.end(); ++it2) {
if (*it2 != get<0>(*it) && *it2 != get<1>(*it)) {
*it = make_tuple(get<0>(*it), get<1>(*it), *it2);
unread.erase(it2);
break;
}
}
if (get<2>(*it) == 0 && it == v.rbegin()) {
return 1;
}
//cout << "(" << get<0>(*it) << ", " << get<1>(*it) << ", " << get<2>(*it) << "), ";
result_ss << get<2>(*it) << " ";
}
string result_s(result_ss.str());
result_s.pop_back();
cout << result_s << "\n";
return 0;
}