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
109
110
111
112
113
114
115
116
117
118
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Comparator;

public class boh {
    
    private static class Monster {
        int hp;
        int strength;
        int number;
        
        @Override
        public final String toString() {
            return "" + (hp - strength > 0 ? "+" : "") + (hp - strength) + ": " + strength + " " + hp + " " + number;
        }
    }
    
    private static class Hero {
        int hp;
        
        private final boolean fight(Monster m) {
            hp -= m.strength;
            if (hp > 0) {
                hp += m.hp;
                return true;
            } else {
                return false;
            }
        }
        
        private final boolean isDead() {
            return hp <= 0;
        }
        
        @Override
        public final String toString() {
            return "hero: hp=" + hp;
        }
        
    }
    
    private static class MonstersComparatr implements Comparator<Monster> {
        
        @Override
        public int compare(Monster m1, Monster m2) {
            
            int m1Value = m1.hp - m1.strength;
            int m2Value = m2.hp - m2.strength;
            if (m1Value < 0 && m2Value < 0) {
                if(m2.hp == m1.hp) {
                    return Integer.compare(m2.strength, m1.strength);
                } else {
                    return Integer.compare(m2.hp, m1.hp);
                }
            } else if (m1Value > 0 && m2Value > 0) {
                return Integer.compare(m1.strength, m2.strength);
            } else if (m1Value == 0 && m2Value == 0) {
                return Integer.compare(m2.strength, m1.strength);
            }
            return Integer.compare(m2Value, m1Value);
        }
        
    }
    
    /**
     * @param args
     */
    public static void main(String[] args) {
        try {
            final BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
//            final BufferedReader bf = new BufferedReader(new FileReader(new File("/home/K.Safaryjski/work/temp/potyczki/input.in.max")));
            
            String line[] = bf.readLine().split(" ");
            int n = Integer.parseInt(line[0]);
            int z = Integer.parseInt(line[1]);
            
            Hero hero = new Hero();
            hero.hp = z;
            Monster m = null;
            Monster[] monsters = new Monster[n];
            
            for (int i = 0; i < n; i++) {
                line = bf.readLine().split(" ");
                m = new Monster();
                m.number = i + 1;
                m.strength = Integer.parseInt(line[0]);
                m.hp = Integer.parseInt(line[1]);
                monsters[i] = m;
            }
            
            StringBuilder sb = new StringBuilder();
            Arrays.sort(monsters, new MonstersComparatr());
//            System.out.println(Arrays.deepToString(monsters));
            
            for (int i = 0; i < monsters.length; i++) {
                if (!hero.fight(monsters[i])) {
                    break;
                }
                sb.append(monsters[i].number).append(" ");
            }
            
            if (hero.isDead()) {
                System.out.println("NIE");
            } else {
                System.out.println("TAK");
                System.out.println(sb.toString().trim());
                System.out.flush();
            }
            bf.close();
        } catch (Throwable t) {
            
        }
    }
    
}