/*2-sat第一题。
好题啊!
首先2-sat是一个2限定性问题。
一组有2个元素。
若a和b矛盾,则a和b同组的另一个元素连一条边。
此为建图。
然后注意要反向存图,建立以缩点为节点的新图。
然后对新图进行自底向上的拓扑排序。
然后按顺序输出一组解。*/
#include <stdio.h>
#include <cstring>
#include <iostream>
#include <queue>
using namespace std;
const int maxn=8001*2;
const int maxm=20001*4;
struct edge
{
int next,to;
} e[maxm];
edge re[maxm];
int n,m,t,scnt,top,cnt,tt;
int head[maxn],dfn[maxn],low[maxn],belong[maxn],col[maxn],st[maxn];
bool vis[maxn];
int in[maxn],rhead[maxn],conflict[maxn],ans[maxn];
void add(int i,int j)
{
e[t].to=j;
e[t].next=head[i];
head[i]=t++;
}
void readd(int i,int j)
{
re[tt].to=j;
re[tt].next=rhead[i];
rhead[i]=tt++;
}
void tarjan(int u)
{
int t;
st[top++]=u;
dfn[u]=low[u]=++cnt;
vis[u]=true;
for(int i=head[u]; i!=-1; i=e[i].next)
{
int v=e[i].to;
if(!dfn[v])
{
tarjan(v);
low[u]=min(low[u],low[v]);
}
else if(vis[v])
low[u]=min(dfn[v],low[u]);
}
if(low[u]==dfn[u])
{
scnt++;
do
{
t=st[--top];
belong[t]=scnt;
vis[t]=false;
}
while(t!=u);
}
}
bool solve()
{
for(int i=0; i<2*n; i++)
if(!dfn[i]) tarjan(i);
for(int i=0; i<2*n; i++)
{
if(belong[i]==belong[i^1])
return false;
conflict[belong[i]]=belong[i^1];
conflict[belong[i^1]]=belong[i];
}
memset(in,0,sizeof(in));
memset(col,0,sizeof(col));
for(int i=0; i<2*n; i++)
{
for(int j=head[i]; j!=-1; j=e[j].next)
{
int u=e[j].to;
if(belong[i]!=belong[u])
{
readd(belong[u],belong[i]);//存反向图
in[belong[i]]++;
}
}
}
queue <int> q;//对新图进行拓扑
for(int i=1; i<=scnt; i++)
if(in[i]==0) q.push(i);
while(!q.empty())
{
int u=q.front();
q.pop();
if(col[u]==0)
{
col[u]=1;
col[conflict[u]]=-1;
}
for(int i=rhead[u]; i!=-1; i=re[i].next)
{
int v=re[i].to;
in[v]--;
if(in[v]==0) q.push(v);
}
}
memset(ans,0,sizeof(ans));
for(int i=0; i<2*n; i++)
if(col[belong[i]]==1) ans[i]=1;
return true;
}
int main()
{
int a,b;
while(scanf("%d%d",&n,&m)==2)
{
memset(dfn,0,sizeof(dfn));
memset(vis,false,sizeof(vis));
memset(e,0,sizeof(e));
memset(re,0,sizeof(re));
memset(rhead,-1,sizeof(rhead));
memset(head,-1,sizeof(head));
memset(conflict,0,sizeof(conflict));
memset(st,0,sizeof(st));
memset(belong,0,sizeof(belong));
top=cnt=scnt=t=tt=0;
while(m--)
{
scanf("%d%d",&a,&b);
a--,b--;
add(a,b^1);
add(b,a^1);
}
if(solve())
{
for(int i=0; i<2*n; i++)
if(ans[i]) printf("%d\n",i+1);
}
else printf("NIE\n");
}
return 0;
}