N,M = [int(i) for i in input().split(" ")]
ans = [0 for _ in range(N)]
ans_flg = [False for _ in range(N)]

for _ in range(M):
    s,c = [int(i) for i in input().split(" ")]
    s -= 1
    if s == 0 and c == 0:
        print(-1)
        break
    if ans_flg[s] and (ans[s] != c):
        print(-1)
        break
    else:
        ans[s] = c
        ans_flg[s] = True
else:
    print("".join(map(str, ans)))