N, M = map(int, input().split())
X = [-1] * N
for _ in range(M):
    s, c = map(int, input().split())
    if s == 1 and c == 0:
        print(-1)
        exit()
    if X[s-1] < 0:
        X[s-1] = c
    elif X[s-1] != c:
        print(-1)
        exit()

if X[0] < 0: X[0] = 1
print("".join([str(x) if x >= 0 else "0" for x in X]))