#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 200 + 10;
int n, m, comp[MAX_N];
bool mark[MAX_N], state[MAX_N];
vector<int> adj[MAX_N], rev[MAX_N], topol;
int NOT(int v) { return 2 * n - v - 1; }
void add_clause(int u, int v) {
  adj[u].push_back(v);
  adj[NOT(v)].push_back(NOT(u));
  rev[v].push_back(u);
  rev[NOT(u)].push_back(NOT(v));
}
void read_input() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    int u, v, c;
    scanf("%d%d%d", &u, &v, &c);
    u--, v--;
    if (c) {
      add_clause(u, v);
      add_clause(NOT(u), NOT(v));
    } else {
      add_clause(u, NOT(v));
      add_clause(NOT(u), v);
    }
  }
}
void rev_dfs(int v, int k) {
  mark[v] = true;
  comp[v] = k;
  for (int u : rev[v])
    if (!mark[u]) rev_dfs(u, k);
}
void dfs(int v) {
  mark[v] = true;
  for (int u : adj[v])
    if (!mark[u]) dfs(u);
  topol.push_back(v);
}
void scc() {
  for (int i = 0; i < 2 * n; i++)
    if (!mark[i]) dfs(i);
  memset(mark, false, sizeof mark);
  reverse(topol.begin(), topol.end());
  int cnt = 0;
  for (int i : topol)
    if (!mark[i]) rev_dfs(i, cnt++);
}
void imp() {
  printf("Impossible");
  exit(0);
}
void sat() {
  scc();
  for (int i = 0; i < n; i++)
    if (comp[i] == comp[NOT(i)])
      imp();
    else if (comp[i] > comp[NOT(i)])
      state[i] = true;
}
void print_output() {
  int x = 0;
  for (int i = 0; i < n; i++) x += state[i];
  printf("%d\n", x);
  for (int i = 0; i < n; i++)
    if (state[i]) printf("%d ", i + 1);
}
int main() {
  read_input();
  sat();
  print_output();
}
