#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
inline int yes(int x) { return x * 2; }
inline int no(int x) { return x * 2 + 1; }
vector<int> E1[210], E2[210];
inline void build(int x, int y) {
  E1[x].push_back(y);
  E2[y].push_back(x);
}
bool vis[210];
vector<int> ord;
int scc[210];
int nid = 0;
int cho[210];
void dfs1(int x) {
  vis[x] = 1;
  for (auto i : E1[x]) {
    if (!vis[i]) dfs1(i);
  }
  ord.push_back(x);
}
void dfs2(int x) {
  vis[x] = 1;
  scc[x] = nid;
  cho[x] = -1;
  for (auto i : E2[x]) {
    if (!vis[i]) dfs2(i);
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ;
  int n, m;
  cin >> n >> m;
  for (int i = 0, a, b, c; i < m; i++) {
    cin >> a >> b >> c;
    if (c) {
      build(yes(a), yes(b));
      build(no(a), no(b));
      build(no(b), no(a));
      build(yes(b), yes(a));
    } else {
      build(no(a), yes(b));
      build(no(b), yes(a));
      build(yes(b), no(a));
      build(yes(a), no(b));
    }
  }
  for (int i = 1; i <= 2 * n; i++) {
    if (!vis[i]) dfs1(i);
  }
  memset(vis, 0, sizeof(vis));
  reverse(ord.begin(), ord.end());
  for (auto &j : ord) {
    if (!vis[j]) {
      nid++;
      dfs2(j ^ 1);
      if (vis[j]) {
        cout << "Impossible\n";
        return 0;
      }
      cho[j] = 1;
    }
  }
  vector<int> ans;
  for (int i = 1; i <= n; i++) {
    if (cho[yes(i)] == 1) {
      ans.push_back(i);
    }
  }
  cout << ans.size() << '\n';
  for (auto i : ans) {
    cout << i << " ";
  }
  cout << '\n';
}
