#include <bits/stdc++.h>
using namespace std;
int N, M, adj[107][107], bisa = 1, a, b, c;
bool take[107], vis[107];
vector<int> road[107];
void F(int x) {
  vis[x] = 1;
  for (auto i : road[x]) {
    if (!bisa) return;
    a = min(i, x), b = max(i, x);
    if (!vis[i]) {
      take[i] = take[x] ^ adj[a][b];
      F(i);
    } else if (take[i] != take[x] ^ adj[a][b])
      bisa = 0;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  memset(vis, 0, sizeof(vis));
  memset(take, 0, sizeof(take));
  memset(adj, -1, sizeof(adj));
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    cin >> a >> b >> c;
    if (a > b) swap(a, b);
    adj[a][b] = c ^ 1;
    road[a].push_back(b);
    road[b].push_back(a);
  }
  for (int i = 1; bisa && i <= N; i++) {
    if (!vis[i]) F(i);
  }
  if (!bisa)
    cout << "Impossible\n";
  else {
    vector<int> ans;
    for (int i = 1; i <= N; i++)
      if (take[i]) ans.push_back(i);
    cout << ans.size() << endl;
    for (auto i : ans) cout << i << ' ';
    cout << endl;
  }
}
