#include <bits/stdc++.h>
using namespace std;
int p[500];
void init() {
  for (int i = 1; i < 500; ++i) p[i] = i;
}
int getParent(int i) {
  while (p[i] != i) {
    p[i] = p[p[i]];
    i = p[i];
  }
  return i;
}
void addEdge(int a, int b) { p[getParent(a)] = getParent(b); }
void addEdge(int a, int b, int c) {
  if (c) {
    addEdge(a * 2, b * 2 + 1);
    addEdge(a * 2 + 1, b * 2);
  } else {
    addEdge(a * 2 + 1, b * 2 + 1);
    addEdge(a * 2, b * 2);
  }
}
int sol[500];
int main() {
  init();
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    int a, b, c;
    cin >> a >> b >> c;
    addEdge(a, b, !c);
  }
  for (int i = 1; i <= n; ++i) {
    if (getParent(i * 2) == getParent(i * 2 + 1)) {
      cout << "Impossible" << endl;
      return 0;
    }
  }
  memset(sol, -1, sizeof sol);
  vector<int> req;
  for (int i = 1; i <= n; ++i) {
    int par = getParent(i * 2);
    if (sol[par] == -1) {
      sol[par] = 1;
      sol[getParent(i * 2 + 1)] = 0;
    }
    if (sol[par]) req.push_back(i);
  }
  cout << req.size() << endl;
  for (auto x : req) cout << x << " ";
  cout << endl;
  return 0;
}
