#include <bits/stdc++.h>
using namespace std;
void PV(vector<long long> v) {
  for (long long i = 0; i < (long long)v.size(); i++) cout << v[i] << " ";
  cout << "\n";
}
void PVV(vector<pair<long long, long long> > v) {
  for (long long i = 0; i < (long long)v.size(); i++)
    cout << v[i].first << " " << v[i].second << "\n";
}
void PA(long long v[], long long n, long long x = 0) {
  for (long long i = x; i < n + x; i++) cout << v[i] << ' ';
  cout << "\n";
}
void IN(long long a[], long long n, long long x = 0) {
  for (long long i = x; i < n + x; i++) cin >> a[i];
}
inline void op() {}
const long long M = 1e9 + 7;
const long long IM = 1e18 + 37;
const long long N = 1e6 + 10;
long long n, m, col[N], a[N];
vector<long long> v[N], r[N], dr[N];
long long f(long long x) {
  if (x > 0) return 2 * x - 1;
  return -2 * x;
}
void add(long long x, long long y) {
  v[f(-x)].push_back(f(y));
  r[f(y)].push_back(f(-x));
  v[f(-y)].push_back(f(x));
  r[f(x)].push_back(f(-y));
}
bool vis[N];
vector<long long> topo;
void dfs(long long x) {
  vis[x] = 1;
  for (long long it : v[x]) {
    if (!vis[it]) dfs(it);
  }
  topo.push_back(x);
}
void solve(long long x, long long c) {
  col[x] = c;
  for (long long it : r[x]) {
    if (!col[it]) solve(it, c);
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  op();
  cin >> n >> m;
  for (long long i = 1; i <= m; i++) {
    long long x, y, c;
    cin >> x >> y >> c;
    if (c == 0) {
      add(x, y);
      add(-x, -y);
    } else {
      add(-x, y);
      add(x, -y);
    }
  }
  for (long long i = 1; i <= 2 * n; i++) {
    if (!vis[i]) dfs(i);
  }
  long long c = 1;
  reverse(topo.begin(), topo.end());
  for (long long it : topo) {
    if (!col[it]) {
      solve(it, c++);
    }
  }
  vector<long long> ans;
  for (long long i = 1; i <= 2 * n; i += 2) {
    if (col[i] == col[i + 1]) {
      cout << ("Impossible") << "\n";
      return 0;
    }
    if (col[i] > col[i + 1]) ans.push_back((i + 1) / 2);
  }
  cout << (ans.size()) << "\n";
  PV(ans);
  return 0;
}
