Harryxun/stf_run huggingface dataset:
n = int(input())
A = list(map(int, input().split()))
q = int(input())
mi = map(int, input().split())

def solve(i, m):
    if (m == 0):
        return True
    if (i >= n):
        return False
    res = solve(i + 1, m) or solve(i + 1, m - A[i])
    return res

for i in range(q):
    if solve(0, mi):
        print("yes")
    else:
        print("no")

### FIXED CODE ###

n = int(input())
A = list(map(int, input().split()))
q = int(input())
mi = map(int, input().split())
t = {}

def solve(i, m):
    if (m == 0):
        return True
    if (i >= n):
        return False
    if (i,m) in t:
        return t[(i,m)]
    res = solve(i + 1, m) or solve(i + 1, m - A[i])
    t[(i,m)] = res
    return res

for m in mi:
    if solve(0, m):
        print("yes")
    else:
        print("no")
import math

x = input()
y = input()


cnt = 0

while x <= y:
    x *= 2
    cnt += 1

print (cnt)

### FIXED CODE ###

x,y=map(int,input().split())

cnt = 0

while x <= y:
    x *= 2
    cnt += 1

print (cnt)
def insertionSort(A,n,g):
    cnt = 0
    for i in range(g,n):
            v = A[i]
            j = i - g
            while j >= 0 and A[j] > v:
                    A[j+g] = A[j]
                    j = j - g
                    cnt += 1
                    A[j+g] = v
    return cnt
