#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, x, y, z;
  cin >> n >> m;
  vector<vector<int> > G1(n), G2(n);
  for (int i = 0; i < m; ++i) {
    cin >> x >> y >> z;
    if (z) {
      G2[x - 1].push_back(y - 1);
      G2[y - 1].push_back(x - 1);
    } else {
      G1[x - 1].push_back(y - 1);
      G1[y - 1].push_back(x - 1);
    }
  }
  vector<int> color(n, -1);
  for (int i = 0; i < n; ++i) {
    if (color[i] == -1) {
      stack<int> dfs;
      dfs.push(i);
      color[i] = 0;
      while (!dfs.empty()) {
        int top = dfs.top();
        dfs.pop();
        for (int j = 0; j < G1[top].size(); ++j) {
          if (color[G1[top][j]] == color[top]) {
            cout << "Impossible\n";
            return 0;
          }
          if (color[G1[top][j]] == -1) {
            color[G1[top][j]] = 1 - color[top];
            dfs.push(G1[top][j]);
          }
        }
        for (int j = 0; j < G2[top].size(); ++j) {
          if (color[G2[top][j]] == (1 - color[top])) {
            cout << "Impossible\n";
            return 0;
          }
          if (color[G2[top][j]] == -1) {
            color[G2[top][j]] = color[top];
            dfs.push(G2[top][j]);
          }
        }
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    if (color[i]) ans++;
  }
  cout << ans << "\n";
  for (int i = 0; i < n; ++i) {
    if (color[i]) cout << i + 1 << " ";
  }
  return 0;
}
