#include <bits/stdc++.h>
const double PI = acos(-1);
const int maxn = 1e2 + 18;
const int INF = 1e9;
const int MOD = 2e9;
using namespace std;
int n, m, k, qq, kmp = 1;
vector<vector<int>> g(maxn << 1);
vector<int> was(maxn << 1), comp(maxn << 1), res;
void dfs(int v) {
  was[v] = 1;
  comp[v] = kmp;
  for (int i : g[v]) {
    if (!was[i]) dfs(i);
  }
}
void solve() {
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    int a, b, c;
    cin >> a >> b >> c;
    if (c) {
      g[a].push_back(b), g[b].push_back(a);
      g[a + n].push_back(b + n), g[b + n].push_back(a + n);
    } else {
      g[a].push_back(b + n), g[b + n].push_back(a);
      g[a + n].push_back(b), g[b].push_back(a + n);
    }
  }
  for (int i = 1; i <= (n << 1); ++i) {
    if (!was[i]) dfs(i), kmp++;
  }
  for (int i = 1; i <= n; ++i) {
    if (comp[i] == comp[i + n]) {
      cout << "Impossible";
      return;
    }
    if (comp[i] < comp[i + n]) res.push_back(i);
  }
  cout << (int)(res).size() << '\n';
  for (int i : res) cout << i << ' ';
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  qq = 1;
  while (qq--) solve();
  return 0;
}
