King's Palace

아직 제출이 없습니다시간 제한6초메모리 제한1024 MB

문제

There are NN walls in the hall of the King's palace, numbered by integers from 11 to NN. The King asks the Royal Painter to paint each wall in one of three colors (red, green, or blue). Additionally, the King gives MM orders.

Every order has the following form: given two walls, a_ia\_i and b_ib\_i, and two colors, x_ix\_i and y_iy\_i, the order dictates that, if the wall a_ia\_i is painted with color x_ix\_i and the wall b_ib\_i is painted with color y_iy\_i, the Royal Painter has to be executed.

Your task is to find a number of ways to paint the walls so that the Royal Painter will not be executed.

입력

The first line of the input contains two integers NN and MM (1N221 \le N \le 22, 1M9N(N1)/21 \le M \le 9 \cdot N \cdot (N-1)/2): the number of walls and the number of orders, respectively.

Each of the following MM lines describes one King's order and contains an integer a_ia\_i, a letter x_ix\_i, an integer b_ib\_i, and a letter y_iy\_i, separated by single spaces (1a_i<b_iN1 \le a\_i < b\_i \le N, x_ix\_i and y_iy\_i are letters from 'R', 'G', and 'B', denoting the red, green, and blue colors, respectively). You may assume that all MM orders are pairwise distinct (no two orders have the exact same effect).

출력

Print one integer: the number of ways to paint the walls so that the Royal Painter will not be executed.