#include <bits/stdc++.h>
using namespace std;
const int N = 1e2 + 5;
int C[N], n, m, rt;
vector<pair<int, int> > adj[N];
bitset<N> B;
void DFS(int u, int c) {
  B[u] = 1;
  C[u] = c;
  rt += c;
  for (pair<int, int> x : adj[u]) {
    if (!B[x.first]) {
      DFS(x.first, x.second ? c : c ^ 1);
    } else if (C[x.first] ^ (x.second ? c : c ^ 1)) {
      printf("Impossible");
      exit(0);
    }
  }
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; i++) {
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    adj[a].push_back({b, c});
    adj[b].push_back({a, c});
  }
  for (int i = 1; i <= n; i++)
    if (!B[i]) DFS(i, 1);
  printf("%d\n", rt);
  for (int i = 1; i <= n; i++)
    if (C[i]) printf("%d ", i);
}
