QOJ.ac

QOJ

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

#13069. Number Game With One Lie

Statistics

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
About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.