#include <bits/stdc++.h>
using namespace std;
int f[111], g[111];
int fd(int x) {
  int y = x, z = 0;
  while (f[x]) {
    z ^= g[x];
    x = f[x];
  }
  while (f[y]) {
    int t = g[y];
    g[y] = z;
    z ^= t;
    t = y;
    y = f[y];
    f[t] = x;
  }
  return x;
}
int n, m;
int main() {
  scanf("%d%d\n", &n, &m);
  for (int i = 0; i < (m); ++i) {
    int x, y, z, xx, yy;
    scanf("%d%d%d", &x, &y, &z);
    z = !z;
    xx = fd(x);
    yy = fd(y);
    z ^= g[x];
    z ^= g[y];
    if (xx == yy && z) {
      puts("Impossible");
      return 0;
    }
    if (xx != yy) {
      f[xx] = yy;
      g[xx] = z;
    }
  }
  vector<int> s;
  for (int i = (1); i <= (n); ++i) {
    fd(i);
    if (g[i]) s.push_back(i);
  }
  printf("%d\n", s.size());
  for (__typeof((s).end()) i = (s).begin(); i != (s).end(); ++i)
    printf("%d%s", *i, i + 1 == s.end() ? "\n" : " ");
  return 0;
}
