#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  int i, j;
  int a, b, c, total;
  bool visited[100];
  bool visited2[100];
  bool onprend[100], toutok, z, y;
  vector<pair<int, bool> > voisins[100];
  queue<pair<int, bool> > q;
  cin >> n >> m;
  for (i = 0; i < m; i++) {
    cin >> a >> b >> c;
    if (c == 1) {
      voisins[a - 1].push_back(make_pair(b - 1, true));
      voisins[b - 1].push_back(make_pair(a - 1, true));
    } else {
      voisins[a - 1].push_back(make_pair(b - 1, false));
      voisins[b - 1].push_back(make_pair(a - 1, false));
    }
  }
  for (i = 0; i < n; i++) visited[i] = false;
  for (i = 0; i < n; i++) {
    if (!visited[i]) {
      for (j = 0; j < n; j++) visited2[j] = visited[j];
      while (!q.empty()) q.pop();
      q.push(make_pair(i, false));
      toutok = true;
      while (!q.empty() && toutok) {
        a = (q.front()).first;
        z = (q.front()).second;
        q.pop();
        if (visited2[a]) {
          if (z ^ onprend[a]) toutok = false;
        } else {
          visited2[a] = true;
          onprend[a] = z;
          for (j = 0; j < voisins[a].size(); j++) {
            b = voisins[a][j].first;
            y = voisins[a][j].second;
            if (y) {
              q.push(make_pair(b, z));
            } else {
              q.push(make_pair(b, !z));
            }
          }
        }
      }
      if (toutok) {
        for (j = 0; j < n; j++) visited[j] = visited2[j];
      } else {
        for (j = 0; j < n; j++) visited2[j] = visited[j];
        while (!q.empty()) q.pop();
        q.push(make_pair(i, true));
        toutok = true;
        while (!q.empty() && toutok) {
          a = (q.front()).first;
          z = (q.front()).second;
          q.pop();
          if (visited2[a]) {
            if (z ^ onprend[a]) toutok = false;
          } else {
            visited2[a] = true;
            onprend[a] = z;
            for (j = 0; j < voisins[a].size(); j++) {
              b = voisins[a][j].first;
              y = voisins[a][j].second;
              if (y) {
                q.push(make_pair(b, z));
              } else {
                q.push(make_pair(b, !z));
              }
            }
          }
        }
        if (!toutok) {
          printf("Impossible\n");
          return 0;
        } else {
          for (j = 0; j < n; j++) visited[j] = visited2[j];
        }
      }
    }
  }
  total = 0;
  for (i = 0; i < n; i++) {
    if (onprend[i]) total++;
  }
  cout << total << endl;
  for (i = 0; i < n; i++) {
    if (onprend[i]) printf("%d ", i + 1);
  }
  printf("\n");
  return 0;
}
