#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll maxn = 2e5 + 10;
struct TwoSat {
  ll n, cnt;
  vector<ll> g[maxn];
  bool vis[maxn];
  ll order[maxn], comp[maxn];
  void init(ll n_) {
    n = n_;
    cnt = 0;
    for (ll i = 0; i < n; ++i) g[i].clear();
  }
  void add(ll u, ll v) {
    g[u].push_back(v);
    g[v].push_back(u);
  }
  void dfs1(ll u) {
    vis[u] = 1;
    for (auto it : g[u]) {
      if (!vis[it]) dfs1(it);
    }
    order[cnt++] = u;
  }
  void dfs2(ll u, ll c) {
    comp[u] = c;
    for (auto it : g[u]) {
      if (comp[it] == -1) dfs2(it, c);
    }
  }
  bool solve(vector<ll>& ans) {
    ans.clear();
    memset(vis, 0, sizeof vis);
    for (ll i = 0; i < n; ++i) {
      if (!vis[i]) dfs1(i);
    }
    memset(comp, -1, sizeof comp);
    ll x{};
    for (ll i = n - 1; i >= 0; i--) {
      ll node = order[i];
      if (comp[node] == -1) {
        dfs2(node, x++);
      }
    }
    for (ll i = 0; i < n; i += 2) {
      if (comp[i] == comp[i + 1]) {
        cerr << i << "\n";
        return 0;
      }
    }
    for (ll i = 0; i < n; i += 2) {
      ll choose = comp[i] > comp[i + 1] ? (i) : (i + 1);
      ans.push_back(choose);
    }
    return 1;
  }
} twoSat;
void addEdge(ll u, ll v, bool c) {
  ll u0 = 2 * (u - 1), u1 = 2 * (u - 1) + 1;
  ll v0 = 2 * (v - 1), v1 = 2 * (v - 1) + 1;
  if (c) {
    twoSat.add(u0, v0);
    twoSat.add(u1, v1);
  } else {
    twoSat.add(u0, v1);
    twoSat.add(u1, v0);
  }
}
void solve() {
  ll n, m, u, v;
  cin >> n >> m;
  bool c;
  twoSat.init(2 * n);
  for (ll i = 0; i < m; ++i) {
    cin >> u >> v >> c;
    addEdge(u, v, c);
  }
  vector<ll> ans;
  if (twoSat.solve(ans)) {
    ll count{};
    for (ll i = 0; i < ans.size(); ++i) {
      count += (ans[i] & 1);
    }
    cout << count << "\n";
    for (ll i = 0; i < ans.size(); ++i) {
      if (ans[i] & 1) {
        cout << (ans[i] - 1) / 2 + 1 << " ";
      }
    }
  } else {
    cout << "Impossible";
  }
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ll t;
  t = 1;
  for (ll i = 0; i < t; ++i) {
    solve();
  }
  return 0;
}
