N, M = map(int, input().split())
ans = []
jdg = True
cnt = 0

for i in range(N):
    ans.append("#")

for i in range(M):
    s, c = map(int, input().split())
    if ans[s-1] != "#" and ans[s-1] !=c:
        jdg = False
    elif s == 1 and c ==0:
        jdg = False
    else:
        ans[s-1] = c

for i in range(N):
    if ans[i] == "#":
        ans[i] = 0

for i in range(N):
    cnt += ans[i] *10**(N-1-i)

if jdg: 
    print(cnt)
elif jdg == False:
    print(-1)