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

if N == 1:
    print(res)
elif flg or (N_list[0] == 0 and flg_list[0] == 1):
    print("-1")
elif N == len(str(res)):
    print(res)
else:
    print(res+10**(N-1))
