#include <bits/stdc++.h>
using namespace std;
long long n;
vector<long long> used;
vector<long long> order;
vector<vector<long long>> g, gr;
void dfs(long long v) {
  used[v] = 1;
  for (int i = 0; i < g[v].size(); ++i) {
    long long to = g[v][i];
    if (!used[to]) dfs(to);
  }
  order.push_back(v);
}
vector<long long> res;
void dfs2(long long v) {
  res.push_back(v);
  used[v] = 1;
  for (int i = 0; i < gr[v].size(); ++i) {
    long long to = gr[v][i];
    if (!used[to]) {
      dfs2(to);
    }
  }
}
map<string, long long> mapp;
int main() {
  long long m;
  cin >> n >> m;
  g.resize(2 * n);
  gr.resize(2 * n);
  vector<pair<long long, long long>> door(n, {-1, -1});
  for (int i = 0; i < m; ++i) {
    long long x, y, c;
    cin >> x >> y >> c;
    --x;
    --y;
    if (c == 1) {
      g[x].push_back(y);
      g[y + n].push_back(x + n);
      g[y].push_back(x);
      g[x + n].push_back(y + n);
      gr[y].push_back(x);
      gr[x + n].push_back(y + n);
      gr[x].push_back(y);
      gr[y + n].push_back(x + n);
    } else {
      g[x].push_back(y + n);
      g[x + n].push_back(y);
      g[y + n].push_back(x);
      g[y].push_back(x + n);
      gr[y + n].push_back(x);
      gr[y].push_back(x + n);
      gr[x].push_back(y + n);
      gr[x + n].push_back(y);
    }
  }
  used.clear();
  used.resize(2 * n);
  for (int i = 0; i < used.size(); ++i) {
    if (!used[i]) {
      dfs(i);
    }
  }
  reverse(order.begin(), order.end());
  used.clear();
  used.resize(2 * n);
  vector<long long> comp(2 * n);
  long long num = -1;
  for (int i = 0; i < order.size(); ++i) {
    long long v = order[i];
    if (!used[v]) {
      ++num;
      res.clear();
      dfs2(v);
      for (int j = 0; j < res.size(); ++j) {
        comp[res[j]] = num;
      }
    }
  }
  for (int i = 0; i < n; ++i) {
    if (comp[i] == comp[i + n]) {
      cout << "Impossible" << endl;
      return 0;
    }
  }
  vector<long long> ans;
  for (int i = 0; i < n; ++i) {
    if (comp[i] < comp[i + n]) {
    } else {
      ans.push_back(i);
    }
  }
  cout << ans.size() << endl;
  for (int i = 0; i < ans.size(); ++i) cout << ans[i] + 1 << endl;
  return 0;
}
