n, m = map(int, input().split())
sc = [list(map(int, input().split())) for i in range(m)]
ans =[0]*n
flag = False

if n == 1 and m != 0:
    for i in range(m):
        for j in range(m):
            if sc[i][0] == sc[j][0] and sc[i][1] == sc[j][1]:
                continue
            else:
                print(-1)
    print(sc[0][1])

elif n == 1 and m == 0:
    print(0)

elif n >= 2 and m == 0:
    ans = [0]*n
    ans[0] = 1
    ans_str = [str(x) for x in ans]
    print("".join(ans_str))

elif n >= 2 and m != 0:
    ans1 = [0]*n

    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):
        ans1[sc[i][0]-1] = sc[i][1]

    count = 0
    for i in range(m):
        if sc[i][0] != 1:
            count += 1
    if count == m:
        ans1[0] = 1

    if not flag:
        if count != m and ans1[0] == 0:
            flag = True

    if flag:
        print(-1)
    else:
        ans1_str = [str(x) for x in ans1]
        print("".join(ans1_str))