/*
* * author: attacker
* * created: 02.04.2026 17:34:45
*/
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "algo/debug.h"
#else
#define debug(...) 1
#endif
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define bpc __builtin_popcount
#define size(v) (int)(v.size())
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
auto Is_ok = [&](vector<int> vt) {
if ((vt[0] != 5 && vt[0] != 6) || (vt[size(vt) - 1] != 7 && vt[size(vt) - 1] != 8)) {
return false;
}
for (int i = 0; i < size(vt); i++) {
if (i > 0 && i < size(vt) - 1) {
if (vt[i] == 1) {
if (vt[i - 1] != 2 && vt[i - 1] != 4 && vt[i - 1] != 6) {
return false;
}
if (vt[i + 1] != 3 && vt[i + 1] != 4 && vt[i + 1] != 8) {
return false;
}
} else if (vt[i] == 2) {
if (vt[i - 1] != 2 && vt[i - 1] != 4 && vt[i - 1] != 6) {
return false;
}
if (vt[i + 1] != 1 && vt[i + 1] != 2 && vt[i + 1] != 7) {
return false;
}
} else if (vt[i] == 3) {
if (vt[i - 1] != 1 && vt[i - 1] != 3 && vt[i - 1] != 5) {
return false;
}
if (vt[i + 1] != 3 && vt[i + 1] != 4 && vt[i + 1] != 8) {
return false;
}
} else if (vt[i] == 4) {
if(vt[i - 1] != 1 && vt[i - 1] != 3 && vt[i - 1] != 5) {
return false;
}
if (vt[i + 1] != 1 && vt[i + 1] != 2 && vt[i + 1] != 7) {
return false;
}
} else {
return false;
}
}
}
return true;
};
int n;
cin >> n;
vector<pair<int, int>> a(n);
for (auto& [x, y] : a) {
cin >> x >> y;
}
auto cur = a;
vector<int> res;
for (int i = 0; i < n; i++) {
res.push_back(INT_MAX);
}
do {
vector<int> vt;
for (auto [x, y] : cur) {
vt.push_back(x);
}
if (Is_ok(vt)) {
vector<int> mn;
for (auto [x, y] : cur) {
mn.push_back(y);
}
res = min(res, mn);
}
} while (next_permutation(cur.begin(), cur.end()));
if (count(res.begin(), res.end(), INT_MAX) == size(res)) {
cout << -1 << '\n';
} else {
for (int i = 0; i < size(res); i++) {
cout << res[i] << " \n"[i == size(res) - 1];
}
}
return 0;
}