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

ans = [0]*n

for s, c in X:
    if ans[s-1]:
        if ans[s-1] != c:
            print(-1)
            exit(0)
    else:
        ans[s-1] = c

if ans[0] == 0:
    print(-1)
else:
    for i in ans:
        print(i, end="")