n, m = map(int, input().split())
ans = [0 for i in range(n)]
bad = False
for i in range(m):
    s, c = map(int, input().split())
    if s==1 and c==0:
        if n==1:
            pass
        else:
            print(-1)
            bad = True
            break
    elif ans[s-1]!="0" and int(ans[s-1])!=c:
        print(-1)
        bad = True
        break
    else:
        ans[s-1] = c
if ans[0] == 0:
    ans[0] = 1
if bad == False:
    a = ""
    for i in range(n):
        a += str(ans[i])
    print(int(a))
