#include <bits/stdc++.h>
using namespace std;
int n, m;
int sz[102];
int mark[102];
vector<int> ans;
vector<pair<pair<int, int>, int> > edge;
vector<pair<int, int> > adj[102];
bool Control() {
  for (int i = 0; i < m; i++) {
    if (edge[i].second == 1 &&
        mark[edge[i].first.first] != mark[edge[i].first.second]) {
      printf("Impossible\n");
      return false;
    }
    if (edge[i].second == 0 &&
        mark[edge[i].first.first] == mark[edge[i].first.second]) {
      printf("Impossible\n");
      return false;
    }
  }
  return true;
}
void dfs(int node) {
  if (mark[node] == 1) ans.push_back(node);
  for (int i = 0; i < sz[node]; i++)
    if (!mark[adj[node][i].first]) {
      if (adj[node][i].second == 1)
        mark[adj[node][i].first] = mark[node];
      else
        mark[adj[node][i].first] = 3 - mark[node];
      dfs(adj[node][i].first);
    }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    int x, y, z;
    scanf("%d%d%d", &x, &y, &z);
    sz[x]++;
    sz[y]++;
    adj[x].push_back(pair<int, int>(y, z));
    adj[y].push_back(pair<int, int>(x, z));
    edge.push_back(pair<pair<int, int>, int>(pair<int, int>(x, y), z));
  }
  for (int i = 1; i <= n; i++)
    if (!mark[i]) {
      mark[i] = 1;
      dfs(i);
    }
  if (Control()) {
    int vsz = ans.size();
    printf("%d\n", vsz);
    for (int i = 0; i < vsz; i++) printf("%d ", ans[i]);
    printf("\n");
  }
  return 0;
}
