#include <bits/stdc++.h>
using namespace std;
const int MAXN = 205;
vector<int> g[MAXN];
vector<int> g2[MAXN];
bool mark[MAXN];
vector<int> topo;
inline void addE(int x, int y) {
  g[x ^ 1].push_back(y);
  g2[y].push_back(x ^ 1);
  g[y ^ 1].push_back(x);
  g2[x].push_back(y ^ 1);
}
void dfs(int u) {
  mark[u] = true;
  for (int i = 0; i < g[u].size(); i++) {
    int v = g[u][i];
    if (!mark[v]) dfs(v);
  }
  topo.push_back(u);
}
int cc;
int comp[MAXN];
void dfs2(int u) {
  mark[u] = true;
  comp[u] = cc;
  for (int i = 0; i < g2[u].size(); i++) {
    int v = g2[u][i];
    if (!mark[v]) dfs2(v);
  }
}
int ans[MAXN];
vector<int> fans;
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    u--;
    v--;
    u *= 2;
    v *= 2;
    if (!w) {
      addE(u, v);
      addE(u ^ 1, v ^ 1);
    } else {
      addE(u, v ^ 1);
      addE(u ^ 1, v);
    }
  }
  for (int i = 0; i < n * 2; i++)
    if (!mark[i]) dfs(i);
  memset(mark, 0, sizeof mark);
  for (int i = topo.size() - 1; i >= 0; i--) {
    int u = topo[i];
    if (!mark[u]) {
      dfs2(u);
      cc++;
    }
  }
  for (int i = 0; i < n * 2; i++)
    if (comp[i] == comp[i ^ 1]) {
      cout << "Impossible" << endl;
      return 0;
    }
  for (int i = 0; i < topo.size(); i++) {
    int u = topo[i];
    if (ans[u]) continue;
    ans[u] = 1;
    ans[u ^ 1] = 2;
  }
  for (int i = 0; i < n * 2; i += 2)
    if (ans[i] == 2) fans.push_back(i / 2 + 1);
  cout << fans.size() << endl;
  for (int i = 0; i < fans.size(); i++) cout << fans[i] << ' ';
  return 0;
}
