#include <bits/stdc++.h>
using namespace std;
struct Edge {
  int a, b;
  bool c;
  Edge() {}
  Edge(int aa, int bb, int cc) : a(aa), b(bb), c(cc) {}
};
int n, m;
bool used[101], w[101];
vector<Edge> g[101];
int h, t, q[101];
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    g[a].push_back(Edge(a, b, c));
    g[b].push_back(Edge(b, a, c));
  }
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    if (used[i]) continue;
    h = t = 0;
    q[t++] = i;
    while (h < t) {
      int v = q[h++];
      cnt += (w[v] == 1);
      for (size_t i = 0; i < g[v].size(); i++) {
        int to = g[v][i].b;
        int c = g[v][i].c;
        bool cur = !(w[v] ^ c);
        if (!used[to]) {
          used[to] = true;
          q[t++] = to;
          w[to] = cur;
        } else {
          if (cur != w[to]) {
            cout << "Impossible\n";
            return 0;
          }
        }
      }
    }
  }
  cout << cnt << "\n";
  for (int i = 1; i <= n; i++)
    if (w[i] == 1) cout << i << " ";
  return 0;
}
