#include<iostream>
#include<cstdio>
using namespace std;
int a[101][101],c[101],r[101],ans[101];
int i,j,tot,temp,num,n,m;
int main() {
cin >> n;
for (i = 1; i <= n; i++) {
do {
cin >> j;
if (j !=0 ) {
c[i]++;
a[i][c[i]] = j;
r[j]++;
}
} while (j != 0);
}
for (i = 1; i <= n; i++)
if (r[i] == 0)
ans[++tot] = i;
do {
temp = ans[tot];
cout << temp << " ";
tot--;
num++;
for (i = 1; i <= c[temp]; i++) {
r[a[temp][i]]--;
if (r[a[temp][i]] == 0)
ans[++tot] = a[temp][i];
}
} while (num != n);
return 0;
}
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int a[101][101],c[101],r[101],ans[101];
int E;
int head[100010];
int to[100010];
int nxt[100010];
void add_edge(int a, int b)
{
to[E] = b;
nxt[E] = head[a];
head[a] = E;
E ++;
}
void init()
{
E = 0;
memset(head, -1, sizeof head);
}
int i,j,tot,temp,num,n,m;
int main() {
init();
cin >> n;
for (i = 1; i <= n; i++) {
do {
cin >> j;
if (j !=0 ) {
c[i]++;
add_edge(i, j);
r[j]++;
}
} while (j != 0);
}
for (i=1;i<=n;i++)
if (r[i] == 0)
ans[++tot] = i;
do {
temp = ans[tot];
cout << temp << " ";
tot--;
num++;
for (i = head[temp]; i != -1; i=nxt[i]) {
r[to[i]]--;
if (r[to[i]] == 0)
ans[++tot] = to[i];
}
} while (num != n);
return 0;
}