def C():
    n,m = list(map(int, input().split()))
    ans = [0]*n
    for s,c in (list(map(int,input().split())) for _ in range(m)):
        if ans[s-1] != 0 and ans[s-1] != c:
            print(-1)
            return
        if ans[s-1] == 0:
            ans[s-1] = c
    if ans[0] == 0:
        print(-1)
    else:
        print("".join(map(str,ans)))
C()