{"problem":{"name":"A. Search for Pretty Integers","description":{"content":"You are given two lists of non-zero digits. Let's call an integer pretty if its (base 10) representation has at least one digit from the first list and at least one digit from the second list. What i","description_type":"Markdown"},"platform":"Codeforces","limit":{"time_limit":1000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"CF870A"},"statements":[{"statement_type":"Markdown","content":"You are given two lists of non-zero digits.\n\nLet's call an integer pretty if its (base 10) representation has at least one digit from the first list and at least one digit from the second list. What is the smallest positive pretty integer?\n\n## Input\n\nThe first line contains two integers _n_ and _m_ (1 ≤ _n_, _m_ ≤ 9) — the lengths of the first and the second lists, respectively.\n\nThe second line contains _n_ distinct digits _a_1, _a_2, ..., _a__n_ (1 ≤ _a__i_ ≤ 9) — the elements of the first list.\n\nThe third line contains _m_ distinct digits _b_1, _b_2, ..., _b__m_ (1 ≤ _b__i_ ≤ 9) — the elements of the second list.\n\n## Output\n\nPrint the smallest pretty integer.\n\n[samples]\n\n## Note\n\nIn the first example 25, 46, 24567 are pretty, as well as many other integers. The smallest among them is 25. 42 and 24 are not pretty because they don't have digits from the second list.\n\nIn the second example all integers that have at least one digit different from 9 are pretty. It's obvious that the smallest among them is 1, because it's the smallest positive integer.","is_translate":false,"language":"English"},{"statement_type":"Markdown","content":"你被给定两个非零数字的列表。\n\n如果一个整数（以 #cf_span[10] 为基）的表示中至少包含第一个列表中的一个数字和第二个列表中的一个数字，则称其为“美观的”。求最小的正美观整数。\n\n第一行包含两个整数 #cf_span[n] 和 #cf_span[m]（#cf_span[1 ≤ n, m ≤ 9]）——分别表示第一个和第二个列表的长度。\n\n第二行包含 #cf_span[n] 个互不相同的数字 #cf_span[a1, a2, ..., an]（#cf_span[1 ≤ ai ≤ 9]）——第一个列表的元素。\n\n第三行包含 #cf_span[m] 个互不相同的数字 #cf_span[b1, b2, ..., bm]（#cf_span[1 ≤ bi ≤ 9]）——第二个列表的元素。\n\n请输出最小的美观整数。\n\n在第一个例子中，#cf_span[25]、#cf_span[46]、#cf_span[24567] 都是美观的，还有很多其他的整数也是。其中最小的是 #cf_span[25]。#cf_span[42] 和 #cf_span[24] 不是美观的，因为它们没有包含第二个列表中的数字。\n\n在第二个例子中，所有至少包含一个不同于 #cf_span[9] 的数字的整数都是美观的。显然，其中最小的是 #cf_span[1]，因为它是最小的正整数。\n\n## Input\n\n第一行包含两个整数 #cf_span[n] 和 #cf_span[m]（#cf_span[1 ≤ n, m ≤ 9]）——分别表示第一个和第二个列表的长度。第二行包含 #cf_span[n] 个互不相同的数字 #cf_span[a1, a2, ..., an]（#cf_span[1 ≤ ai ≤ 9]）——第一个列表的元素。第三行包含 #cf_span[m] 个互不相同的数字 #cf_span[b1, b2, ..., bm]（#cf_span[1 ≤ bi ≤ 9]）——第二个列表的元素。\n\n## Output\n\n请输出最小的美观整数。\n\n[samples]\n\n## Note\n\n在第一个例子中，#cf_span[25]、#cf_span[46]、#cf_span[24567] 都是美观的，还有很多其他的整数也是。其中最小的是 #cf_span[25]。#cf_span[42] 和 #cf_span[24] 不是美观的，因为它们没有包含第二个列表中的数字。在第二个例子中，所有至少包含一个不同于 #cf_span[9] 的数字的整数都是美观的。显然，其中最小的是 #cf_span[1]，因为它是最小的正整数。","is_translate":true,"language":"Chinese"},{"statement_type":"Markdown","content":"**Definitions**  \nLet $ A \\subseteq \\{1, 2, \\dots, 9\\} $ be the first set of distinct non-zero digits, with $ |A| = n $.  \nLet $ B \\subseteq \\{1, 2, \\dots, 9\\} $ be the second set of distinct non-zero digits, with $ |B| = m $.  \n\n**Constraints**  \n$ 1 \\leq n, m \\leq 9 $, and $ A \\cap B $ may be non-empty.  \n\n**Objective**  \nFind the smallest positive integer $ x $ such that the decimal representation of $ x $ contains at least one digit from $ A $ and at least one digit from $ B $.","is_translate":false,"language":"Formal"}],"meta":{"iden":"CF870A","tags":["brute force","implementation"],"sample_group":[["2 3\n4 2\n5 7 6","25"],["8 8\n1 2 3 4 5 6 7 8\n8 7 6 5 4 3 2 1","1"]],"created_at":"2026-03-03 11:00:39"}}