#include <bits/stdc++.h>
using namespace std;
vector<int> adj[1024];
int ncomp;
int comp[1024];
int vis[1024], stck[1024], t, high[1024];
int num;
void dfscc(int u) {
  int i, v;
  high[u] = vis[u] = num--;
  stck[t++] = u;
  for (i = 0; i < (int)adj[u].size(); i++) {
    v = adj[u][i];
    if (!vis[v]) {
      dfscc(v);
      high[u] = max(high[u], high[v]);
    } else if (vis[v] > vis[u] && !comp[v])
      high[u] = max(high[u], vis[v]);
  }
  if (high[u] == vis[u]) {
    ncomp++;
    do {
      v = stck[--t];
      comp[v] = ncomp;
    } while (v != u);
  }
}
void scc(int n) {
  ncomp = t = 0;
  num = n;
  memset(vis, 0, sizeof(vis));
  memset(comp, 0, sizeof(comp));
  for (int i = 0; i < n; i++)
    if (!vis[i]) dfscc(i);
}
bool two_sat(int n) {
  n *= 2;
  bool ok = true;
  scc(n);
  for (int i = 0; i < n / 2 && ok; i++) ok &= (comp[2 * i] != comp[2 * i + 1]);
  return ok;
}
int getsol(int x) { return comp[2 * x] < comp[2 * x + 1]; }
void clau(int x, int y) {
  int negx = (x % 2 == 1 ? x - 1 : x + 1), negy = (y % 2 == 1 ? y - 1 : y + 1);
  adj[negx].push_back(y);
  adj[negy].push_back(x);
}
int main() {
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  while (m--) {
    int x, y, w;
    cin >> x >> y >> w;
    --x;
    --y;
    if (w) {
      clau((2 * x + 1), (2 * y));
      clau((2 * x), (2 * y + 1));
    } else {
      clau((2 * x + 1), (2 * y + 1));
      clau((2 * x), (2 * y));
    }
  }
  if (!two_sat(n))
    cout << "Impossible\n";
  else {
    vector<int> ans;
    for (int i = 0; i < (n); ++i)
      if (getsol(i)) ans.push_back(i + 1);
    cout << (int)((ans).size()) << endl;
    for (int x : ans) cout << x << " ";
    cout << endl;
  }
}
