N, M = map(int, input().split())
Ans = [-1] * N
ans = 0
for i in range(M):
    s, c = map(int, input().split())
    s -= 1
    if (Ans[s] == -1) or (Ans[s] == c):
        Ans[s] = c
    else:
        print(-1)
        exit()


if Ans[0] == -1:
    Ans[0] = 1
if (N != 1) and (Ans[0] == 0):
    print(-1)
    exit()

for i in range(N):
    if Ans[i] == -1:
        Ans[i] = 0
    ans = ans * 10 + Ans[i]


print(ans)
