#include <bits/stdc++.h>
using namespace std;
void solutionE();
int main() {
  ios_base::sync_with_stdio(false);
  solutionE();
  return EXIT_SUCCESS;
}
long long n, m, u[128], c[128];
long long g[128][128];
bool ok;
void dfs(long long v, long long clr) {
  u[v] = 1;
  c[v] = clr + 1;
  for (long long to = 0; to < n; ++to) {
    if (to == v || g[v][to] == -1) continue;
    if (u[to]) {
      if (g[v][to] == 1) {
        if (c[v] != c[to]) ok = false;
      } else {
        if (c[v] == c[to]) ok = false;
      }
    } else {
      if (g[v][to] == 1)
        dfs(to, clr);
      else
        dfs(to, !clr);
    }
  }
}
bool check(vector<long long>& ans) {
  ans.clear();
  for (long long i = 0; i < n; ++i) {
    if (c[i] == 2) {
      ans.push_back(i);
      for (long long j = 0; j < n; ++j)
        if (i != j && g[i][j] >= 0) g[i][j] = !g[i][j], g[j][i] = !g[j][i];
    }
  }
  bool ok = true;
  for (long long i = 0; i < n; ++i)
    for (long long j = 0; j < n; ++j)
      if (i != j && g[i][j] == 0) ok = false;
  for (long long i = 0; i < n; ++i)
    if (c[i] == 2)
      for (long long j = 0; j < n; ++j)
        if (i != j && g[i][j] >= 0) g[i][j] = !g[i][j], g[j][i] = !g[j][i];
  return ok;
}
void solve() {
  memset(u, 0, sizeof(long long) * n);
  memset(c, 0, sizeof(long long) * n);
  ok = true;
  for (long long i = 0; i < n; ++i)
    if (!u[i]) dfs(i, 0);
  if (!ok) {
    cout << "Impossible" << endl;
    return;
  }
  vector<long long> ans;
  if (check(ans)) {
    cout << ans.size() << endl;
    for (long long i : ans) cout << i + 1 << " ";
    cout << endl;
    return;
  }
  for (long long i = 0; i < n; ++i)
    if (c[i] == 1)
      c[i] = 2;
    else
      c[i] = 1;
  if (check(ans)) {
    cout << ans.size() << endl;
    for (long long i : ans) cout << i + 1 << " ";
    cout << endl;
    return;
  }
  cout << "Impossible" << endl;
}
void solutionE() {
  for (; cin >> n >> m;) {
    for (long long i = 0; i < n; ++i)
      for (long long j = 0; j < n; ++j) g[i][j] = -1;
    for (long long i = 0; i < m; ++i) {
      long long a, b, c;
      cin >> a >> b >> c;
      --a, --b;
      g[a][b] = g[b][a] = c;
    }
    solve();
    cerr << endl;
  }
}
