#include <bits/stdc++.h>
using namespace std;
const int N = 100 + 5;
int n, m, ord[N << 1], nord = 0;
vector<int> adj[N << 1], radj[N << 1];
bool vis[N << 1];
int ncmp = 0, cmp[N << 1];
vector<int> ans;
inline void addedge(int u, int v) {
  adj[u].push_back((v > n ? v - n : v + n));
  ;
  radj[(v > n ? v - n : v + n)].push_back(u);
  ;
  adj[(u > n ? u - n : u + n)].push_back(v);
  ;
  radj[v].push_back((u > n ? u - n : u + n));
  ;
}
inline void dfs(int v) {
  vis[v] = 1;
  for (int i = 0; i < (int)adj[v].size(); i++)
    if (!vis[adj[v][i]]) dfs(adj[v][i]);
  ord[++nord] = v;
}
inline void rdfs(int v) {
  cmp[v] = ncmp;
  vis[v] = 1;
  for (int i = 0; i < (int)radj[v].size(); i++)
    if (!vis[radj[v][i]]) rdfs(radj[v][i]);
}
int main() {
  scanf("%d%d", &n, &m);
  int u, v, c;
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d", &u, &v, &c);
    if (!c) {
      addedge(u, v);
      addedge(v, u);
    } else {
      addedge(u, (v > n ? v - n : v + n));
      addedge((v > n ? v - n : v + n), u);
    }
  }
  memset(vis, 0, sizeof vis);
  for (int i = 1; i <= 2 * n; i++)
    if (!vis[i]) dfs(i);
  memset(vis, 0, sizeof vis);
  for (; nord--;) {
    u = ord[nord];
    if (!vis[u]) {
      ncmp++;
      rdfs(u);
    }
  }
  for (int i = 1; i <= n; i++) {
    if (cmp[i] == cmp[i + n]) {
      printf("Impossible\n");
      return 0;
    }
    if (cmp[i + n] < cmp[i]) ans.push_back(i);
    ;
  }
  printf("%d\n", (int)ans.size());
  for (int i = 0; i < (int)ans.size(); i++) printf("%d ", ans[i]);
  printf("\n");
  return 0;
}
