#include <bits/stdc++.h>
using namespace std;
const long long N = 105;
vector<long long> g[N], wt[N];
long long col[N];
bool dfs(long long x) {
  for (long long i = 0; i < g[x].size(); i++) {
    long long y = g[x][i];
    long long w = wt[x][i];
    if (w == 1) {
      if (col[y] == 0) {
        col[y] = col[x];
        if (dfs(y)) return true;
      } else if (col[y] != col[x])
        return true;
    } else {
      if (col[y] == 0) {
        if (col[x] == 1)
          col[y] = 2;
        else
          col[y] = 1;
        if (dfs(y)) return true;
      } else if (col[y] == col[x])
        return true;
    }
  }
  return false;
}
void solve() {
  long long n, m, x, y, c;
  cin >> n >> m;
  for (__typeof((m)) i = (1); i <= (m); i++) {
    cin >> x >> y >> c;
    g[x].push_back(y);
    g[y].push_back(x);
    wt[x].push_back(c);
    wt[y].push_back(c);
  }
  for (__typeof((n)) i = (1); i <= (n); i++) {
    if (col[i] == 0) {
      col[i] = 1;
      if (dfs(i) == true) {
        cout << "Impossible" << '\n';
        return;
      }
    }
  }
  vector<long long> v;
  for (__typeof((n)) i = (1); i <= (n); i++) {
    if (col[i] == 1) v.push_back(i);
  }
  cout << (long long)v.size() << '\n';
  for (long long x : v) cout << x << " ";
  cout << '\n';
}
signed main() {
  long long t;
  ios_base::sync_with_stdio(false);
  t = 1;
  while (t--) solve();
  return 0;
}
