#include <bits/stdc++.h>
using namespace std;
void load() {}
const int N = 205;
int cs[N], n, m, cnt, typ[N];
vector<int> ed[N];
int _not(int u) {
  if (u > n) return u - n;
  return u + n;
}
void dfs(int u) {
  cs[u] = cnt;
  for (int i = 0; i < ed[u].size(); ++i) {
    int v = ed[u][i];
    if (!cs[v]) dfs(v);
  }
}
void dfs_tv(int u) {
  for (int i = 0; i < ed[u].size(); ++i) {
    int v = ed[u][i];
    if (!typ[v]) {
      typ[v] = typ[u];
      dfs_tv(v);
      if (!typ[_not(v)]) typ[_not(v)] = 3 - typ[u], dfs_tv(_not(v));
    }
  }
}
void trungtt() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; ++i) {
    int u, v, c;
    scanf("%d%d%d", &u, &v, &c);
    if (c == 0) {
      ed[u].push_back(_not(v));
      ed[v].push_back(_not(u));
      ed[_not(u)].push_back(v);
      ed[_not(v)].push_back(u);
    } else {
      ed[u].push_back(v);
      ed[v].push_back(u);
      ed[_not(u)].push_back(_not(v));
      ed[_not(v)].push_back(_not(u));
    }
  }
  for (int i = 1; i <= 2 * n; ++i)
    if (!cs[i]) {
      ++cnt;
      dfs(i);
    }
  for (int i = 1; i < n; ++i)
    if (cs[i] == cs[_not(i)]) {
      printf("Impossible");
      return;
    }
  for (int i = 1; i <= n; ++i)
    if (!typ[i]) {
      typ[i] = 1;
      typ[_not(i)] = 2;
      dfs_tv(i);
      dfs_tv(_not(i));
    }
  int res = 0;
  for (int i = 1; i <= n; ++i)
    if (typ[i] == 2) ++res;
  printf("%d\n", res);
  for (int i = 1; i <= n; ++i)
    if (typ[i] == 2) printf("%d ", i);
}
int main() {
  load();
  trungtt();
  return 0;
}
