
n, m = map(int, input().split())
sl = list(list(map(int, input().split())) for _ in range(m))
sl = list(map(list, set(map(tuple, sl))))

cnt = [0]*n
cnn = [0]*n
# for s in sl:
#     if cnt[s[0]-1] == 0:
#         cnn[s[0]-1]
#     else:
#         print(-1)
#         exit()


for s in sl:
    if s[0] > n:
        print(-1)
        exit()
    if s[0] == 1 and s[1] == 0:
        print(-1)
        exit()
    elif cnn[s[0]-1] == 0:
        cnn[s[0] - 1] = s[1]
    # elif cnn[s[0]-1] != s[1] and cnn[s[0]-1] > s[1]:
    #     cnn[s[0] - 1] = s[1]
    elif cnn[s[0]-1] != s[1]:
        print(-1)
        exit()
    else:
        print(-1)
        exit()

if n > 1 and cnn[0] == 0:
    cnn[0] = 1
    print(*cnn, sep='')
else:
    print(*cnn, sep='')