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

ans_ = [False] * N

ans = [0] * N

Flag = True

for i in range(M):
    S, C = list(map(int, input().split()))
    if ans_[S-1] == False:
        ans_[S-1] = True
        ans[S-1] = C
    else:
        if ans[S-1] != C:
            Flag = False


if Flag:
    if len(ans) == 1 and ans[0] == 0:
        print(0)
    else:
        if ans[0] == 0:
            print(-1)
        else:
            print(*ans, sep='')
else:
    print(-1)