#include <bits/stdc++.h>
using namespace std;
const int MAXN = 405;
vector<int> g[MAXN];
vector<int> gr[MAXN];
vector<int> g2[MAXN];
int n, m;
inline int neg(int u) { return ((u <= n) ? u + n : u - n); }
bool mk[MAXN];
int order[MAXN], posord;
void dfs1(int u, vector<int> *g) {
  if (mk[u]) {
    return;
  }
  mk[u] = true;
  for (int i = 0; i < (int)(g[u].size()); ++i) {
    dfs1(g[u][i], g);
  }
  order[posord--] = u;
}
int SCC[MAXN], sccnum;
void dfs2(int u, int root) {
  if (mk[u]) {
    return;
  }
  mk[u] = true;
  SCC[u] = SCC[root];
  for (int i = 0; i < (int)(gr[u].size()); ++i) {
    dfs2(g[u][i], root);
  }
}
int color[MAXN];
int SCCORD[MAXN];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 0; i < (int)(m); ++i) {
    int u, v, c;
    cin >> u >> v >> c;
    if ((c == 1)) {
      g[u].push_back(v);
      g[v].push_back(u);
      g[neg(u)].push_back(neg(v));
      g[neg(v)].push_back(neg(u));
    } else {
      g[u].push_back(neg(v));
      g[neg(v)].push_back(u);
      g[neg(u)].push_back(v);
      g[v].push_back(neg(u));
    }
  }
  for (int i = 1; i <= (int)(2 * n); ++i) {
    int u;
    u = i;
    for (int i = 0; i < (int)(g[u].size()); ++i) {
      int v;
      v = g[u][i];
      gr[v].push_back(u);
    }
  }
  posord = 2 * n;
  for (int i = 1; i <= (int)(2 * n); ++i) {
    int u;
    u = i;
    if (!mk[u]) {
      dfs1(u, g);
    }
  }
  fill(mk, mk + 2 * n + 1, false);
  sccnum = 0;
  for (int i = 1; i <= (int)(2 * n); ++i) {
    int u;
    u = order[i];
    if (!mk[u]) {
      sccnum++;
      SCC[u] = sccnum;
      dfs2(u, u);
    }
  }
  for (int u = 1; u <= (int)(n); ++u) {
    cerr << SCC[u] << ' ';
  }
  cerr << '\n';
  for (int u = 1; u <= (int)(n); ++u) {
    cerr << SCC[neg(u)] << ' ';
  }
  cerr << '\n';
  for (int u = 1; u <= (int)(n); ++u) {
    if ((SCC[u] == SCC[neg(u)])) {
      cout << "Impossible\n";
      return 0;
    }
  }
  for (int u = 1; u <= (int)(2 * n); ++u) {
    for (int i = 0; i < (int)(g[u].size()); ++i) {
      int v;
      v = g[u][i];
      if (!(SCC[u] == SCC[v])) {
        g2[SCC[u]].push_back(SCC[v]);
      }
    }
  }
  fill(mk, mk + sccnum + 1, false);
  posord = sccnum;
  for (int u = 1; u <= (int)(sccnum); ++u) {
    if (!mk[u]) {
      dfs1(u, g2);
    }
  }
  for (int i = 1; i <= (int)(sccnum); ++i) {
    SCCORD[order[i]] = i;
  }
  vector<int> sol;
  for (int u = 1; u <= (int)(n); ++u) {
    if (SCCORD[SCC[u]] > SCCORD[SCC[neg(u)]]) {
      sol.push_back(u);
    }
  }
  cout << sol.size() << '\n';
  for (int i = 0; i < (int)(sol.size()); ++i) {
    if (i > 0) {
      cout << ' ';
    }
    cout << sol[i];
  }
  if (sol.size() > 0) {
    cout << '\n';
  }
}
