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>
const int N = 2010;
const int M = 200010;
struct Edge {
  int u, v, idx;
  char tp;
} edge[M];
struct ROAD {
  int v, idx;
  void push(int _v, int _idx) {
    v = _v;
    idx = _idx;
  }
};
std::vector<ROAD> road[N];
struct PREVEVE {
  int u, idx;
  void push(int _u, int _idx) {
    u = _u;
    idx = _idx;
  }
} prev[N];
int que[N], fr, bk;
bool vst[N];
int p[N], ok[M], size[N];
int find(int a) { return a == p[a] ? a : p[a] = find(p[a]); }
void uni(int a, int b) { p[find(a)] = find(b); }
int main() {
  int n, m, x, y;
  char s[20];
  while (~scanf("%d %d", &n, &m)) {
    for (int i = 0; i < m; i++) {
      scanf("%d %d %s", &edge[i].u, &edge[i].v, s);
      edge[i].tp = s[0];
      edge[i].u--;
      edge[i].v--;
      edge[i].idx = i;
    }
    if (n == 1) {
      puts("0");
    } else {
      if (n % 2 == 0)
        puts("-1");
      else {
        ROAD tmp;
        x = y = 0;
        for (int i = 0; i < n; i++) p[i] = i, road[i].clear();
        ;
        for (int i = 0; i < m; i++) {
          if (find(edge[i].u) != find(edge[i].v)) {
            uni(edge[i].u, edge[i].v);
            tmp.push(edge[i].v, i);
            road[edge[i].u].push_back(tmp);
            tmp.push(edge[i].u, i);
            road[edge[i].v].push_back(tmp);
            ok[i] = true;
            if (edge[i].tp == 'S')
              x++;
            else
              y++;
          } else
            ok[i] = false;
        }
        if (x + y != n - 1) {
          puts("-1");
        } else {
          if (x < y) {
            std::swap(x, y);
            for (int i = 0; i < m; i++) {
              if (edge[i].tp == 'S')
                edge[i].tp = 'M';
              else
                edge[i].tp = 'S';
            }
          }
          int done = 0;
          if (x != y) {
            for (int i = 0; i < n; i++) size[i] = road[i].size();
            for (int i = 0, u, v; i < m; i++) {
              if (!ok[i] && edge[i].tp == 'M') {
                memset(vst, false, sizeof(vst));
                fr = bk = 0;
                que[bk++] = edge[i].u;
                vst[edge[i].u] = 1;
                while (fr < bk) {
                  u = que[fr++];
                  for (int l = 0; l < size[u]; l++) {
                    v = road[u][l].v;
                    if (!vst[v]) {
                      que[bk++] = v;
                      vst[v] = 1;
                      prev[v].push(u, road[u][l].idx);
                    }
                  }
                }
                v = edge[i].v;
                while (v != edge[i].u) {
                  if (edge[prev[v].idx].tp == 'S') {
                    done++;
                    ok[i] = true;
                    ok[prev[v].idx] = false;
                    int idx = prev[v].idx;
                    u = edge[idx].u;
                    v = edge[idx].v;
                    for (int j = 0; j < size[u]; j++) {
                      if (road[u][j].v == v) {
                        for (int k = j + 1; k < size[u]; k++)
                          road[u][k - 1] = road[u][k];
                        road[u].pop_back();
                        size[u]--;
                        break;
                      }
                    }
                    u = edge[idx].v;
                    v = edge[idx].u;
                    for (int j = 0; j < size[u]; j++) {
                      if (road[u][j].v == v) {
                        for (int k = j + 1; k < size[u]; k++)
                          road[u][k - 1] = road[u][k];
                        road[u].pop_back();
                        size[u]--;
                        break;
                      }
                    }
                    u = edge[i].u;
                    v = edge[i].v;
                    tmp.push(v, i);
                    road[u].push_back(tmp);
                    size[u]++;
                    tmp.push(u, i);
                    road[v].push_back(tmp);
                    size[v]++;
                    break;
                  }
                  v = prev[v].u;
                }
                if (2 * done == x - y) break;
              }
            }
          }
          if (2 * done == x - y) {
            printf("%d\n", n - 1);
            bool flg = false;
            for (int i = 0; i < m; i++) {
              if (ok[i]) {
                if (flg) putchar(' ');
                printf("%d", i + 1);
                flg = true;
              }
            }
            puts("");
          } else
            puts("-1");
        }
      }
    }
  }
  return 0;
}