#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<pair<int, int> > e[205];
bool v[205];
bool act[205];
int marked;
void dfs(int k, bool on) {
  if (v[k]) return;
  act[k] = on;
  v[k] = true;
  if (act[k]) marked++;
  for (int i = 0; i < e[k].size(); i++) {
    if (e[k][i].second == 0) {
      dfs(e[k][i].first, !act[k]);
    } else {
      dfs(e[k][i].first, act[k]);
    }
  }
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    e[a].push_back(pair<int, int>(b, c));
    e[b].push_back(pair<int, int>(a, c));
  }
  for (int i = 0; i < n; i++) {
    dfs(i, 0);
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < e[i].size(); j++) {
      if (e[i][j].second == 0 && act[i] == act[e[i][j].first] ||
          e[i][j].second == 1 && act[i] != act[e[i][j].first]) {
        cout << "Impossible";
        return 0;
      }
    }
  }
  cout << marked << "\n";
  for (int i = 0; i < n; i++) {
    if (act[i]) {
      cout << i + 1 << " ";
    }
  }
  return 0;
}
