n, m = map(int, input().split())
ans = [-1 for _ in range(n)]
l = [list(map(int, input().split())) for _ in range(m)]

if m == 0:
    if n == 1:
        print(0)
        exit()
    elif n == 2:
        print(10)
        exit()
    elif n == 3:
        print(100)
        exit()

for k in range(m):
    if l[k][1] != 0:
        break
    for p in range(m):
        if l[p][0] == 1:
            break
        else:
            if n ==2:
                print(10)
                exit()
            elif n == 3:
                print(100)
                exit()
else:
    if n == 1:
        print(0)
        exit()
    else:
        print(-1)
        exit()

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

    print(''.join(list(map(str,ans))))