#include <bits/stdc++.h>
using namespace std;
bool err = false;
int n, m;
bool A[111];
int G[111][111];
bool vis[111];
void dfs(int d) {
  vis[d] = true;
  bool v = A[d];
  for (int i = 1; i <= n; i++) {
    if (G[d][i] == 0) {
      if (vis[i] == false) {
        A[i] = !v;
        dfs(i);
      } else {
        if (A[i] != (!v)) err = true;
      }
    }
    if (G[d][i] == 1) {
      if (vis[i] == false) {
        A[i] = v;
        dfs(i);
      } else {
        if (A[i] != v) err = true;
      }
    }
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) G[i][j] = 2;
  int a, b, c;
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d", &a, &b, &c);
    G[a][b] = c;
    G[b][a] = c;
  }
  for (int i = 1; i <= n; i++)
    if (vis[i] == false) {
      A[i] = 0;
      dfs(i);
    }
  if (err)
    printf("Impossible\n");
  else {
    int ct = 0, c = 0;
    for (int i = 1; i <= n; i++)
      if (A[i] == 1) ct++;
    printf("%d\n", ct);
    for (int i = 1; i <= n; i++)
      if (A[i] == 1) {
        c++;
        if (c == ct)
          printf("%d\n", i);
        else
          printf("%d ", i);
      }
  }
  return 0;
}
