#include <bits/stdc++.h>
using namespace std;
const int MAXN = 210;
struct union_find {
  int par[MAXN];
  int find(int x) { return x == par[x] ? x : par[x] = find(par[x]); }
  void merge(int x, int y) { par[find(x)] = find(y); }
} uf;
int N, M;
int col[MAXN];
int main() {
  scanf("%d %d", &N, &M);
  for (int i = 0; i < 2 * N; i++) {
    uf.par[i] = i;
  }
  for (int i = 0, x, y, c; i < M; i++) {
    scanf("%d %d %d", &x, &y, &c);
    x--;
    y--;
    uf.merge(2 * x, 2 * y + !c);
    uf.merge(2 * x + 1, 2 * y + c);
  }
  for (int i = 0; i < 2 * N; i += 2) {
    if (uf.find(i) == uf.find(i + 1)) {
      puts("Impossible");
      return 0;
    }
  }
  memset(col, -1, sizeof(col));
  for (int i = 0; i < N; i++) {
    if (col[i] == -1) {
      col[i] = 0;
      for (int j = 0; j < N; j++) {
        for (int k = 0; k < 2; k++) {
          if (uf.find(2 * j + k) == uf.find(2 * i)) {
            col[i] = k;
            break;
          }
        }
      }
    }
  }
  vector<int> ans;
  for (int i = 0; i < N; i++) {
    assert(col[i] != -1);
    if (col[i]) {
      ans.push_back(i);
    }
  }
  printf("%lu\n", ans.size());
  for (int x : ans) {
    printf("%d ", x + 1);
  }
}
