#include <bits/stdc++.h>
using namespace std;
class DSU {
 public:
  vector<int> par, rank, sum;
  void init(int n) {
    par.assign(n, 0);
    rank.assign(n, 1);
    sum.assign(n, 0);
    for (int i = 0; i < n; i++) par[i] = i;
  }
  int find(int u) { return (par[u] == u) ? u : find(par[u]); }
  int getSum(int u) { return (par[u] == u) ? 0 : sum[u] ^ getSum(par[u]); }
  void unite(int x, int v, int val) {
    x = find(x);
    v = find(v);
    if (x == v) return;
    if (rank[x] > rank[v]) swap(x, v);
    par[x] = v;
    rank[v] += rank[x];
    sum[x] = val;
  }
};
int main() {
  int n, m, u, v, uu, vv, su, sv, c, ans1 = 0, ans2 = 0, ans;
  scanf("%d", &n);
  scanf("%d", &m);
  DSU p;
  p.init(n + 1);
  bool f = true;
  while (m--) {
    scanf("%d", &u);
    scanf("%d", &v);
    scanf("%d", &c);
    uu = p.find(u);
    vv = p.find(v);
    su = p.getSum(u);
    sv = p.getSum(v);
    if (uu != vv)
      p.unite(uu, vv, !(su ^ sv ^ c));
    else if (su ^ sv == c)
      f = false;
  }
  if (!f)
    cout << "Impossible";
  else {
    for (int i = 1; i < n + 1; i++)
      if (p.getSum(i)) ans1++;
    for (int i = 1; i < n + 1; i++)
      if (!p.getSum(i)) ans2++;
    if (ans1 > ans2)
      ans = ans2, f = false;
    else
      ans = ans1, f = true;
    printf("%d\n", ans);
    for (int i = 1; i < n + 1; i++)
      if (p.getSum(i) == f) printf("%d ", i);
  }
  return 0;
}
