#include #include #include #include #define maxn 1000100 using namespace std; ifstream fin ("test.in"); vector > G[maxn],con[maxn]; int T[maxn][2],maxv1[maxn],maxv2[maxn],status[maxn],v[maxn]; bool in_stack[maxn],viz[maxn]; int n,t,c,a,b; string s; void end () { cout<<"IMPOSSIBLE"; exit(0); } void dfs (int x) { in_stack [x] = 1; viz[x] = 1; maxv1[x] = maxv2[x] = x; for (int i = 0; i < G[x].size(); ++i) { int y = G[x][i].first; if (in_stack[y]) { end(); } else if (!viz[y]) { dfs (y); } if (G[x][i].second == 0) { maxv1[x] = max (maxv1[x],maxv2[y]); } maxv2[x] = max (maxv2[x],maxv2[y]); } in_stack[x] = 0; } int construct (int l, int r) { if (l > r) return 0; T[l][0] = construct (l+1,maxv1[l]); T[l][1] = construct (maxv1[l]+1,r); return l; } void check (int x) { if (x == 0) return; for (int i = 0; i < con[x].size(); ++i) { if (status[con[x][i].first] != con[x][i].second+1) end (); } status[x] = 1; check (T[x][0]); v[++t] = x; status[x] = 2; check (T[x][1]); status[x] = 0; } int main() { fin>>n>>c; for (int i = 1; i <= c; ++i) { fin>>a>>b>>s; if (s == "LEFT") { G[a].push_back (make_pair(b,0)); con[b].push_back (make_pair(a,0)); } else { G[a].push_back (make_pair(b,1)); con[b].push_back (make_pair(a,1)); } } for (int i = 1; i <= n; ++i) { if (!viz[i]) dfs (i); } construct (1,n); check (1); for (int i = 1; i <= n; ++i) cout<