#include <bits/stdc++.h>
using namespace std;
int i, j, n, m, a, b, c, mas[20005], z, r, rez[20005], rr[20005][3], gg,
    atb[20005];
using namespace std;
class Graph {
  int V;
  list<int> *adj;
  void SCCUtil(int u, int disc[], int low[], stack<int> *st,
               bool stackMember[]);

 public:
  Graph(int V);
  void addEdge(int v, int w);
  void SCC();
};
Graph::Graph(int V) {
  this->V = V;
  adj = new list<int>[V];
}
void Graph::addEdge(int v, int w) { adj[v].push_back(w); }
void Graph::SCCUtil(int u, int disc[], int low[], stack<int> *st,
                    bool stackMember[]) {
  static int time = 0;
  disc[u] = low[u] = ++time;
  st->push(u);
  stackMember[u] = true;
  list<int>::iterator i;
  for (i = adj[u].begin(); i != adj[u].end(); ++i) {
    int v = *i;
    if (disc[v] == -1) {
      SCCUtil(v, disc, low, st, stackMember);
      low[u] = min(low[u], low[v]);
    } else if (stackMember[v] == true)
      low[u] = min(low[u], disc[v]);
  }
  int w = 0;
  if (low[u] == disc[u]) {
    while (st->top() != u) {
      w = (int)st->top();
      mas[w] = r + 1;
      stackMember[w] = false;
      st->pop();
    }
    w = (int)st->top();
    mas[w] = r + 1;
    r = r + 1;
    stackMember[w] = false;
    st->pop();
  }
}
void Graph::SCC() {
  int *disc = new int[V];
  int *low = new int[V];
  bool *stackMember = new bool[V];
  stack<int> *st = new stack<int>();
  for (int i = 0; i < V; i++) {
    disc[i] = -1;
    low[i] = -1;
    stackMember[i] = false;
  }
  for (int i = 0; i < V; i++)
    if (disc[i] == -1) SCCUtil(i, disc, low, st, stackMember);
}
int main() {
  cin >> n >> m;
  i = 0;
  Graph g1(2 * n);
  int zz = 0;
  while (i < m) {
    cin >> a >> b >> c;
    a = a - 1;
    b = b - 1;
    rr[zz][0] = a;
    rr[zz][1] = b;
    rr[zz][2] = c;
    zz = zz + 1;
    if (c == 1) {
      g1.addEdge(a, b);
      g1.addEdge(b, a);
      g1.addEdge(a + n, b + n);
      g1.addEdge(b + n, a + n);
    } else {
      g1.addEdge(a + n, b);
      g1.addEdge(b + n, a);
      g1.addEdge(a, b + n);
      g1.addEdge(b, a + n);
    }
    i = i + 1;
  }
  g1.SCC();
  i = 0;
  int aa = 0;
  while (i < n) {
    if (mas[i] == mas[i + n]) {
      aa = 1;
    }
    i = i + 1;
  }
  if (aa == 0) {
    gg = 0;
    int zzz = 0;
    i = 0;
    while (i < zz) {
      if (rr[i][2] == 0) {
        if ((atb[rr[i][0]] == 0) and (atb[rr[i][1]] == 0)) {
          if (mas[rr[i][0]] < mas[rr[i][1]]) {
            atb[rr[i][0]] = 1;
            atb[rr[i][1]] = -1;
          } else {
            atb[rr[i][1]] = 1;
            atb[rr[i][0]] = -1;
          }
        } else {
          if ((atb[rr[i][0]] == -1) and (atb[rr[i][1]] == 0)) {
            atb[rr[i][1]] = 1;
          }
          if ((atb[rr[i][1]] == -1) and (atb[rr[i][0]] == 0)) {
            atb[rr[i][0]] = 1;
          }
        }
      } else {
        if ((atb[rr[i][0]] == 1) or (atb[rr[i][1]] == 1)) {
          atb[rr[i][0]] = 1;
          atb[rr[i][1]] = 1;
        }
      }
      i = i + 1;
    }
    i = 0;
    while (i < zz) {
      if (rr[i][2] == 0) {
        if ((atb[rr[i][0]] == 0) and (atb[rr[i][1]] == 0)) {
          if (mas[rr[i][0]] < mas[rr[i][1]]) {
            atb[rr[i][0]] = 1;
          } else {
            atb[rr[i][1]] = 1;
          }
        } else {
          if ((atb[rr[i][0]] == -1) and (atb[rr[i][1]] == 0)) {
            atb[rr[i][1]] = 1;
          }
          if ((atb[rr[i][1]] == -1) and (atb[rr[i][0]] == 0)) {
            atb[rr[i][0]] = 1;
          }
        }
      } else {
        if ((atb[rr[i][0]] == 1) or (atb[rr[i][1]] == 1)) {
          atb[rr[i][0]] = 1;
          atb[rr[i][1]] = 1;
        }
      }
      i = i + 1;
    }
    i = 0;
    while (i < zz) {
      if (rr[i][2] == 0) {
        if ((atb[rr[i][0]] == 0) and (atb[rr[i][1]] == 0)) {
          if (mas[rr[i][0]] < mas[rr[i][1]]) {
            atb[rr[i][0]] = 1;
          } else {
            atb[rr[i][1]] = 1;
          }
        } else {
          if ((atb[rr[i][0]] == -1) and (atb[rr[i][1]] == 0)) {
            atb[rr[i][1]] = 1;
          }
          if ((atb[rr[i][1]] == -1) and (atb[rr[i][0]] == 0)) {
            atb[rr[i][0]] = 1;
          }
        }
      } else {
        if ((atb[rr[i][0]] == 1) or (atb[rr[i][1]] == 1)) {
          atb[rr[i][0]] = 1;
          atb[rr[i][1]] = 1;
        }
      }
      i = i + 1;
    }
    i = 0;
    while (i < n) {
      if (atb[i] == 1) {
        gg = gg + 1;
      }
      i = i + 1;
    }
    cout << gg << "\n";
    i = 0;
    while (i < n) {
      if (atb[i] > 0) {
        cout << i + 1 << " ";
      }
      i = i + 1;
    }
  } else {
    cout << "Impossible";
  }
  return (0);
}
