#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m;
  cin >> n >> m;
  vector<int> v[n + 1];
  vector<int> index[n + 1];
  int x;
  for (int i = 1; i <= n; i++) {
    set<int> s;
    for (int j = 1; j <= m; j++) {
      cin >> x;
      if (s.find(x) == s.end()) {
        s.insert(x);
        v[i].push_back(x);
        index[i].push_back(j);
      }
    }
  }
  int xor_ = 0;
  int size_ = -1;
  for (int i = 1; i <= n; i++) {
    xor_ ^= v[i][0];
    if (v[i].size() > 1) {
      size_ = i;
    }
  }
  if (xor_ != 0) {
    cout << "TAK" << endl;
    for (int i = 1; i <= n; ++i) {
      cout << index[i][0] << ' ';
    }
  } else if (size_ == -1) {
    cout << "NIE" << endl;
  } else {
    cout << "TAK" << endl;
    for (int i = 1; i <= n; ++i) {
      if (i == size_) {
        cout << index[i][1] << ' ';
      } else {
        cout << index[i][0] << ' ';
      }
    }
  }
}
