[n,m] = [int(i) for i in input().split()]
data = []
ans = [-1] * n
flag = False
for _ in range(m):
    data.append([int(i) for i in input().split()])
for q in data:
    if ans[q[0]-1] == -1 or ans[q[0]-1] == q[1]:
        ans[q[0]-1] = q[1]
    else:
        flag = True
        break
if flag:
    print(-1)
elif ans == [0]:
    print(0)
elif ans[0] == 0:
    print(-1)
else:
    fa = ["0" if ans[i] == -1 else str(ans[i]) for i in range(n)]
    if fa[0] == 0:
        fa[0] = 1
    print("".join(fa))
