n, m = map(int,input().split())
sc = []
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(len(sc)):
    ans[sc[i][0]-1] = sc[i][1]
if ans[0] == 0:
    print(-1)
    exit()
map_ans = map(str, ans)
print("".join(map_ans))
