#include <bits/stdc++.h>
using namespace std;
int G[128][128];
int n, m, resp[102], tot;
int Me[102 * 5000];
int *M[5000];
int somae[102 * 5000];
int *soma[5000];
inline void trocalinha(int i1, int i2) {
  int *c = M[i1];
  M[i1] = M[i2];
  M[i2] = c;
  c = soma[i1];
  soma[i1] = soma[i2];
  soma[i2] = c;
}
bool solve() {
  for (int i = 0; i < m; i++)
    for (int j = 0; j < n; j++) soma[i][j] = M[i][j] + (j ? soma[i][j - 1] : 0);
  for (int col = 0; col < n; col++) {
    int lcomnzero = -1;
    for (int i = 0; i < m; i++)
      if (M[i][col] == 1 and (col == 0 or soma[i][col - 1] == 0)) {
        lcomnzero = i;
        break;
      }
    if (lcomnzero == -1) continue;
    trocalinha(col, lcomnzero);
    for (int i = 0; i < m; i++)
      if (i != col and M[i][col] == 1 and (i == 0 or soma[i][col - 1] == 0)) {
        bool sozero = true;
        for (int j = col; j <= n; j++) {
          M[i][j] ^= M[col][j];
          if (j < n and M[i][j] == 1) sozero = false;
          soma[i][j] = M[i][j] + (j ? soma[i][j - 1] : 0);
        }
        if (sozero and M[i][n] == 1) return false;
      }
  }
  for (int i = n - 1; i >= 0; i--) {
    int r = M[i][n];
    for (int j = i + 1; j < n; j++)
      if (M[i][j] == 1) r ^= resp[j];
    if (r == 1 and M[i][i] == 0) return false;
    resp[i] = r;
    if (r == 1) tot++;
  }
  for (int i = n; i < m; i++) {
    int x = 0;
    for (int j = 0; j < n; j++)
      if (M[i][j] == 1) x ^= resp[j];
    if (x != M[i][n]) return false;
  }
  return true;
}
int main() {
  scanf("%d %d", &n, &m);
  memset(Me, 0, sizeof(Me));
  for (int i = 0; i < 102 * 5000; i += 102) {
    M[i / 102] = Me + i;
    soma[i / 102] = somae + i;
  }
  memset(G, 0xff, sizeof(G));
  for (int i = 0; i < m; i++) {
    int v1, v2, w;
    scanf("%d %d %d", &v1, &v2, &w);
    v1--;
    v2--;
    G[v1][v2] = G[v2][v1] = w;
    M[i][v1] = M[i][v2] = 1;
    M[i][n] = w ^ 1;
  }
  m = (m > n ? m : n);
  if (!solve())
    printf("Impossible\n");
  else {
    printf("%d\n", tot);
    bool p = true;
    for (int i = 0; i < n; i++)
      if (resp[i] == 1) {
        if (!p) printf(" ");
        p = false;
        printf("%d", i + 1);
        for (int j = 0; j < n; j++)
          if (G[i][j] != -1) {
            G[i][j] ^= 1;
            G[j][i] ^= 1;
          }
      }
    printf("\n");
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++)
        if (G[i][j] == 0) {
          printf("Error in %d-%d\n", i + 1, j + 1);
        }
  }
  return 0;
}