def shellsort(A,n):
    cnt = 0
    h = 1
    G = []
    while h <= 1:
        G.append(h)
        h = 3*h + 1
    G.reverse()
    m = len(G)
    print(m

    print(" ".join(map(str,G)))
    for i in range(m:
        cnt += insertionSort(A,n,G[i])
    print(cnt)
    for i in A:
        print(i)
n = int(input())
A = []
for _ in range(n):
    A.append(int(input()))
shellsort(A,n)




### FIXED CODE ###

def insertionSort(A,n,g):
    cnt = 0
    for i in range(g,n):
        v = A[i]
        j = i - g
        while j >= 0 and A[j] > v:
            A[j+g] = A[j]
            j = j - g
            cnt += 1
            A[j+g] = v
    return cnt
    
def shellsort(A,n):
    cnt = 0
    h = 1
    G = []
    while h <= n:
        G.append(h)
        h = 3*h + 1
    G.reverse()
    m = len(G)
    print(m)

    print(" ".join(map(str,G)))
    for i in range(m):
        cnt += insertionSort(A,n,G[i])
    print(cnt)
    for i in A:
        print(i)
        
n = int(input())
A = []
for _ in range(n):
    A.append(int(input()))
shellsort(A,n)
a = [list(map(int, input().split())) for _ in range(3)]
N = int(input())
b = [int(input()) for _ in range(10)]

c = [[0 for _ in range(3)] for _ in range(3)]
result = ""

for i in range(3):
    for j in range(3):
        if a[j][i] in b:
            c[j][i] = 1

for i in range(3):
    if c[i][0] == c[i][1] == c[i][2] == 1:
        result = "Yes"
        break
    elif c[0][i] == c[1][i] == c[2][i] == 1:
        result = "Yes"
        break

if c[0][0] == c[1][1] == c[2][2] == 1:
    result = "Yes"
elif c[0][2] == c[1][1] == c[2][0] == 1:
    result = "Yes"

if result is None:
    result ="No"

print(result)

### FIXED CODE ###

a = [list(map(int, input().split())) for _ in range(3)]
N = int(input())
b = [int(input()) for _ in range(N)]

c = [[0 for _ in range(3)] for _ in range(3)]
result = ""

for i in range(3):
    for j in range(3):
        if a[j][i] in b:
            c[j][i] = 1

for i in range(3):
    if c[i][0] == c[i][1] == c[i][2] == 1:
        result = "Yes"
        break
    elif c[0][i] == c[1][i] == c[2][i] == 1:
        result = "Yes"
        break

if c[0][0] == c[1][1] == c[2][2] == 1:
    result = "Yes"
elif c[0][2] == c[1][1] == c[2][0] == 1:
    result = "Yes"

if result == "":
    result ="No"

print(result)
s=input()
t=input()
ss=s+s
n=len(s)
for i in range(n):
  if ss[i:]=t:
    print("Yes")
    exit(0)

print("No")


### FIXED CODE ###

S=input()
T=input()
for i in range(len(S)):
  if S[i:]+S[:i]==T:
    print("Yes")
    exit(0)
    
print("No")
import sys

def longestcommonsubsequence():
    seq1 = raw_input()
    seq2 = raw_input()

    a,b = len(seq1), len(seq2)
    x1 = [0 for i in range(b+1)]
    for i in range(a+1):
        e1 = seq[i]
        x2 = x1
        x1 = [0 for i2 in range(b+1)]
        tmp = 0
        for j in range(b):
            if e1 == seq2[j]:
                tmp = x2[j] + 1
            else:
                tmp = max(x2[j+1], tmp)
            x1[j+1] = tmp
    return x1[-1]

n = input()
for i2 in range(n):

    print longestcommonsubsequence()

### FIXED CODE ###

import sys

def longestcommonsubsequence():
    seq1 = raw_input()
    seq2 = raw_input()

    a, b = len(seq1), len(seq2)
    x1 = [0 for i in range(b+1)]
    for i in range(a):
        e1 = seq1[i]
        x2 = x1+[]
        #x1 = [0 for i2 in range(b+1)]
        for j in range(b):
            if e1 == seq2[j]:
                x1[j+1] = x2[j] + 1
            elif x1[j+1]<x1[j]:
                x1[j+1] = x1[j]
    return x1[-1]

n = input()
for i2 in range(n):

    print longestcommonsubsequence()
A, B, K = [int(s) for s in input().split()]
if K <= A:
  print(str(A-K)+' '+str(B))
else
  print(str(0)+' '+str(A+B-K))

### FIXED CODE ###

A, B, K = [int(s) for s in input().split()]
X = A+B
if K <= A:
  print(str(A-K)+' '+str(B))
elif K <= X:
  print(str(0)+' '+str(X-K))
else:
  print(str(0)+' '+str(0))
"""Coloring Edges on Tree
https://atcoder.jp/contests/abc146/tasks/abc146_d
"""
import sys
input = sys.stdin.readline


class Node:
    def __init__(self, num):
        self.num = num
        self.edge = []
        self.edge_color = []


def dfs(node, p):
    # print(node.num, p)
    for e in node.edge:
        used_color = node.edge_color
        if e != p:
            # 子のノードを取得
            child = tree[e]
            child_used_color = child.edge_color

            # このnodeと子のノードでまだ使っていない色を特定
            unused_colors = list(set(colors) - set(used_color + child_used_color))
            if len(unused_colors) == 0:
                color_num = max(colors) + 1
                colors.append(color_num)
            else:
                color_num = unused_colors[0]

            # このノードと、子のノードに使用ずみの色をマーク
            node.edge_color.append(color_num)
            child.edge_color.append(color_num)

            # 答えを記録
            ans['{a} {b}'.format(a=node.num, b=child.num)] = color_num
            ans['{a} {b}'.format(a=child.num, b=node.num)] = color_num

            # 掘る
            dfs(child, node.num)


N = int(input())
ans = {}
colors = [1]

# treeの初期化
tree = []
edges = []
tree.append(Node(0))
for i in range(1, N + 1):
    tree.append(Node(i))
for i in range(N - 1):
    inp = input().split()
    edges.append(inp)
    a, b = map(int, inp)
    tree[a].edge.append(b)
    tree[b].edge.append(a)

dfs(tree[1], -1)


print(len(colors))
for e in edges:
    # print(e)
    print(str(ans.get(' '.join(e))))


### FIXED CODE ###

"""Coloring Edges on Tree
https://atcoder.jp/contests/abc146/tasks/abc146_d
"""
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 5 + 1)

class Node:
    def __init__(self, num):
        self.num = num
        self.edge = set()
        self.edge_color = set()


def dfs(node, c = -1 , p = -1):
    k = 1    
    for e in node.edge:
        if e == p:
            continue
        if k == c:
            k += 1
        # 子のノードを取得
        child = tree[e]

        # 答えを記録
        if a < b:
            ans['{0} {1}'.format(node.num, child.num)] = k
        else:
            ans['{0} {1}'.format(child.num, node.num)] = k
        k += 1

        # 掘る
        dfs(child,k - 1, node.num)


N = int(input())
ans = {}
# colors = {1}

# treeの初期化
tree = [Node(i) for i in range(0, N + 1)]
edges = []
for i in range(N - 1):
    a, b = map(int, input().split())
    tree[a].edge.add(b)
    tree[b].edge.add(a)
    if a < b:
        edges.append('{0} {1}'.format(a, b))
    else:
        edges.append('{0} {1}'.format(b, a))

dfs(tree[1], -1)

# print("edges:{}".format(edges))
# print(max(c))
# print(ans)
count = 0
for node in tree:
    count = max(count, len(node.edge))
print(count)
for edge in edges:
    # print(edge)
    print(str(ans.get(edge)))
s = input()
t = input()

def z_algorithm(s):
    a = [0] * len(s)
    i = 1
    j = 0
    a[0] = len(s)
    while i < len(s):
        while i + j < len(s) and s[j] == s[i+j]:
            j += 1
        a[i] = j
        if j == 0:
            i += 1
            continue
        k = 1
        while i + k < len(s) and k + a[k] < j:
            a[i+k] = a[k]
            k += 1
        i += k
        j -= k
    return a

def solve(i, li):
    ans = 0
    while True:
        if visited[i]:
            break
        if i < 0 or len(li) <= i:
            break
        if li[i] < len(t):
            visited[i] = True
            break
        if li[i] >= len(t):
            visited[i] = True
            ans += 1
            i += len(t)
    return ans

#sを伸ばす
new_s = ""
while True:
    new_s += s
    if len(new_s) > len(t):
        s = new_s
        break

s = s*3
li = z_algorithm(t + s)[len(t):]
visited = [False] * len(li)
ans1 = 0
for i in range(len(li)):
    ans1 = max(ans1, solve(i, li))
'''
s += s
li = z_algorithm(t + s)[len(t):]
visited = [False] * len(li)
ans2 = 0
for i in range(len(li)):
    ans2 = max(ans2, solve(i, li))

if ans1 == ans2:
    print(ans1)
else:
    print(-1)
'''
print(ans1)

### FIXED CODE ###

s = input()
t = input()

def z_algorithm(s):
    a = [0] * len(s)
    i = 1
    j = 0
    a[0] = len(s)
    while i < len(s):
        while i + j < len(s) and s[j] == s[i+j]:
            j += 1
        a[i] = j
        if j == 0:
            i += 1
            continue
        k = 1
        while i + k < len(s) and k + a[k] < j:
            a[i+k] = a[k]
            k += 1
        i += k
        j -= k
    return a

def solve(i, li):
    ans = 0
    while True:
        if i < 0 or len(li) <= i or visited[i]:
            break
        if li[i] < len(t):
            visited[i] = True
            break
        if li[i] >= len(t):
            visited[i] = True
            ans += 1
            i += len(t)
    return ans

#sを伸ばす
new_s = s
while True:
    if len(new_s) > len(t):
        s = new_s
        break
    new_s += new_s

s = s*3
li = z_algorithm(t + s)[len(t):]
visited = [False] * len(li)
ans1 = 0
for i in range(len(li)):
    ans1 = max(ans1, solve(i, li))

s += s
li = z_algorithm(t + s)[len(t):]
visited = [False] * len(li)
ans2 = 0
for i in range(len(li)):
    ans2 = max(ans2, solve(i, li))

if ans1 == ans2:
    print(ans1)
else:
    print(-1)
a=input()
b=input()
print(b*2-a)

### FIXED CODE ###

a=int(input())
b=int(input())
print(b*2-a)
n = int(input())

ans = 0

print((n-1)+len(range(n**(1/2))))

### FIXED CODE ###

n = int(input())
ans = 0
for a in range(1, n):
  ans += (n - 1) // a
print(ans)
# -*- coding: utf-8 -*-

import sys
import os
import math

N, M = map(int, input().split())
#print('N', N)
#print('M', M)

A = [[] for i in range(N)]
for i in range(M):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    A[a].append((b, -c))

# 始点から到達不可能な頂点は除去する
visited = [False] * N
Q = [0]
while Q:
    i = Q.pop(0)
    visited[i] = True
    for edge in A[i]:
        to = edge[0]
        if not visited[to]:
            Q.append(to)
# 到達不可能な頂点
unreachable = []
reachable = []
for i in range(N):
    if visited[i]:
        reachable.append(i)
    else:
        unreachable.append(i)
#print('unreach', unreachable)
for i in unreachable:
    A[i] = []

dists = [float('inf')] * N
dists[0] = 0
def bellman_ford(A):
    for i in reachable:
        for v in reachable:
            for edge in A[v]:
                to = edge[0]
                cost = edge[1]
                if dists[v] != float('inf') and dists[to] > dists[v] + cost:
                    dists[to] = dists[v] + cost
                    if i == N - 1:
                        return True
    return False

is_loop = bellman_ford(A)

if is_loop:
    print('inf')
else:
    # パスがある
    print(-dists[N-1])

### FIXED CODE ###

# -*- coding: utf-8 -*-

import sys
import os
import math

A, B, C = map(int, input().split())

if A <= C <= B:
    print('Yes')
else:
    print('No')
n = int(input())


def make_divisors(n):
    lower_divisors, upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]


