n, m = map(int, input().split())
ans_list = [0] * n
for i in range(m):
    s,c = map(int,input().split())
    if ans_list[s-1] == 0:
        ans_list[s - 1] = c
    elif ans_list[s - 1] == c:
        continue
    else:
        print(-1)
        exit()

if ans_list[0] == 0:
    print(-1)
    exit()
ans = map(str,ans_list)
print("".join(ans))