1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class boh {

	/**
	 * @param args
	 * @throws IOException
	 * @throws NumberFormatException
	 */
	public static void main(String[] args) throws NumberFormatException,
			IOException {
		BufferedReader bi = new BufferedReader(new InputStreamReader(System.in));
		String line = bi.readLine();
		String[] strs = line.split("\\s");
		int n = Integer.valueOf(strs[0]);
		int z = Integer.valueOf(strs[1]);
		Battle[] battles = new Battle[n];

		for (int i = 0; i < n; i++) {
			line = bi.readLine();
			strs = line.split("\\s");
			int d = Integer.valueOf(strs[0]);
			int h = Integer.valueOf(strs[1]);
			battles[i] = new Battle(d, h, i + 1);
		}
		Arrays.sort(battles);
		boolean result = true;
		for (int i = 0; i < n && result; i++) {
			if (z <= battles[i].getDamage()) {
				result = false;
			} else {
				z += battles[i].getDiff();
			}
		}
		if (!result) {
			System.out.println("NIE");
		} else {
			System.out.println("TAK");
			System.out.print(battles[0].getIndex());
			for (int i = 1; i < n; i++) {
				System.out.print(" " + battles[i].getIndex());
			}
			System.out.println();
		}
	}

	public static class Battle implements Comparable<Battle> {
		private final Integer damage;
		private final Integer health;
		private final Integer diff;
		private final Integer index;

		public Battle(Integer damage, Integer health, Integer index) {
			super();
			this.damage = damage;
			this.health = health;
			this.index = index;
			this.diff = health - damage;
		}

		public Integer getDamage() {
			return damage;
		}

		public int getHealth() {
			return health;
		}

		public Integer getDiff() {
			return diff;
		}

		@Override
		public int compareTo(Battle o) {
			Integer signumDiff = Integer.signum(getDiff());
			Integer otherSignumDiff = Integer.signum(o.getDiff());
			Integer signumDiff2 = signumDiff;
			int cmp = -signumDiff2.compareTo(otherSignumDiff);
			if (cmp == 0) {
				if (signumDiff >= 0) {
					return getDamage().compareTo(o.getDamage());
				} else {
					return -getDamage().compareTo(o.getDamage());
				}
			} else {
				return cmp;
			}
		}

		public Integer getIndex() {
			return index;
		}

//		@Override
//		public String toString() {
//			return "[d=" + damage + ", diff=" + diff + "]";
//		}
		
	}

}