# 約数から1引いたものが候補
arr = make_divisors(n)
arr = [x - 1 for x in arr]

#　商と剰余が不一致ならbreakできる
ans = 0
for x in arr[::-1]:
    if n // x != n % x:
        break
    ans += x

print(ans)

### FIXED CODE ###

n = int(input())


def make_divisors(n):
    lower_divisors, upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]


def is_favorite(n, m):
    if x == 0:
        return False
    else:
        return n // m == n % m


li = make_divisors(n)
li = [x - 1 for x in li]


ans = 0
for x in li:
    if is_favorite(n, x):
        ans += x

print(ans)
n = int(input())
edge = [[] for _ in range(n)]
for _ in range(n-1):
    a,b = map(int,input().split())
    edge[a-1].append(b-1)
    edge[b-1].append(a-1)

def dfs(v,d,dist):
    dist[v] = d
    for ve in edge[v]:
        if dist[ve] is None:
            dist = dfs(ve, d+1, dist)
    return dist
    
    
f_dist = dfs(0,0,[None]*n)
s_dist = dfs(n-1,0,[None]*n)

fget = sum(1 for f,s in zip(f_dist,s_dist) if f<=s)
print("Fennec" if fget*2>n else "Snuke")

### FIXED CODE ###

import sys
sys.setrecursionlimit(1000000)

