#include <bits/stdc++.h>
using namespace std;
int dfsNum[2 * 105], low[2 * 105], seen[2 * 105], scc[2 * 105], num_scc, num, V;
stack<int> S;
vector<int> ady[2 * 105];
void dfs(int x) {
  dfsNum[x] = low[x] = num++;
  seen[x] = 1;
  S.push(x);
  for (int i = 0; i < ady[x].size(); ++i) {
    int y = ady[x][i];
    if (dfsNum[y] == -1) {
      dfs(y);
      low[x] = min(low[x], low[y]);
    } else if (seen[y]) {
      low[x] = min(low[x], low[y]);
    }
  }
  if (dfsNum[x] == low[x]) {
    int y;
    do {
      y = S.top();
      S.pop();
      scc[y] = num_scc;
      seen[y] = 0;
    } while (x != y);
    num_scc++;
  }
}
void build_scc() {
  memset(seen, 0, sizeof(seen));
  memset(dfsNum, -1, sizeof(dfsNum));
  num = num_scc = 0;
  for (int i = 0; i < 2 * V; ++i) {
    if (dfsNum[i] == -1) dfs(i);
  }
}
int NOT(int x) { return x + V; }
void AddXor(int a, int b, int c) {
  if (c) {
    ady[a].push_back(b);
    ady[b].push_back(a);
    ady[NOT(a)].push_back(NOT(b));
    ady[NOT(b)].push_back(NOT(a));
  } else {
    ady[a].push_back(NOT(b));
    ady[b].push_back(NOT(a));
    ady[NOT(a)].push_back(b);
    ady[NOT(b)].push_back(a);
  }
}
int main() {
  int E, u, v, c, i, out[2 * 105], len = 0;
  scanf("%d %d", &V, &E);
  while (E-- > 0 && scanf("%d %d %d", &u, &v, &c)) {
    AddXor(u - 1, v - 1, c);
  }
  build_scc();
  for (i = 0; i < V; ++i) {
    if (scc[i] == scc[NOT(i)]) break;
    if (scc[i] >= scc[NOT(i)]) out[len++] = i + 1;
  }
  if (i != V)
    puts("Impossible");
  else {
    printf("%d\n%d", len, out[0]);
    for (i = 1; i < len; ++i) {
      printf(" %d", out[i]);
    }
    printf("\n");
  }
  return 0;
}
