#include <bits/stdc++.h>
using namespace std;
struct DSU {
  static const int MAXN = 210;
  int fa[MAXN], n;
  void init(int _n) {
    n = _n;
    for (int i = 0; i < n; i++) {
      fa[i] = i;
    }
  }
  int find(int u) { return u == fa[u] ? u : fa[u] = find(fa[u]); }
  bool join(int u, int v) {
    u = find(u);
    v = find(v);
    if (u == v) {
      return false;
    }
    fa[u] = v;
    return true;
  }
} dsu;
int main() {
  for (int n, m; ~scanf("%d%d", &n, &m);) {
    dsu.init(2 * n);
    for (int i = 0, u, v, c; i < m; i++) {
      scanf("%d%d%d", &u, &v, &c);
      u = (u - 1) * 2;
      v = (v - 1) * 2;
      if (c) {
        dsu.join(u, v);
        dsu.join(u ^ 1, v ^ 1);
      } else {
        dsu.join(u, v ^ 1);
        dsu.join(u ^ 1, v);
      }
    }
    bool flag = false;
    for (int u = 0; u < 2 * n; u += 2) {
      if (dsu.find(u) == dsu.find(u ^ 1)) {
        flag = true;
        break;
      }
    }
    if (flag) {
      puts("Impossible");
      continue;
    }
    int select[DSU::MAXN] = {0}, ans = 0;
    for (int u = 1; u < 2 * n; u += 2) {
      if (select[u] == 0) {
        select[u] = 1;
        select[u ^ 1] = 2;
        ans++;
        for (int v = u + 2; v < 2 * n; v += 2) {
          if (select[v]) {
            continue;
          }
          if (dsu.find(u) == dsu.find(v)) {
            select[v] = 1;
            ans++;
          } else if (dsu.find(u ^ 1) == dsu.find(v)) {
            select[v] = 2;
          }
        }
      }
    }
    printf("%d\n", ans);
    for (int u = 1; u < 2 * n; u += 2) {
      if (select[u] == 1) {
        printf("%d", u / 2 + 1);
        if (--ans) {
          putchar(' ');
        }
      }
    }
    puts("");
  }
  return 0;
}
