#include <bits/stdc++.h>
using namespace std;
const int N = 100000 + 5;
const int M = 3e4 + 5;
const int mod = 1e9 + 7;
const int MAX_LOG = 16;
const int inf = 0x3f3f3f3f;
int readint() {
  char c = getchar();
  while (!isdigit(c)) c = getchar();
  int res = 0;
  while (isdigit(c)) res = res * 10 + c - '0', c = getchar();
  return res;
}
int n, m;
int vis[222];
vector<int> edge[222];
int c, S[222];
bool dfs(int x) {
  if (vis[x ^ 1]) return 0;
  if (vis[x]) return 1;
  vis[x] = 1;
  S[c++] = x;
  for (int i = 0; i < edge[x].size(); i++) {
    if (!dfs(edge[x][i])) return 0;
  }
  return 1;
}
bool solve() {
  for (int i = 0; i < n * 2; i += 2) {
    if (!vis[i] && !vis[i + 1]) {
      c = 0;
      if (!dfs(i)) {
        while (c > 0) vis[S[--c]] = 0;
        if (!dfs(i + 1)) return 0;
      }
    }
  }
  return 1;
}
int main() {
  scanf("%d%d", &n, &m);
  vector<pair<int, int> > gg;
  for (int i = 0; i < m; i++) {
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    a--, b--;
    if (c == 1) {
      edge[a << 1].push_back(b << 1);
      edge[b << 1].push_back(a << 1);
      edge[a * 2 + 1].push_back(b * 2 + 1);
      edge[b * 2 + 1].push_back(a * 2 + 1);
    } else {
      gg.push_back(make_pair(a, b));
      edge[a << 1].push_back(b * 2 + 1);
      edge[b * 2 + 1].push_back(a << 1);
      edge[a * 2 + 1].push_back(b << 1);
      edge[b << 1].push_back(a * 2 + 1);
    }
  }
  memset(vis, 0, sizeof(vis));
  int ans = solve();
  if (!ans)
    puts("Impossible");
  else {
    vector<int> p;
    for (int i = 0; i < 2 * n; i += 2)
      if (vis[i]) p.push_back(i / 2 + 1);
    printf("%d\n", p.size());
    for (int i = 0; i < p.size(); i++) {
      if (i) printf(" ");
      printf("%d", p[i]);
    }
    puts("");
  }
  return 0;
}
