#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const double eps = 1e-8;
const int maxn = 105;
vector<pair<int, int> > adj[maxn];
int n, m, color[maxn];
inline void add(int a, int b, int c) { adj[a].push_back(make_pair(b, c)); }
inline bool dfs(int u, int c) {
  if (color[u] != -1) {
    if (color[u] != c) return false;
    return true;
  }
  color[u] = c;
  for (int i = 0; i < adj[u].size(); ++i) {
    if (!dfs(adj[u][i].first, c ^ adj[u][i].second)) return false;
  }
  return true;
}
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);
    c ^= 1;
    add(a, b, c);
    add(b, a, c);
  }
  memset(color, -1, sizeof(color));
  bool found = true;
  for (int i = 1; i <= n && found; ++i) {
    if (color[i] == -1) {
      if (!dfs(i, 0)) {
        found = false;
      }
    }
  }
  if (!found)
    puts("Impossible");
  else {
    int c = 0;
    for (int i = 1; i <= n; ++i) {
      c += color[i];
    }
    printf("%d\n", c);
    for (int i = 1; i <= n; ++i) {
      if (color[i] == 1) {
        printf("%d ", i);
      }
    }
    puts("");
  }
  return 0;
}
