n, m = map(int, input().split())
ans = [10]*n

sl = []
cl = []
for _ in range(m):
    s, c = map(int, input().split())
    if s in sl:
        if cl[sl.index(s)] != c:
            print(-1)
            exit(0)
    sl.append(s)
    cl.append(c)

for i in range(m):
    if ans[sl[i]-1] > cl[i]:
        ans[sl[i]-1] = cl[i]

if ans[0] == 0 and len(ans) != 1:
    print(-1)
    exit(0)

for i in range(len(ans)):
    if ans[i] == 10:
        ans[i] = 0

ans2 = []
for i in ans:
    ans2.append(str(i))
ans3 = "".join(ans2)
print(int(ans3))
