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

if M == 0:
    print(0)
    exit(0)

slist = [list(map(int,input().split())) for i in range(M)]

mlist = [-1 for i in range (M+1)]

for lis in slist:
    if mlist[lis[0]] != -1:
        if mlist[lis[0]] != lis[1]:
            print(-1)
            exit(0)
    else:
        if lis[0] == 1 and lis[1] == 0:
            print(-1)
            exit(0)
        mlist[lis[0]] = lis[1]

# print(mlist)

reslist = []

for j in range(1, M+1):
    # print(mlist[j])
    if mlist[j] == -1:
        if j == 1:
            reslist.append(1)
        else:
            reslist.append(0)
    else:
        reslist.append(mlist[j])

# print(reslist)

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