N, M = map(int, input().split())
sc = [[]]*M
ans = [0]*N
for i in range(M):
    sc[i] = list(map(int, input().split()))

#flag = 1
flag2 = [-1]*N
"""
for x in sc:
    if x[0] == 1 and x[1] == 0:
        if N != 1:
            print(-1)
            exit()
        elif flag2[0] > 0:
            print(-1)
            exit()
        #if flag == 0 or flag2[0] > 0:
        #    print(-1)
        #    exit()
        else:
            flag2[0] == 0
            flag = -1
    elif x[1] == 0:
        if flag2[x[0]-1] != 0:
            print(-1)
            exit()
        else:
            flag2[x[0]-1] = 0

    else:
        if flag == -1:
            if flag2[x[0]-1] != x[1] and flag2[x[0]-1] >= 0:
                print(-1)
                exit()
        else:
            print("hei")
            flag = 0
            flag2[x[0]-1] = x[1]
            ans[x[0]-1] = x[1]
"""
for x in sc:
    if x[0] == 1 and x[1] == 0:
        if N != 1 or flag2[0] > 0:
            print(-1)
            exit()
        else:
            flag2[0] = 0
    else:
        if flag2[x[0]-1] >= 0 and flag2[x[0]-1] != x[1]:
            print(-1)
            exit()
        else:
            ans[x[0]-1] = x[1]
            flag2[x[0]-1] = x[1]


print("".join(map(str, ans)))
