N,M = map(int,input().split())
N_list = [0]*N
flg = False
for i in range(M):
    s,c = map(int,input().split())
    if N_list[s-1] == 0:
        N_list[s-1] = c
    elif N_list[s-1] != c:
        flg = True
        break
print(N_list)
if flg:
    print("-1")
else:
    res = 0
    for i in range(N-1,-1,-1):
        res += (10**i)*N_list[N-1-i]
    if res == 0:
        print("-1")
    else:
        print(res)
