#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 1;
struct Node{
int mun;
int a;
int b;
};
bool cmp(Node x,Node y){
return x.b > y.b;
}
int read(){
char s;
int f ;
s = getchar();
if(s >= '0' && s <= '9'){
f = s - '0';
}
s = getchar();
while(s >= '0' && s <= '9'){
f = (f << 3) + (f << 1) + s - '0';
s = getchar();
}
return f;
}
int m,n;
Node a[maxn];
queue<Node> q1;
queue<int> ans;
int p;
int main(){
n = read();
m = read();
for(int i = 1;i <= n;i ++){
a[i].a = read();
a[i].b = read();
a[i].mun = i;
}
sort(a + 1,a + 1 + n,cmp);
for(int i = 1;i <= n;i ++){
if(a[i].a < m){
m -= a[i].a;
m += a[i].b;
ans.push(a[i].mun);
}else if(a[i].a >= m){
q1.push(a[i]);
}
}
Node sun;
sun.mun = -1;
while(!q1.empty()){
Node cnt = q1.front();
q1.pop();
if(cnt.mun == sun.mun){
cout << "NIE";
return 0;
}
if(cnt.a < m){
m -= cnt.a;
m += cnt.b;
ans.push(cnt.mun);
}else if(cnt.a >= m){
q1.push(cnt);
}
sun.mun = cnt.mun;
}
cout << "TAK\n";
while(!ans.empty()){
printf("%d ",ans.front());
ans.pop();
}
return 0;
}