n, m = map(int,input().split())
sc = []
if n == 1 and m == 0:
    print(0)
    exit()
elif n == 2 and m == 0:
    print(10)
    exit()
elif n == 3 and m == 0:
    print(100)
    exit()
for i in range(m):
    s,c = map(int,input().split())
    sc.append([s,c])
sc.sort()
# for i in range(m - 1):
#     if sc[i][0] == sc[i+1][0] and sc[i][1] != sc[i+1][1]:
#         print(-1)
#         exit()
ans = [0] * n
for i in range(m):
    if ans[sc[i][0]-1] == 0 or ans[sc[i][0]-1] == sc[i][1]:
        ans[sc[i][0]-1] = sc[i][1]
    else:
        print(-1)
        exit()
if n == 1 and ans[0] == 0:
    print(0)
    exit()
if ans[0] == 0:
    print(-1)
    exit()
map_ans = map(str, ans)
print("".join(map_ans))
