#include <bits/stdc++.h>
using namespace std;
int n, m;
int asph[101][101];
bool cant[101];
bool was[101];
void dfs(int v) {
  was[v] = true;
  for (int i = 0; i < n; i++) {
    if (asph[v][i] > 0) {
      if (not was[i]) {
        if (asph[v][i] == 1)
          cant[i] = !cant[v];
        else
          cant[i] = cant[v];
        dfs(i);
      }
    }
  }
}
void check(int v) {
  dfs(v);
  for (int i = 0; i < n; i++)
    if (!was[i]) dfs(i);
  int isValid = true;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) {
      if (asph[i][j] > 0) {
        if (asph[i][j] == 1)
          isValid &= cant[i] != cant[j];
        else
          isValid &= cant[i] == cant[j];
      }
    }
  if (isValid) {
    int ans = 0;
    for (int i = 0; i < n; i++) {
      ans += !cant[i];
    }
    cout << ans << endl;
    for (int i = 0; i < n; i++)
      if (!cant[i]) cout << i + 1 << " ";
    exit(0);
  }
}
int main() {
  cin >> n >> m;
  bool wasZero = false;
  for (int i = 0; i < m; i++) {
    int fr, to, cur;
    cin >> fr >> to >> cur;
    fr--;
    to--;
    cur++;
    wasZero |= cur == 1;
    asph[fr][to] = asph[to][fr] = cur;
  }
  if (not wasZero) {
    cout << "0" << endl;
    return 0;
  }
  for (int i = 0; i < n; i++) {
    memset(cant, 0, sizeof(cant));
    memset(was, 0, sizeof(was));
    check(i);
    memset(cant, 0, sizeof(cant));
    memset(was, 0, sizeof(was));
    cant[i] = true;
    check(i);
  }
  cout << "Impossible" << endl;
  return 0;
}