n = int(input())
edge = [[] for _ in range(n)]
for _ in range(n-1):
    a,b = map(int,input().split())
    edge[a-1].append(b-1)
    edge[b-1].append(a-1)

def dfs(v,d,dist):
    dist[v] = d
    for ve in edge[v]:
        if dist[ve] is None:
            dist = dfs(ve, d+1, dist)
    return dist
    
    
f_dist = dfs(0,0,[None]*n)
s_dist = dfs(n-1,0,[None]*n)

fget = sum(1 for f,s in zip(f_dist,s_dist) if f<=s)
print("Fennec" if fget*2>n else "Snuke")
S = str(input())
Q = int(input())
Qy = list([input().split() for _ in range(Q)])
ans = [S]
for i in Qy:
    if i[0] == '1':
        ans.reverse()
    elif i[0] == '2':
        if i[1] == '1':
            ans.insert(0,i[2])
        else:
            ans.append(i[2])
    print(ans)
print(''.join(ans))

### FIXED CODE ###

from collections import deque
S = str(input())
Q = int(input())
Qy = list([input().split() for _ in range(Q)])
rev = False #反転チェック
ans = deque([S])
for t in Qy:
    if t[0] == '1':
        rev = not rev
    else:
        if (t[1]=='1' and rev == False) or (t[1]=='2' and rev == True):
            ans.appendleft(t[2])
        else:
            ans.append(t[2])
if rev == False:
    print(''.join(ans))
else:
    print(''.join(ans)[::-1])
S = input()
if S == "zyxwvutsrqponmlkjihgfedcba":
  print(-1)
  exit()
if len(S) != 26:
  L = [0]*26
  for i in range(len(S)):
    L[ord(S[i])-97] = 1
  for i in range(26):
    if L[i] == 0:
      print(S + chr(97+i))
      exit()
else:
  B = []
  for i in reversed(range(26)):
    if ord(S[i]) - ord(S[i-1]) > 1:
      U = i
      M = i-1
      B += [ord(S[i])]
      break
    else:
      B += [ord(S[i])]
  B.sort()
  print(S[:M] + chr(B[0]))

