#include <bits/stdc++.h>
const unsigned long long P = 239017, MaxN = 2100000, INF = 100000000;
using namespace std;
bool f;
vector<int> ans;
int m[501][501], n, m1, clr[501], used[501], have[101][101];
void dfs(int v, int c) {
  if (f) return;
  used[v] = 1;
  clr[v] = c;
  for (int i = 1; i <= n && !f; ++i) {
    if (!have[v][i]) continue;
    if (!used[i]) {
      if (m[v][i] == 1 && c == 1) {
        dfs(i, 1);
        continue;
      }
      if (m[v][i] == 1 && c == 2) {
        dfs(i, 2);
        continue;
      }
      if (m[v][i] == 0 && c == 1) {
        dfs(i, 2);
        continue;
      }
      if (m[v][i] == 0 && c == 2) {
        dfs(i, 1);
        continue;
      }
    } else if (used[i] && i != v) {
      if ((clr[v] + clr[i]) % 2 != (m[v][i] + 1) % 2) {
        f = true;
        return;
      }
    }
  }
}
int a, b, c;
int main() {
  scanf("%d%d", &n, &m1);
  bool f1 = 0;
  for (int i = 1; i <= m1; ++i) {
    scanf("%d%d%d", &a, &b, &c);
    m[a][b] = m[b][a] = c;
    have[a][b] = have[b][a] = 1;
    if (!c) f1 = 1;
  }
  if (!f1) {
    printf("0");
    return 0;
  }
  for (int i = 1; i <= n; ++i) {
    if (!used[i]) dfs(i, 1);
  }
  if (f) {
    printf("Impossible");
    return 0;
  }
  for (int i = 1; i <= n; ++i) {
    if (clr[i] == 1) ans.push_back(i);
  }
  printf("%d\n", ans.size());
  for (int i = 0; i < ans.size(); ++i) printf("%d ", ans[i]);
  return 0;
}
