#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr int N = 2e5 + 5;
int n, m, d[N];
vector<pair<int, int>> adj[N];
bool dfs(int u) {
  bool f = true;
  for (auto v : adj[u]) {
    if (d[v.first] == -1) {
      d[v.first] = 1 ^ d[u] ^ v.second;
      f &= dfs(v.first);
    } else if (d[u] ^ d[v.first] ^ v.second != 1)
      return false;
  }
  return f;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    u--;
    v--;
    adj[u].push_back(make_pair(v, w));
    adj[v].push_back(make_pair(u, w));
  }
  memset(d, -1, sizeof d);
  for (int i = 0; i < n; i++) {
    if (d[i] == -1) {
      d[i] = 0;
      bool x = dfs(i);
      if (x == false) {
        cout << "Impossible";
        exit(0);
      }
    }
  }
  vector<int> ans;
  for (int i = 0; i < n; i++) {
    if (d[i]) ans.push_back(i);
  }
  cout << ans.size() << "\n";
  for (int x : ans) cout << x + 1 << " ";
  return 0;
}
