#include <bits/stdc++.h>
using namespace std;
int n, m, u, v, val, col[111], ans;
vector<int> adj[222], adjv[222];
queue<int> q;
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> m;
  while (m--) {
    cin >> u >> v >> val;
    if (val) {
      adj[u].push_back(v);
      adj[v].push_back(u);
    } else {
      adjv[u].push_back(v);
      adjv[v].push_back(u);
    }
  }
  memset(col, -1, sizeof(col));
  for (int i = (1); i <= (n); i++)
    if (col[i] == -1) {
      q.push(i);
      col[i] = 0;
      while (!q.empty()) {
        v = q.front();
        q.pop();
        for (auto nex : adj[v]) {
          if (col[nex] == -1) {
            col[nex] = col[v];
            q.push(nex);
          } else if (col[nex] != col[v]) {
            cout << "Impossible";
            return 0;
          }
        }
        for (auto nex : adjv[v]) {
          if (col[nex] == -1) {
            col[nex] = 1 - col[v];
            q.push(nex);
          } else if (col[nex] == col[v]) {
            cout << "Impossible";
            return 0;
          }
        }
      }
    }
  for (int i = (1); i <= (n); i++) ans += col[i];
  cout << ans << endl;
  for (int i = (1); i <= (n); i++)
    if (col[i]) cout << i << ' ';
}
