

N,M = list(map(int, input().split()))
sc  = [list(map(int, input().split())) for _ in range(M)]
ans = [10]*N
dp  = [False]*N
is_same = True 
is_keta = True
for i in range(M):
    if N > 1 and sc[i][0] == 1 and sc[i][1] == 0:
        is_keta = False
    if dp[sc[i][0]-1] and ans[sc[i][0]-1] != sc[i][1]:
        is_same = False
        break  
    if ans[sc[i][0]-1] > sc[i][1]:
        ans[sc[i][0]-1] = sc[i][1]
        dp[sc[i][0]-1] = True
for i in range(N):
    if not dp[i]:
        ans[i] = 0
#print(dp)
#print(ans)
if is_same and is_keta:
    Ans = "".join([str(n) for n in ans])
    print(Ans)
else:
    print(-1)
