N, M = map(int, input().split())
arr = []
ans = [0] * N

for i in range(M):
    s, c = map(int, input().split())
    if s == 1 and c == 0 and N != 1:
        print(-1)
        exit(0)
    if s in arr and ans[s-1] != c:
        print(-1)
        exit(0)
    arr.append(s)
    ans[s-1] = c
print("".join([str(i) for i in ans]))
