#include <bits/stdc++.h>
using namespace std;
vector<vector<pair<int, int> > > g;
vector<bool> color;
vector<bool> used;
int n, m;
bool dfs(int v) {
  used[v] = true;
  for (int i = 0; i < g[v].size(); i++) {
    int to = g[v][i].first;
    int road = g[v][i].second;
    if (!used[to]) {
      if (road)
        color[to] = color[v];
      else
        color[to] = !color[v];
      dfs(to);
    } else if (road == 1 && color[v] != color[to] ||
               road == 0 && color[v] == color[to])
      return false;
  }
  return true;
}
int main() {
  scanf("%d %d", &n, &m);
  g.resize(n);
  used.resize(n, false);
  color.resize(n);
  int x, y, z;
  for (int i = 0; i < m; i++) {
    scanf("%d %d %d", &x, &y, &z);
    x--;
    y--;
    g[x].push_back(make_pair(y, z));
    g[y].push_back(make_pair(x, z));
  }
  for (int i = 0; i < n; i++)
    if (!used[i])
      if (!dfs(i)) {
        printf("Impossible\n");
        return 0;
      }
  int count = 0;
  for (int i = 0; i < n; i++)
    if (color[i]) count++;
  printf("%d\n", count);
  for (int i = 0; i < n; i++)
    if (color[i]) printf("%d ", i + 1);
  printf("\n");
  return 0;
}
