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
105
106
107
108
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.Comparator;

public class boh {
    private static int skipWS(final InputStream in) throws IOException {
		int val = -1;
		while ((val = in.read()) != -1) {
			if (!Character.isWhitespace((char) val)) break;
		}
		return val;
	}

	private static int readInt(final InputStream in) {
		try {
			final StringBuilder b = new StringBuilder();
			int val = skipWS(in);
			b.append((char) val);
			while ((val = in.read()) != -1) {
				if (Character.isWhitespace((char) val))
					break;
				b.append((char) val);
			}
			return Integer.parseInt(b.toString());
		} catch (final IOException e) {
			throw new RuntimeException(e);
		}
	}

	private static void bohAlg() {
    	final int n = readInt(System.in);
    	long z = readInt(System.in);
    	Mon[] monsters = new Mon[n];
    	int [] killOrder = new int[n];
    	for (int i = 0; i < n; i++) {
    		monsters[i] = new Mon(readInt(System.in), readInt(System.in), i+1);
    	}
        Arrays.sort(monsters, Cmp.INSTANCE);
    	Mon current;
    	for (int i = 0; i < monsters.length; i++) {
    		current = monsters[i];
    		if (current.l >= z) {
        		System.out.println("NIE");
        		return;
    		}
    		z = z - current.l + current.e;
    		killOrder[i] = current.i;
    	}
		System.out.println("TAK");
		for (int i = 0; i < n; i++) {
			System.out.print(killOrder[i]);
			System.out.print(" ");
		}
	}

	public static void main(String[] args) throws Exception {
		bohAlg();
	}

	private static class Mon {
		final int l; //life
		final int e; //elixir
		final int i; //index
		Mon(int l, int e, int i) {
			this.l = l;
			this.e = e;
			this.i = i;
		}
	}

	private static class Cmp implements Comparator<Mon> {
		static final Cmp INSTANCE = new Cmp();
		@Override
		public int compare(Mon a, Mon b) {
			return select(a,b) == a.i ? -1 : 1;
		}

		int select(Mon a, Mon b) {
			int lifeGainA = a.e - a.l;
			int lifeGainB = b.e - b.l;
			if (lifeGainA > 0 && lifeGainB > 0) {
				if (a.l == b.l) {
					if (a.e == b.e) return a.i < b.i ? a.i : b.i;
					return a.e > b.e ? a.i : b.i;
				}
				return a.l < b.l ? a.i : b.i;
			}
			else if (lifeGainA >= 0 && lifeGainB < 0) {
				return a.i;
			}
			else if (lifeGainA < 0 && lifeGainB >=0) {
				return b.i;
			}
			else if (lifeGainA <= 0 && lifeGainB <= 0) {
				if (a.l == b.l) {
					if (a.e == b.e) return a.i < b.i ? a.i : b.i;
					return a.e > b.e ? a.i : b.i;
				}
				return a.l > b.l ? a.i : b.i;
			}
			else if (lifeGainA == 0 && lifeGainB == 0) {
				return a.l > b.l ? a.i : b.i;
			}
			return a.i;
		}
	}
}