#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> g1, g2;
vector<int> ord, used, col;
int now1 = 0;
void add(int i, int j) {
  g1[i ^ 1].push_back(j);
  g1[j ^ 1].push_back(i);
  g2[j].push_back(i ^ 1);
  g2[i].push_back(j ^ 1);
}
void topsort(int v) {
  used[v] = 1;
  for (int i : g1[v]) {
    if (!used[i]) {
      topsort(i);
    }
  }
  ord.push_back(v);
}
void dfs(int v) {
  col[v] = now1;
  for (int i : g2[v]) {
    if (col[i] == 0) {
      dfs(i);
    }
  }
}
signed main() {
  int n, m;
  cin >> n >> m;
  g1.resize(2 * n);
  g2.resize(2 * n);
  used.resize(2 * n);
  col.resize(2 * n);
  vector<vector<pair<int, int>>> a(n);
  for (int i = 0; i < m; ++i) {
    int o, k, c;
    cin >> o >> k >> c;
    a[o - 1].emplace_back(k - 1, c);
    a[k - 1].emplace_back(o - 1, c);
  }
  for (int i = 0; i < n; ++i) {
    for (pair<int, int> j : a[i]) {
      if (j.second == 0) {
        add(i * 2, j.first * 2);
        add(i * 2 + 1, j.first * 2 + 1);
      } else {
        add(i * 2 + 1, j.first * 2);
        add(i * 2, j.first * 2 + 1);
      }
    }
  }
  for (int i = 0; i < 2 * n; ++i) {
    if (!used[i]) {
      topsort(i);
    }
  }
  reverse(ord.begin(), ord.end());
  for (int i = 0; i < 2 * n; ++i) {
    if (col[ord[i]] == 0) {
      ++now1;
      dfs(ord[i]);
    }
  }
  for (int i = 0; i < n; ++i) {
    if (col[i * 2] == col[i * 2 + 1]) {
      cout << "Impossible";
      return 0;
    }
  }
  int ans1 = 0;
  for (int i = 0; i < n; ++i) {
    if (col[i * 2] > col[i * 2 + 1]) {
      ++ans1;
    }
  }
  cout << ans1 << "\n";
  for (int i = 0; i < n; ++i) {
    if (col[i * 2] > col[i * 2 + 1]) {
      cout << i + 1 << " ";
    }
  }
  return 0;
}
