#include <bits/stdc++.h>
using namespace std;
const signed long long int inf = 5000000000000000000;
const signed long long int sup = -inf;
const signed long long int mod = 1000000007;
const signed long long int nmax = 100001;
signed long long int n, m;
std::vector<signed long long int> ct[nmax << 1];
signed long long int a[nmax];
signed long long int on[nmax];
signed long long int visit[nmax];
signed long long int scc[nmax << 1];
signed long long int low[nmax << 1];
signed long long int num[nmax << 1];
std::vector<signed long long int> res;
signed long long int anise, cnt;
stack<signed long long int> ss;
void dfs(signed long long int u) {
  low[u] = num[u] = ++anise;
  ss.push(u);
  for (auto v : ct[u]) {
    if (scc[v]) continue;
    if (num[v]) {
      low[u] = min(low[u], num[v]);
      continue;
    }
    dfs(v);
    low[u] = min(low[u], low[v]);
  }
  if (low[u] == num[u]) {
    cnt++;
    signed long long int v = 0;
    do {
      v = ss.top();
      ss.pop();
      scc[v] = cnt;
    } while (u != v);
  }
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> a) {
  os << "";
  for (T &x : a) os << x << " ";
  os << "\n";
  return os;
}
int main() {
  if (fopen("FLIGHT.inp", "r")) {
    freopen("FLIGHT.inp", "r", stdin);
    freopen("FLIGHT.out", "w", stdout);
  }
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (signed long long int i = 1; i <= m; ++i) {
    signed long long int x, y;
    cin >> x >> y;
    cin >> a[i];
    if (!a[i]) {
      ct[x].push_back(y + n);
      ct[y].push_back(x + n);
      ct[x + n].push_back(y);
      ct[y + n].push_back(x);
    } else {
      ct[x].push_back(y);
      ct[y].push_back(x);
      ct[x + n].push_back(y + n);
      ct[y + n].push_back(x + n);
    }
  }
  for (signed long long int i = 1; i <= n; ++i) {
    if (!num[i]) dfs(i);
    if (!num[i + n]) dfs(i + n);
  }
  std::vector<signed long long int> res;
  for (signed long long int i = 1; i <= n; ++i) {
    if (scc[i] == scc[i + n]) {
      cout << "Impossible";
      return 0;
    }
    if (scc[i] >= scc[i + n]) res.push_back(i);
  }
  cout << res.size() << "\n";
  cout << res;
  return 0;
}
