N, M = map(int,input().split())

ans = [None] * N
flag = 1
for i in range(M):
    s,c = map(int,input().split())

    if (c == 0 and s < N) or (ans[s-1] and ans[s-1] != c):
        flag = 0
        break
    ans[s-1] = c

for i in range(N):
    if not ans[i]:
        ans[i] = 0

if flag:
    print("".join([str(x) for x in ans]))
else:
    print(-1)
