#include <bits/stdc++.h>
using namespace std;
const int nmax = 1e2 + 42;
vector<int> eq[nmax], diff[nmax];
int n, m;
int colour[nmax];
vector<int> outp;
void dfs(int node, int col) {
  if (colour[node]) {
    if (colour[node] != col) {
      cout << "Impossible" << endl;
      exit(0);
    }
    return;
  }
  colour[node] = col;
  if (col == 1) {
    outp.push_back(node);
  }
  for (auto k : eq[node]) dfs(k, col);
  for (auto k : diff[node]) dfs(k, 3 - col);
}
int main() {
  cin >> n >> m;
  int a, b, c;
  for (int i = 1; i <= m; i++) {
    cin >> a >> b >> c;
    if (c == 0) {
      diff[a].push_back(b);
      diff[b].push_back(a);
    } else {
      eq[a].push_back(b);
      eq[b].push_back(a);
    }
  }
  for (int i = 1; i <= n; i++)
    if (colour[i] == 0) dfs(i, 1);
  cout << outp.size() << endl;
  for (auto k : outp) cout << k << " ";
  cout << endl;
  return 0;
}
