#include <bits/stdc++.h>
using namespace std;
const int MAX = 100 + 3, K = 20;
int vis[MAX], col[MAX];
vector<pair<int, int> > g[MAX];
void dfs(int u, int color = 0) {
  vis[u] = 1;
  col[u] = color;
  for (auto x : g[u]) {
    if (!vis[x.first]) {
      dfs(x.first, color ^ x.second);
    }
  }
}
void dfs2(int u) {
  vis[u] = 1;
  for (auto x : g[u]) {
    int v = x.first, color = x.second;
    if (col[u] ^ col[v] != color) {
      cout << "Impossible";
      exit(0);
    }
    if (!vis[v]) {
      dfs2(v);
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  memset(col, -1, sizeof col);
  for (int i = 0; i < m; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    g[a].push_back({b, c ^ 1});
    g[b].push_back({a, c ^ 1});
  }
  for (int i = 1; i <= n; i++) {
    if (!vis[i]) dfs(i);
  }
  memset(vis, 0, sizeof vis);
  for (int i = 1; i <= n; i++) {
    if (!vis[i]) dfs2(i);
  }
  cout << count(col + 1, col + n + 1, 1) << "\n";
  for (int i = 1; i <= n; i++) {
    if (col[i]) cout << i << " ";
  }
}
