#include <bits/stdc++.h>
using namespace std;
const int maxn = 503;
int n, m;
int judge(bitset<10> a[maxn][maxn], int i, int j) {
  for (int k = 1; k < m; ++k)
    if (a[j][k][i] != a[j][0][i]) {
      return -1;
    }
  return a[j][0][0];
}
int main() {
  while (~scanf("%d%d", &n, &m)) {
    bitset<10> a[maxn][maxn];
    int num;
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < m; ++j) {
        scanf("%d", &num);
        a[i][j] = bitset<10>(num);
      }
    }
    bool flag = false;
    vector<int> ans(n, 0);
    for (int i = 0; i < 10; ++i) {
      for (int j = 0; j < n; ++j) {
        if (judge(a, i, j) == -1) {
          int tem = 0;
          for (int k = 0; k < j; ++k) tem ^= a[k][0][i];
          for (int k = j + 1; k < n; ++k) tem ^= a[k][0][i];
          for (int k = 0; k < m; ++k)
            if ((tem ^ a[j][k][i]) != 0) {
              flag = true;
              ans[j] = k;
              break;
            }
        }
        if (flag) break;
      }
      if (flag)
        break;
      else {
        int tem = 0;
        for (int j = 0; j < n; ++j) tem ^= a[j][0][i];
        if (tem) {
          flag = true;
          break;
        }
      }
    }
    if (flag) {
      printf("TAK\n%d", 1 + ans[0]);
      for (int i = 1; i < n; ++i) printf(" %d", 1 + ans[i]);
      printf("\n");
    } else {
      printf("NIE\n");
    }
  }
  return 0;
}