### FIXED CODE ###

S = input()
if S == "zyxwvutsrqponmlkjihgfedcba":
  print(-1)
  exit()
if len(S) != 26:
  L = [0]*26
  for i in range(len(S)):
    L[ord(S[i])-97] = 1
  for i in range(26):
    if L[i] == 0:
      print(S + chr(97+i))
      exit()
else:
  B = []
  for i in reversed(range(26)):
    if ord(S[i]) > ord(S[i-1]):
      U = i
      M = i-1
      B += [ord(S[i])]
      break
    else:
      B += [ord(S[i])]
  B.sort()
  for i in B:
    if chr(i) > S[M]:
      print(S[:M] + chr(i))
      exit()
n,T=[int(i) for i in input().split()]
mn=10000
print(n)
print(t)
for i in range(n):
    c,t=[int(i) for i in input().split()]
    if t<=T:
        mn=min(mn,c)
print("TLE" if mn==10000 else mn)

### FIXED CODE ###

N,T=map(int,input().split())

c_min=1001
for i in range(N):
  c,t=map(int,input().split())
  if t<=T and c<c_min:
    c_min=c
if c_min==1001:
  print('TLE')
else:print(c_min)
import math
from itertools import combinations
n = int(input())
p = [list(map(int, input().split())) for i in range(n)]
def enclose(points):

    a = points[0]
    b = points[1]
    c = points[2]
    d = points[3]
    e = points[4]
    f = points[5]

    aa = a * a
    bb = b * b
    cc = c * c
    dd = d * d
    ee = e * e
    ff = f * f

    py = ((e - a) * (aa + bb - cc - dd) - (c - a) * (aa + bb - ee- ff)) / (2 * (e - a)*(b - d) - 2 * (c - a) * (b - f))

    px = (2 * (b - f) * py - aa - bb + ee + ff) / (2 * (e - a)) \
        if (c == a) else (2 * (b - d) * py - aa - bb + cc + dd) / (2 * (c - a))

    r = math.hypot(px - a, py - b)

    return (px, py, r)


ans = 1000000

if n >= 3:
    for i, j, k in combinations(range(n), 3):
        points = []
        points.extend(p[i])
        points.extend(p[j])
        points.extend(p[k])
        try:
            px, py, r = enclose(points)
        except:
            continue
        flag = 1
        for l in range(n):
            if (px-p[l][0])**2 + (py-p[l][1])**2 > r**2-0.00001:
                flag = 0
                break
        if flag == 1:
            ans = min(ans, r)

for i, j in combinations(range(n), 2):
    px = (p[i][0]+p[j][0]) / 2
    py = (p[i][1]+p[j][1]) / 2
    rr = (p[i][0] - px)**2 + (p[i][1] - py) ** 2
    flag = 1
    for l in range(n):
        if (px-p[l][0])**2 + (py-p[l][1])**2 > r-0.00001:
            flag = 0
            break
    if flag == 1:
        ans = min(ans, r)

print(ans)


### FIXED CODE ###

import math
from itertools import combinations
n = int(input())
p = [list(map(int, input().split())) for i in range(n)]
def enclose(points):

    a = points[0]
    b = points[1]
    c = points[2]
    d = points[3]
    e = points[4]
    f = points[5]

    aa = a * a
    bb = b * b
    cc = c * c
    dd = d * d
    ee = e * e
    ff = f * f

    py = ((e - a) * (aa + bb - cc - dd) - (c - a) * (aa + bb - ee- ff)) / (2 * (e - a)*(b - d) - 2 * (c - a) * (b - f))

    px = (2 * (b - f) * py - aa - bb + ee + ff) / (2 * (e - a)) \
        if (c == a) else (2 * (b - d) * py - aa - bb + cc + dd) / (2 * (c - a))

    r = math.hypot(px - a, py - b)

    return (px, py, r)


ans = 1000000

if n >= 3:
    for i, j, k in combinations(range(n), 3):
        points = []
        points.extend(p[i])
        points.extend(p[j])
        points.extend(p[k])
        try:
            px, py, r = enclose(points)
        except:
            continue
        flag = 1
        for l in range(n):
            if (px-p[l][0])**2 + (py-p[l][1])**2 > r**2 + 0.0000001:
                flag = 0
                break
        if flag == 1:
            ans = min(ans, r)

