#include <bits/stdc++.h>
using namespace std;
long long n, m;
long long a[505][505];
long long q[505];
long long vis[505];
long long ko = 0;
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> a[i][j];
    }
  }
  for (int k = 0; k <= 10; k++) {
    long long l = 0, b = 0, y = 0;
    memset(vis, 0, sizeof(vis));
    for (int i = 1; i <= n; i++) {
      int flag1 = 0, flag2 = 0;
      for (int j = 1; j <= m; j++) {
        if (a[i][j] & (1 << k)) {
          flag1 = 1;
        } else {
          flag2 = 1;
        }
      }
      if (flag1 && flag2 == 0) {
        y++;
        vis[i] = 2;
      } else if (flag1 == 0 && flag2) {
        l++;
        vis[i] = 0;
      } else {
        b++;
        vis[i] = 1;
      }
    }
    long long ny = 0, nl = 0, bq = 0;
    if (y % 2 || (y % 2 == 0 && b >= 1)) {
      if (y % 2) {
        ny = y;
        nl = n - y;
        bq = 0;
      } else {
        ny = y;
        nl = n - y - 1;
        bq = 1;
      }
      for (int i = 1; i <= n; i++) {
        int flag = 0;
        if (vis[i] == 2 && ny >= 1) {
          ny--;
          flag = 1;
        } else if (vis[i] == 1 && bq) {
          flag = 1;
          bq = 0;
        } else if (nl >= 1) {
          nl--;
          flag = 0;
        }
        for (int j = 1; j <= m; j++) {
          if (flag) {
            if ((a[i][j] & (1 << k))) {
              q[i] = j;
              break;
            }
          } else if (flag == 0) {
            if ((a[i][j] & (1 << k)) == 0) {
              q[i] = j;
              break;
            }
          }
        }
      }
      ko = 1;
      break;
    }
  }
  if (ko) {
    printf("TAK\n");
    for (int i = 1; i <= n; i++) cout << q[i] << " ";
  } else
    printf("NIE");
}
