QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 256 MB Total points: 100

#13069. Number Game With One Lie

统计

Define number game (between Alice and Bob) as follows: they agree on a positive number $n$, then Alice will pick a number $x$ from $1$ to $n$. Each time, Bob will select some intervals and ask Alice whether $x$ is in any of the intervals. To be clear, it's a yes/no question. One special rule about this game is that, Alice can lie once (more precisely at most once).

We're in the middle of the Game. Given $n$, all questions already been asked by Bob and the answers by Alice respectively. Please compute the minimum number of additional questions that Bob needs to ask to uniquely determine the value of $x$.

Input

There are at most $10000$ test cases. Each case consists of $n$ and $m$ (the number of questions always been asked by Bob), separated by a space. For the following $m$ lines, the first number is $c$, then the line is followed by $c$ pairs $[s_i, t_i]$ ($1 \leq s_i \leq t_i \leq n$, $1 \leq i \leq c$) denoting the $i$-th interval in this question, then a string "yes" or "no" denoting the answer. You may assume that Alice is strictly obeying the rule and it's always possible to find the answer $x$ if Bob continues to play the game.

$1 \leq n \leq 10^{16}$, $0 \leq m \leq 10$, and $1 \leq c \leq 100$

Output

For each test case, print a single line containing one integer — the minimum number of additional questions required.

Example

Input

1 0
2 0
2 2
1 1 1 yes
1 1 1 no
2 2
1 1 1 yes
1 1 1 yes
2 3
1 1 1 yes
1 1 1 no
1 1 1 yes

Output

0
3
1
0
0

Discussions

About Discussions

The discussion section is only for posting: Editorials, General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues. Submitting multiple issues may cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.