#include <cstdio>
#include <utility>
#include <algorithm>
#include <vector>
using namespace std;

struct mob
{
	int nr;
	int hit;
	int pot;
};

bool profitOrder(const mob& m1, const mob& m2)
{
	return m1.hit < m2.hit;
}

bool riskOrder(const mob& m1, const mob& m2)
{
	if (m1.hit != m2.hit)
		return m1.hit > m2.hit;
	else
		return m1.pot > m2.pot;
}

//order:ilość życia, potem różnica 

int main(int argc, char** argv)
{
	int monsters;
	int hp;

	scanf("%d %d", &monsters, &hp);

	vector<int> order;
	vector<mob> profit;
	vector<mob> risk;
	order.reserve(monsters);
	profit.reserve(monsters);
	risk.reserve(monsters);

	for (int i = 1; i <= monsters; i++)
	{
		int hit, pot;
		scanf("%d %d", &hit, &pot);

		if (hit <= pot && hit < hp)
		{
			order.push_back(i);
			hp += (pot - hit);
		}
		else if (hit <= pot)
		{
			profit.push_back({ i, hit, pot });
		}
		else
		{
			risk.push_back({ i, hit, pot });
		}
	}

	sort(begin(profit), end(profit), profitOrder);

	for (auto& x : profit)
	{
		if (x.hit >= hp)
		{
			printf("NIE");
			return 0;
		}

		hp += (x.pot - x.hit);
		order.push_back(x.nr);
	}

	sort(begin(risk), end(risk), riskOrder);

	for (auto& x : risk)
	{
		if (x.hit >= hp)
		{
			printf("NIE");
			return 0;
		}

		hp += (x.pot - x.hit);
		order.push_back(x.nr);
	}

	printf("TAK\n");

	for (auto x : order)
		printf("%d ", x);

}

