N, M = map(int, input().split())
S = []
C = []
for _ in range(M):
    s, c = map(int, input().split())
    S.append(s)
    C.append(c)
    

n = int('9'*N)
ans = []

for i in range(n+1):
    if len(str(i)) == 1:
        I = '00'+str(i)
    elif len(str(i)) == 2:
        I = '0'+str(i)
    else:
        I = str(i)
    for m in range(M):
        if N >= 2 and S[m] == 1 and C[m] == 0:
            break
        if I[S[m]-1] != str(C[m]):
            break
    else:
        ans.append(I)

if len(ans) == 0:
    print(-1)
    exit()

ans_map = list(map(int,ans))

print(ans_map)

print(min(ans_map))
