Problem: After Santa Claus and his assistant Elf delivered all the presents and made all the wishes come true, they returned to the North Pole and found out that it is all covered with snow. Both of them were quite tired and they decided only to remove the snow from the roads connecting huts. The North Pole has n huts connected with m roads. One can go along the roads in both directions. 

The Elf offered to split: Santa Claus will clear up the wide roads and the Elf will tread out the narrow roads. For each road they decided who will clear it: Santa Claus or the Elf. To minimize the efforts they decided to clear the road so as to fulfill both those conditions: 

  * between any two huts should exist exactly one simple path along the cleared roads; 
  * Santa Claus and the Elf should clear the same number of roads. 



At this point Santa Claus and his assistant Elf wondered which roads should they clear up?

Input

The first input line contains two positive integers n and m (1 ≤ n ≤ 103, 1 ≤ m ≤ 105) — the number of huts and the number of roads. Then follow m lines, each of them contains a road description: the numbers of huts it connects — x and y (1 ≤ x, y ≤ n) and the person responsible for clearing out this road ("S" — for the Elf or "M" for Santa Claus). It is possible to go on each road in both directions. Note that there can be more than one road between two huts and a road can begin and end in the same hut.

Output

Print "-1" without the quotes if it is impossible to choose the roads that will be cleared by the given rule. Otherwise print in the first line how many roads should be cleared and in the second line print the numbers of those roads (the roads are numbered from 1 in the order of occurrence in the input). It is allowed to print the numbers of the roads in any order. Each number should be printed exactly once. As you print the numbers, separate them with spaces.

Examples

Input

1 2
1 1 S
1 1 M


Output

0



Input

3 3
1 2 S
1 3 M
2 3 S


Output

2
2 1 


Input

5 6
1 1 S
1 2 M
1 3 S
1 4 M
1 5 M
2 2 S


Output

-1

Note

A path is called simple if all huts on it are pairwise different.

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1030, MAX2 = 1e5 + 20;
struct in {
  int a, b, be, idx;
  in(int x = 0, int y = 0, int z = 0, int h = 0) : a(x), b(y), be(z), idx(h) {}
  void rr() {
    char c;
    scanf("%d %d %c\n", &a, &b, &c);
    if (c == 'S')
      be = 0;
    else
      be = 1;
  }
};
in ins[MAX2];
int n, m;
set<int> eds[2];
struct edge {
  int to;
  int idx;
  edge(int a = 0, int b = 0) : to(a), idx(b) {}
  bool operator<(const edge &b) const {
    if (to != b.to)
      return to < b.to;
    else
      return idx < b.idx;
  }
};
vector<edge> adj[MAX];
set<int> al0;
int vist[MAX];
int C[MAX], ccn;
void dfs1(int v) {
  vist[v] = 1;
  C[v] = ccn;
  for (int i = 0; i < adj[v].size(); i++) {
    int u = adj[v][i].to;
    if (!vist[u]) {
      al0.insert(adj[v][i].idx);
      dfs1(u);
    }
  }
}
vector<edge> adj2[MAX];
set<int> al1;
void dfs2(int v) {
  vist[v] = 1;
  for (int i = 0; i < adj2[v].size(); i++) {
    int u = adj2[v][i].to;
    if (!vist[u]) {
      al1.insert(adj2[v][i].idx);
      dfs2(u);
    }
  }
}
edge pa[MAX];
set<edge> adj3[MAX];
void dfs3(int v) {
  vist[v] = 1;
  for (auto &e : adj3[v]) {
    int u = e.to;
    if (!vist[u]) {
      pa[u] = edge(v, e.idx);
      dfs3(u);
    }
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = (1); i <= (m); ++i) {
    ins[i].rr();
    ins[i].idx = i;
  }
  for (int i = (1); i <= (m); ++i) {
    if (ins[i].a != ins[i].b) eds[ins[i].be].insert(ins[i].idx);
  }
  if (n % 2 == 0)
    printf("%d\n", -1);
  else {
    for (int idx : eds[0]) {
      int a = ins[idx].a, b = ins[idx].b;
      adj[a].push_back(edge(b, idx)), adj[b].push_back(edge(a, idx));
    }
    memset(vist, 0, sizeof(vist));
    ccn = 1;
    for (int v = (1); v <= (n); ++v) {
      if (!vist[v]) {
        dfs1(v);
        ccn++;
      }
    }
    ccn--;
    if (ccn - 1 > (n - 1) / 2)
      printf("%d\n", -1);
    else {
      for (int idx : eds[1]) {
        int a = ins[idx].a, b = ins[idx].b;
        a = C[a], b = C[b];
        adj2[a].push_back({b, idx}), adj2[b].push_back({a, idx});
      }
      memset(vist, 0, sizeof(vist));
      for (int v = (1); v <= (ccn); ++v) {
        if (!vist[v]) {
          dfs2(v);
        }
      }
      bool ok = 1;
      for (int v = (1); v <= (ccn); ++v)
        if (!vist[v]) {
          ok = 0;
          break;
        }
      if (!ok)
        printf("%d\n", -1);
      else {
        if (al0.size() == al1.size()) {
          printf("%d ", n - 1);
          for (int idx : al0) printf("%d ", idx);
          for (int idx : al1) printf("%d ", idx);
          printf("\n");
        } else {
          assert(al0.size() > al1.size());
          for (int idx : al1) {
            eds[1].erase(idx);
          }
          for (int idx : al0) {
            int a = ins[idx].a, b = ins[idx].b;
            adj3[a].insert(edge(b, idx));
            adj3[b].insert(edge(a, idx));
          }
          for (int idx : al1) {
            int a = ins[idx].a, b = ins[idx].b;
            adj3[a].insert(edge(b, idx));
            adj3[b].insert(edge(a, idx));
          }
          for (int idx : eds[1]) {
            if (al0.size() == al1.size()) break;
            int a = ins[idx].a, b = ins[idx].b;
            for (int v = (1); v <= (n); ++v) vist[v] = 0;
            dfs3(a);
            int tmp = b;
            int prev, next, eidx;
            bool find = 0;
            while (tmp != a) {
              if (ins[pa[tmp].idx].be == 0) {
                find = 1;
                prev = pa[tmp].to, next = tmp, eidx = pa[tmp].idx;
                break;
              }
              tmp = pa[tmp].to;
            }
            if (find) {
              adj3[prev].erase(edge(next, eidx));
              adj3[next].erase(edge(prev, eidx));
              al0.erase(eidx);
              adj3[a].insert(edge(b, idx));
              adj3[b].insert(edge(a, idx));
              al1.insert(idx);
            }
          }
          if (al0.size() != al1.size())
            printf("%d\n", -1);
          else {
            printf("%d\n", (n - 1));
            for (int idx : al0) printf("%d ", idx);
            for (int idx : al1) printf("%d ", idx);
            printf("\n");
          }
        }
      }
    }
  }
  return 0;
}