n,m=map(int,input().split())
s_c=[list(map(str,input().split())) for _ in range(m)]

ans=["0"]*n
for i in s_c:
    ans[int(i[0])-1]=i[1]

x=0
for i in range(m-1):
    for k in range(i+1,m):
        if s_c[i][0]==s_c[k][0] and s_c[i][1]!=s_c[k][1]:
            ans = -1
            break

print(int("".join(ans)) if ans!=-1 else -1)