#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, mm;
  scanf("%d %d", &n, &mm);
  map<int, int> m[505];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < mm; j++) {
      int first;
      scanf("%d", &first);
      m[i][first] = j;
    }
  }
  vector<pair<int, int> > ans;
  int sum = 0;
  for (int i = 0; i < n; i++) {
    ans.push_back(*m[i].begin());
    sum ^= ans.back().first;
  }
  if (sum == 0) {
    int ok = 0;
    for (int i = 0; i < n; i++) {
      if (m[i].size() != 1) {
        ans[i] = *m[i].rbegin();
        ok = 1;
        break;
      }
    }
    if (!ok) {
      printf("NIE\n");
      return 0;
    }
  }
  printf("TAK\n");
  for (auto it : ans) printf("%d ", it.second + 1);
  printf("\n");
}
