#include <bits/stdc++.h>
using namespace std;
const int maxn = 128;
const int MAX = maxn * maxn;
const int dm = 30;
int A[MAX][10], C[MAX];
void ChgA(int a, int b) { A[a][b / dm] ^= 1 << (b % dm); }
int getA(int a, int b) {
  int t = A[a][b / dm] & (1 << (b % dm));
  return t == 0 ? 0 : 1;
}
int N, M;
void swapRow(int a, int b) {
  if (a == b) return;
  swap(C[a], C[b]);
  for (int i = 0; i < 5; ++i) swap(A[a][i], A[b][i]);
}
void sub(int a, int b) {
  C[a] ^= C[b];
  for (int i = 0; i < 5; ++i) A[a][i] ^= A[b][i];
}
void Set(int id) {
  for (int i = id; i <= M; ++i)
    if (getA(i, id) == 1) {
      swapRow(i, id);
      return;
    }
}
int sol[maxn];
bool ContradictionTest() {
  for (int i = 1; i <= M; ++i) {
    int tsol = 0;
    for (int j = 1; j <= N; ++j) tsol += sol[j] * getA(i, j);
    tsol &= 1;
    if (tsol != C[i]) return false;
  }
  return true;
}
vector<int> Fsol;
void isp() {
  for (int i = 1; i <= M; ++i) {
    for (int j = 1; j <= N; ++j) printf("%d ", getA(i, j));
    printf("%d\n", C[i]);
  }
  printf("-------\n");
}
int main() {
  memset(A, 0, sizeof A);
  memset(C, 0, sizeof C);
  scanf("%d%d", &N, &M);
  for (int i = 1; i <= M; ++i) {
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    ChgA(i, a);
    ChgA(i, b);
    if (c == 0) C[i] = 1;
  }
  for (int i = 1; i <= N; ++i) {
    Set(i);
    if (getA(i, i) == 1) {
      for (int j = 1; j <= M; ++j)
        if (i != j && getA(j, i) == 1) sub(j, i);
    } else {
      ++M;
      swapRow(i, M);
    }
  }
  for (int i = 1; i <= N; ++i) sol[i] = C[i];
  if (ContradictionTest() == false)
    printf("Impossible\n");
  else {
    for (int i = 1; i <= N; ++i)
      if (sol[i] == 1) Fsol.push_back(i);
    printf("%d\n", Fsol.size());
    for (int i = 0; i < Fsol.size(); ++i) printf("%d ", Fsol[i]);
    printf("\n");
  }
}
