#include <bits/stdc++.h>
using namespace std;
namespace sat {
const int MAX = 200010;
bool vis[MAX];
vector<int> ed[MAX], rev[MAX];
int n, m;
vector<int> order;
int comp[MAX];
inline int inv(int x) { return ((x) <= n ? (x + n) : (x - n)); }
void init(int vars) {
  n = vars, m = vars << 1;
  for (int i = 1; i <= m; i++) {
    ed[i].clear();
    rev[i].clear();
  }
}
inline void add(int a, int b) {
  ed[a].push_back(b);
  rev[b].push_back(a);
}
inline void OR(int a, int b) {
  add(inv(a), b);
  add(inv(b), a);
}
inline void AND(int a, int b) {
  add(a, b);
  add(b, a);
}
void XOR(int a, int b) {
  add(inv(b), a);
  add(a, inv(b));
  add(inv(a), b);
  add(b, inv(a));
}
inline void XNOR(int a, int b) {
  add(a, b);
  add(b, a);
  add(inv(a), inv(b));
  add(inv(b), inv(a));
}
inline void force_true(int x) { add(inv(x), x); }
void dfs(int s) {
  vis[s] = true;
  for (int x : ed[s]) {
    if (vis[x]) continue;
    dfs(x);
  }
  order.push_back(s);
}
void mark(int s, int c) {
  comp[s] = c;
  vis[s] = true;
  for (int x : rev[s]) {
    if (vis[x]) continue;
    mark(x, c);
  }
}
bool satisfy(vector<int> &res) {
  memset(vis, 0, sizeof(vis));
  for (int i = 1; i <= m; i++) {
    if (vis[i]) continue;
    dfs(i);
  }
  memset(vis, 0, sizeof(vis));
  reverse(order.begin(), order.end());
  int it = 0;
  for (int s : order) {
    if (vis[s]) continue;
    mark(s, ++it);
  }
  res.clear();
  for (int i = 1; i <= n; i++) {
    if (comp[i] == comp[inv(i)]) return false;
    if (comp[i] > comp[inv(i)]) res.push_back(i);
  }
  return true;
}
}  // namespace sat
int main() {
  int n, m, a, b, c;
  scanf("%d %d", &n, &m);
  sat::init(n);
  for (int i = 1; i <= m; i++) {
    scanf("%d %d %d", &a, &b, &c);
    if (c == 0)
      sat::XOR(a, b);
    else
      sat::XNOR(a, b);
  }
  vector<int> V;
  if (sat::satisfy(V)) {
    cout << V.size() << endl;
    for (int i = 0; i < V.size(); i++) cout << V[i] << " ";
    puts("");
  } else
    puts("Impossible");
  return 0;
}
