QOJ.ac

QOJ

时间限制: 1.0 s 内存限制: 1024 MB 总分: 100

#10691. 危险数字

统计

有一天,oToToT 收到了一项秘密黑客任务,指示他入侵 NTU 的学校系统。经过简单的调查,他发现 NTU 的系统存在许多漏洞。作为一名经验丰富的黑客,他轻松绕过了这些漏洞,并到达了最后阶段:密码验证。

尽管付出了努力,oToToT 还是没能找到密码。由于他可以看到网上所有可访问的内容,他怀疑安全人员可能把密码写在了纸上。

幸运的是,oToToT 发现了密码验证器的一些奇特之处。首先,该机器只接受数字作为密码。对于任何输入的数字,验证器都会将其与 $M$ 个被称为“危险”数字的数进行比对。如果输入数字的任何子串与任何一个危险数字匹配,机器就会报错。否则,输入通过。例如,如果 $12$ 是一个危险数字,那么像 $123$ 和 $3212$ 这样的输入会触发错误,而 $2142$ 和 $456$ 则不会。

当然,事情没那么简单。除了要避开危险数字外,oToToT 还发现密码必须不小于最小值 $N$。也就是说,如果输入的数字小于 $N$,机器也会报错。

此时,oToToT 被周老师叫去参加培训。你能帮 oToToT 找到能通过密码验证器且不触发错误的最小数字吗?

输入格式

第一行包含一个大整数 $N$,表示密码的最小值($1 \le |N| \le 3 \cdot 10^5$;此后 $|X|$ 表示 $X$ 的位数)。

第二行包含一个整数 $M$,表示危险数字的数量($1 \le M \le 3 \cdot 10^5$)。

接下来的 $M$ 行,每行包含一个大整数 $d_i$,表示第 $i$ 个危险数字($\sum_{i=1}^M |d_i| \le 3 \cdot 10^5$)。

零表示为“0”,其他数字均不以零开头。

输出格式

输出一行,包含一个大整数:能通过密码验证器且不触发错误的最小数字。如果无法构造出这样的数字,则输出 -1。零应表示为“0”,其他数字均不以零开头。

样例

输入 1

339
4
9
34
51
0

输出 1

352

Discussions

About Discussions

The discussion section is only for posting: 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.
  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.