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

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

if flag:
    print(-1)
else:
    ans = int("".join(map(str, ans)))
    if N == len(str(ans)):
        print(ans)
    else:
        print(-1)