#include <bits/stdc++.h>
using namespace std;
int n, m, country[101][101], color[101];
bool dfs(int v, int c, vector<int>& cities) {
  color[v] = c;
  if (c == 1) cities.push_back(v);
  for (int w = 1; w <= n; w++)
    if (country[v][w] != -1)
      if (color[w] != -1) {
        if (country[v][w] == 0 && color[v] == color[w]) return false;
        if (country[v][w] == 1 && color[v] != color[w]) return false;
      } else if (!dfs(w, country[v][w] ? c : !c, cities))
        return false;
  return true;
}
int main() {
  fill(*country, *country + 101 * 101, -1);
  fill(color, color + 101, -1);
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    country[a][b] = c;
    country[b][a] = c;
  }
  vector<int> cities;
  for (int v = 1; v <= n; v++)
    if (color[v] == -1 && !dfs(v, 1, cities)) {
      cout << "Impossible\n";
      return 0;
    }
  cout << cities.size() << endl;
  for (int i = 0; i < cities.size(); i++) cout << cities[i] << " ";
  cout << endl;
  return 0;
}