for i, j in combinations(range(n), 2):
    px = (p[i][0]+p[j][0]) / 2
    py = (p[i][1]+p[j][1]) / 2
    r = ((p[i][0] - px)**2 + (p[i][1] - py) ** 2) ** (1/2)
    flag = 1
    for l in range(n):
        if (px-p[l][0])**2 + (py-p[l][1])**2 > r**2 + 0.0000001:
            flag = 0
            break
    if flag == 1:
        ans = min(ans, r)

print(ans)
def calc_gcd(a, b):
    from math import gcd
    return gcd(a, b)


if __name__ == '__main__':
    # ??????????????¬?????¨
    # start_time = datetime.now()
    # print('>>> {0}'.format(start_time))

    # ???????????\???
    data = [int(x) for x in input().split(' ')]

    # ?¨?????????????
    result = calc_gcd(data[0], data[1])

    # ???????????¨???
    print('{0}'.format(result))

### FIXED CODE ###

def calc_gcd(x, y):
    """
    math.gcd()????????¨??§????????????python3.5??\??????AOJ???python?????????????????????3.4????????§?????¨??§?????????
    """
    if y == 0:
        return x
    else:
        return calc_gcd(y, x % y)


if __name__ == '__main__':
    data = [int(x) for x in input().split(' ')]
    result = calc_gcd(data[0], data[1])
    print('{0}'.format(result))
A, B = map(int, input().split())

def gcd( x, y ):
    count = 0
    while y != 0:
        x, y = y, x%y        
    return x


def primes(n):
    is_prime = [True] * (n + 1)
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return {i: True for i in range(n + 1) if is_prime[i]}

def make_divisors(n):
    divisors = 0
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            if i in p:
                divisors+=1
            if i != n // i and n//i in p:
                divisors+=1

    return divisors
x = gcd(A, B)
p = primes(x)
x = make_divisors(x)
print(x)

### FIXED CODE ###

A, B = map(int, input().split())


def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    return divisors

import math

def is_prime(n):
    if n == 1: return True

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False
    return True

import fractions
x = fractions.gcd(A, B)
divisors = make_divisors(x)
ans = 0
for d in divisors:
    if is_prime(d):
        ans += 1
print(ans)
n = input()
s = " "
for i in n:
    if i == '0':
        s+='0'
    elif i=='1':
        s+='1'
    if i=='B':
        s = s.replace(s[-1],'')

print(s)


### FIXED CODE ###

n = input()
s = ''
for i in n:
    if i== '1' or i == '0':
        s+=i
    else:
        if len(s)>0:
            s =s[0:-1]
print(s)
a=input()
b=input()
c=input()
  
a=int(a)
b=int(b)
c=int(c)
x=int(x)

x=b//a
  
if x>=c:
  print(c)
else :
  print(x)


### FIXED CODE ###

a,b,c = map(int, input().split())
  
a=int(a)
b=int(b)
c=int(c)

x=b//a
x=int(x)

if x>=c:
  print(c)
else :
  print(x)
n, m = map(int, input().split())
s = [0]*m
c = [0]*m
num = ['']*n
for i in range(m):
    s[i], c[i] = map(int, input().split())
    if s[i]==1 and c[i]==0:
        print(-1)
        exit()
    elif num[s[i]-1] == '':
        num[s[i]-1] = c[i]
    elif num[s[i]-1] != c[i]:
        print(-1)
        exit()
for i in range(m):
    if num[i]=='':
        if i == 0:
            num[i] = 1
        else:
            num[i] = 0
print(''.join(map(str,num)))

### FIXED CODE ###

from math import ceil,floor,comb,factorial,gcd,pow,sqrt,log2,cos,sin,tan,pi,inf
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heappop,heappush
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n, m = MAP()
ans = [-1]*n

for i in range(m):
    s, c = MAP()
    s -= 1
    if ans[s] == -1 or ans[s] == c:
        ans[s] = c
    else:
        print(-1)
        exit()

if ans[0] == 0:
    if n == 1:
        print(0)
    else:
        print(-1)
    exit()
else:
    for i in range(n):
        if ans[i] == -1:
            if n != 1 and i == 0:
                ans[i] = 1
            else:
                ans[i] = 0
    print(*ans, sep='')