n,m = map(int,input().split())
sc = [list(map(int,input().split())) for i in range(m)]

check = [0] * n

for i in range(m):
    if check[sc[i][0]-1] == 0 or check[sc[i][0]-1] == sc[i][1]:
        check[sc[i][0]-1] = sc[i][1]
        if i == m-1:
            if check[0] == 0:
                print(-1)
            else:
                ans = ""
                for i in range(n):
                    ans += str(check[i])
                print(int(ans))
    else:
        ans = -1
        print(ans)
        break