//============================================================================
// Name        : kug.cpp
// Author      : Grzegorz Gajoch
// Description : Potyczki 2014 - kuglarz
//============================================================================


#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <ctype.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <cstring>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <list>

using namespace std;

#define FOR(i,a,b) for(int i = a; i <= b; ++i)
#define FORD(i,a,b) for(int i = a; i >= b; --i)
#define REP(x, n) for(int x=0; x < (n); ++x)
#define VAR(v,i) __typeof(i) v=(i)
#define FOREACH(i,c) for(VAR(i,(c).begin());i!=(c).end();++i)
#define SIZE(n) (int)n.size()
#define ALL(c) c.begin(),c.end()
#define PB(n) push_back(n)
typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef vector<bool> VB;
#define MP make_pair
#define ST mon
#define ND second
const int INF = 1000000001;

#undef DBGGG

#ifdef DBGGG
	#define debug
	#define deb printf
#else
	#undef debug
	#define deb //printf
#endif

int N, Z;
struct monster
{
	int cost, gain, number;
	void print()
	{
		printf("(%d %d |%d)\n", cost, gain, number);
	}
};
bool operator<(monster a, monster b)
{
	if (a.cost == b.cost)
	{
		if (a.gain == b.gain)
		{
			return (a.number > b.number);
		}
		return (a.gain > b.gain);
	}
	return (a.cost > b.cost);
}
struct by_gain {
	bool operator() (const monster& a, const monster& b)
	{
		if (a.gain == b.gain)
		{
			if (a.cost == b.cost)
			{
				return (a.number > b.number);
			}
			return (a.cost > b.cost);
		}
		return (a.gain > b.gain);
	}
};
vector<int> res;
int main(int argc, char **argv)
{
	scanf("%d %d", &N, &Z);
	monster mon;
	int d, a;
	multiset<monster> more, less;
	multiset<monster, by_gain> less_by_gain;
	long long LAST_DEL = 0;
	REP(i, N)
	{
		scanf("%d %d", &d, &a);
		mon.cost = d;
		mon.gain = a-d;
		mon.number = i;
		if (a == 0)
		{
			LAST_DEL += d;
		}
		else if( mon.gain >= 0 ) 
			more.insert(mon);
		else
		{
			less.insert(mon);
			less_by_gain.insert(mon);
		}
	}
#ifdef debug
	printf("first phase: %d\n",Z);
	for (auto x : more)
	{
		x.print();
	}
#endif
	while (more.size() > 0)
	{
		deb("now: %d\n", Z);
		mon.cost = Z-1;
		mon.gain = INF;
		mon.number = 0;
		auto x = more.lower_bound(mon);
		if (x != more.end())
		{
			mon = *x;
#ifdef debug
			mon.print();
#endif
			if (Z <= mon.cost) goto fail;
			Z += mon.gain;
			res.push_back(mon.number);
			more.erase(x);
		}
		else
		{
			goto fail;
		}
		if (Z <= 0) goto fail;
	}










#ifdef debug
	printf("after first: %d\nLESS:\n", Z);
	for (auto x : less)
	{
		printf("(%d %d)\n", x.cost, x.gain);
	}
	printf("LESS BY GAIN:\n");
	for (auto x : less_by_gain)
	{
		printf("(%d %d)\n", x.cost, x.gain);
	}
#endif

	
	while (less_by_gain.size() > 0 || less.size() > 0)
	{
		auto less_top_itr = less_by_gain.begin(),
			biggest_val_itr = less.begin();

		if (Z + less_top_itr->gain > biggest_val_itr->cost) //można ciachnąć
		{
			if (Z <= less_top_itr->cost) goto fail;
			Z += less_top_itr->gain;
#ifdef debug
			printf("TAKING: Z = %d ",Z);
			monster x = *less_top_itr;
			x.print();
#endif
			res.push_back(less_top_itr->number);
			less.erase(*less_top_itr);
			less_by_gain.erase(less_top_itr);
		}
		else //trzeba dużego
		{
			if (Z <= biggest_val_itr->cost) goto fail;
			Z += biggest_val_itr->gain;
#ifdef debug
			printf("TAKING: Z = %d ", Z);
			monster x = *biggest_val_itr;
			x.print();
#endif
			res.push_back(biggest_val_itr->number);
			less.erase(biggest_val_itr);
			less_by_gain.erase(*biggest_val_itr);
		}
		if (Z <= 0) goto fail;
	}

	Z -= LAST_DEL;
	if (Z > 0)
	{
		printf("TAK\n");
		for (auto x : res)
			printf("%d ", x+1);
		printf("\n");
	}
	else
	{
	fail:
		printf("NIE\n");
	}
	return 0;
}
