#include <bits/stdc++.h>
using namespace std;
struct Edge {
  int a, b;
  bool c;
  Edge() {}
  Edge(int aa, int bb, int cc) : a(aa), b(bb), c(cc) {}
};
int n, m;
bool used[101], u[2][101], of[2][101];
set<int> ans;
vector<Edge> g[101];
int q[101];
bool bfs(int v, int f) {
  int h = 0, t = 0;
  q[t++] = v;
  of[f][v] = f;
  u[f][v] = true;
  bool res = true;
  for (; h < t; h++) {
    v = q[h];
    for (size_t i = 0; i < g[v].size(); i++) {
      int to = g[v][i].b;
      bool c = g[v][i].c;
      if (u[f][to]) {
        bool cur = !(of[f][v] ^ c);
        if (cur != of[f][to]) res = false;
      } else {
        of[f][to] = !(of[f][v] ^ c);
        u[f][to] = used[to] = true;
        q[t++] = to;
      }
    }
  }
  return res;
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    g[a].push_back(Edge(a, b, c));
    g[b].push_back(Edge(b, a, c));
  }
  for (int i = 1; i <= n; i++) {
    if (used[i]) continue;
    for (int j = 1; j <= n; j++) u[0][j] = u[1][j] = used[j];
    bool good = false;
    for (int f = 0; f < 2; f++) {
      if (bfs(i, f)) {
        for (int j = 1; j <= n; j++)
          if (of[f][j]) ans.insert(j);
        good = true;
        break;
      }
    }
    if (!good) {
      cout << "Impossible\n";
      return 0;
    }
  }
  cout << ans.size() << "\n";
  while (!ans.empty()) {
    cout << *(ans.begin()) << "\n";
    ans.erase(ans.begin());
  }
  return 0;
}
