n, m = map(int, input().split())
sc = [list(map(int, input().split())) for i in range(m)]
ans =[0]*n
flag = False
if m == 0:
    ans_1 = [0]*n
    if n != 1:
        ans_1[0] = 1
        ans_2 = "".join([str(x) for x in ans_1])
        print(ans_2)
    else:
        print(0)

else:
    for i in range(m):
        for j in range(m):
            if sc[i][0] == sc[j][0] and sc[i][1] != sc[j][1]:
                flag = True

    for i in range(m):
        ans[sc[i][0]-1] = sc[i][1]

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