#include <bits/stdc++.h>
using namespace std;
const int N = 200 + 10;
vector<int> g[N], rg[N];
vector<int> used(N), ord, comp(N);
int cnt = 0;
void dfs1(int v) {
  used[v] = 1;
  for (auto u : g[v])
    if (!used[u]) dfs1(u);
  ord.push_back(v);
}
void dfs2(int v) {
  used[v] = 1;
  for (auto u : g[v])
    if (!used[u]) dfs2(u);
  comp[v] = cnt;
}
signed main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    int a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    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].push_back(a + n);
      g[a + n].push_back(b);
      g[b + n].push_back(a);
    }
  }
  for (int i = 0; i < 2 * n; i++)
    if (!used[i]) dfs1(i);
  reverse(ord.begin(), ord.end());
  fill(used.begin(), used.end(), 0);
  for (auto v : ord) {
    if (used[v]) continue;
    dfs2(v);
    cnt++;
  }
  vector<int> ans;
  for (int i = 0; i < n; i++) {
    if (comp[i] == comp[i + n]) {
      cout << "Impossible\n";
      return 0;
    } else if (comp[i + n] > comp[i])
      ans.push_back(i + 1);
  }
  cout << (int)ans.size() << '\n';
  for (auto v : ans) cout << v << ' ';
}
