import sys
n,m = map(int,input().split())
ans = [-1 for i in range(n)]
check = [0 for i in range(n)]

for i in range(m):
    s,c = map(int,input().split())
    if ans[s-1] != -1 and ans[s-1] != c:
        print(-1)
        sys.exit()
    else:
        ans[s-1] = c
for i in range(n):
    if ans[i] == -1:
        ans[i] = 0
ans2 = ""
for i in range(n):
    if len(ans2)==0:
        if ans[i] == 0:
            ans2 = ans2
        else:
            ans2 += str(ans[i])
    else:
        ans2 += str(ans[i])
if len(ans2) == 0:
    print(-1)
else:
    print(ans2)