#include <bits/stdc++.h>
using namespace std;
struct Graph {
  vector<vector<int> > conn;
  vector<bool> explr;
  int n;
  Graph(int nsize) {
    n = nsize;
    conn.resize(n);
    explr.resize(n, false);
  }
  void addEdge(int a, int b) {
    conn[a].push_back(b);
    conn[b].push_back(a);
  }
  void dfs(int pos) {
    explr[pos] = true;
    for (auto next : conn[pos])
      if (!explr[next]) dfs(next);
  }
};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  Graph g(2 * n);
  for (int i = 0; i < m; i++) {
    int u, v, c;
    cin >> u >> v >> c;
    u--, v--;
    if (c == 0) {
      g.addEdge(u * 2, v * 2 + 1);
      g.addEdge(u * 2 + 1, v * 2);
    }
    if (c == 1) {
      g.addEdge(u * 2, v * 2);
      g.addEdge(u * 2 + 1, v * 2 + 1);
    }
  }
  vector<int> result;
  for (int i = 0; i < n; i++) {
    if (!g.explr[2 * i] && !g.explr[2 * i + 1]) g.dfs(2 * i);
    if (g.explr[2 * i] && g.explr[2 * i + 1]) {
      cout << "Impossible\n";
      return 0;
    }
    if (g.explr[2 * i + 1]) result.push_back(i + 1);
  }
  cout << result.size() << '\n';
  for (auto c : result) cout << c << ' ';
  cout << '\n';
  return 0;
}
