#include <iostream>
#include <cstdio>
#include <algorithm>
#include <iterator>
#include <forward_list>

using namespace std;

const char * TAK = "TAK";
const char * NIE = "NIE";

struct task{

	int p;
	int k;
	int c;
};

bool compare_task(task first, task second){
	if (first.p < second.p)
		return true;
	else if (first.p == second.p){
		if ( (first.k - first.c) < (second.k - second.c))
			return true;
		return false;
	}
	return false;
}

bool compare_task_with_kc(task first, task second){

	// zakladamy, ze p dla first i second sa takie same
	if ( (first.k - first.c) < (second.k - second.c))
			return true;
	return false;
}

task getAt(forward_list<task> zadania, int index){
	int i = 0;
	for ( auto it = zadania.begin(); it != zadania.end(); ++it ){
		if(i == index)
			return (*it);
		++i;
	}
	task t;
	t.p = -1; t.k = -1; t.c = -1;
	return t;
}

int getFirstIndexElement(forward_list<task> zadania, int value){
	int i = 0;
	for ( auto it = zadania.begin(); it != zadania.end(); ++it ){
		
		if((*it).p > value)
			return i;
		i = i+1;
	}
	return i;
}

bool is_task_done(task t){

	if (t.c < 1)
		return true;
	return false;
}

int main() {

	int n, m;
	scanf("%d %d", &n, &m);
	
	if (m >= n){
		cout << TAK;
		return 0;
	}
	
	forward_list<task> zadania;
	forward_list<task> temp_sort;
	
	int p, k, c;
	
	// wypelniamy liste
	for (int i=0; i<n; i++){
		task t;
		scanf("%d %d %d", &p, &k, &c);
		t.p = p; t.k = k; t.c = c;
		zadania.push_front(t);
	}
	
	zadania.sort(compare_task);
	// posortowany poczatkowy zbior
	
	
	// wyrownaj pierwsze m zadan
	int next_p, i;
	while(true){
		while(true){
		
			next_p = getAt(zadania, m).p; // element o indeksie m, jesli mniej elementow to -1
			
			if (next_p == zadania.front().p){ // jesli pierwszy element.p == m_element.p
				break;
			}
			else if(next_p == -1){	// liczba zadan mniejsza od m, wypisz TAK
				cout << TAK << endl;
				return 0;
			}
			int progress = 0;
			i = 0;
			for ( auto it = zadania.begin(); it != zadania.end(); ++it ){
				if(i >= m)
					break;

				progress = next_p - (*it).p;
				(*it).p = next_p;
				(*it).c -= progress;
				++i;
			}
			// OK, wyryównane pierwsze m zadañ
			
			// usun wszystkie ukonczone zadania ( c < 1)
			zadania.remove_if(is_task_done);
		
		} // end while
		
		//teraz n o tym samym p wieksze od m
		
		// next_p = getAt(zadania, m).p;
		
		//int up_index = getFirstIndexElement(zadania, next_p);  // indeks pierwszego elementu o wiekszym p
		
		int up_index = 0;
		auto up_iterator_el = zadania.begin();
		for (; up_iterator_el != zadania.end(); ++up_iterator_el ){
			
			if((*up_iterator_el).p > next_p){
				break;
			}
			up_index += 1;
		}
		
		//zadania.sort(compare_task);
		// sortowanie 
		temp_sort.splice_after(temp_sort.before_begin(), zadania, zadania.before_begin(), up_iterator_el);
		temp_sort.sort(compare_task);
		zadania.splice_after(zadania.before_begin(), temp_sort);
		//temp_sort.clear(); temp_sort i tak jest tutaj pusty
		
		// liczba zadan o tym samym p > m - dla ka¿dego odejmujemy jeden i sprawdzamy czy nie ma przypadku NIE
		i = 0;
		for ( auto it = zadania.begin(); it != zadania.end(); ++it ){
			if(i >= up_index){
				break;
			}

			(*it).p += 1;
			if (i < m){
				(*it).c -= 1;
			}
			if ( ((*it).k - (*it).p) < (*it).c){
				cout << NIE << endl;
				return 0;
			}
			i += 1;
		}
		zadania.remove_if(is_task_done);
		if (zadania.empty()){
			cout << TAK << endl;
			return 0;
		}
	} // end outer while
	
	
	cout << TAK << endl;
	return 0;
}
