#include <bits/stdc++.h>
using namespace std;
int n, m, s = 0;
int t[501][501];
int a = -1, b = -1, c = -1, d;
int g = -1;
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> m;
  for (int i = 0; i < n - 1; i++) {
    for (int j = 0; j < m; j++) {
      cin >> t[i][j];
      if (j == 0) {
        s = s ^ t[i][j];
        a = t[i][j];
      }
      if (((!(t[i][j] == a)) && (j > 0)) && (b == -1)) {
        b = i;
        c = j + 1;
      }
    }
  }
  for (int j = 0; j < m; j++) {
    cin >> d;
    if (((s ^ d) > 0) && (g == -1)) {
      g = j + 1;
    }
  }
  if (g == -1) {
    if (b == -1) {
      cout << "NIE" << endl;
    } else {
      cout << "TAK" << endl;
      for (int i = 0; i < n; i++) {
        if (i == b) {
          cout << c << " ";
        } else {
          cout << "1"
               << " ";
        }
      }
    }
  } else {
    cout << "TAK" << endl;
    for (int i = 0; i < n - 1; i++) {
      cout << "1"
           << " ";
    }
    cout << g << " ";
  }
  cout << endl;
  return 0;
}
