#abc157c. C - Guess The Number

C - Guess The Number

Score : 300300 points

问题描述

如果有满足以下条件的不小于 00 的整数,请输出其中最小的一个;否则,输出 -1

  • 此整数以十进制表示时恰好有 NN 位数字。(我们假设 00 是一个 11 位整数。对于其他整数,不允许前导零。)
  • 从左数第 sis_i 位的数字为 cic_i(i=1,2,,M)\left(i = 1, 2, \cdots, M\right)

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

If there is an integer not less than 00 satisfying the following conditions, print the smallest such integer; otherwise, print -1.

  • The integer has exactly NN digits in base ten. (We assume 00 to be a 11-digit integer. For other integers, leading zeros are not allowed.)
  • The sis_i-th digit from the left is cic_i. (i=1,2,,M)\left(i = 1, 2, \cdots, M\right)

Constraints

  • All values in input are integers.
  • 1N31 \leq N \leq 3
  • 0M50 \leq M \leq 5
  • 1siN1 \leq s_i \leq N
  • 0ci90 \leq c_i \leq 9

Input

Input is given from Standard Input in the following format:

NN MM

s1s_1 c1c_1

\vdots

sMs_M cMc_M

Output

Print the answer.

Sample Input 1

3 3
1 7
3 2
1 7

Sample Output 1

702

702702 satisfies the conditions - its 11-st and 33-rd digits are 7 and 2, respectively - while no non-negative integer less than 702702 satisfies them.

Sample Input 2

3 2
2 1
2 3

Sample Output 2

-1

Sample Input 3

3 1
1 0

Sample Output 3

-1

update @ 2024/3/10 17:14:21