#include<bits/stdc++.h>
using namespace std;
long long n,z,ans[1000040],l;
long long an,bn,cn;
struct mos{
long long id,cost,geta,weight;
}m[1000060];
mos a[590000],b[590000],c[590000];
bool cmpb(mos a,mos b){
return a.weight>b.weight;
}
bool cmpc(mos a,mos b){
return a.geta>b.geta;
}
int main()
{
std::ios::sync_with_stdio(false);
cin>>n>>z;
for(long long i=1;i<=n;i++){
cin>>m[i].cost>>m[i].geta;
m[i].id=i;
m[i].weight=m[i].geta-m[i].cost;
}
for(long long i=1;i<=n;i++){
if(z>m[i].cost&&m[i].weight>=0){
a[++an]=m[i];
}else if(z<=m[i].cost&&m[i].weight>=0){
b[++bn]=m[i];
}else{
c[++cn]=m[i];
}
}
sort(b+1,b+bn+1,cmpb);
sort(c+1,c+cn+1,cmpc);
for(long long i=1;i<=an;i++){
z+=a[i].weight;
ans[++l]=a[i].id;
}
for(long long i=1;i<=bn;i++){
if(z>b[i].cost){
z+=b[i].weight;
ans[++l]=b[i].id;
}else{
cout<<"NIE";
return 0;
}
}
for(long long i=1;i<=cn;i++){
if(z>c[i].cost){
z+=c[i].weight;
ans[++l]=c[i].id;
}else{
cout<<"NIE";
return 0;
}
}
cout<<"TAK\n";
for(long long i=1;i<=l;i++){
cout<<ans[i]<<' ';
}
return 0;
}
98 pts