n, m = map(int, input().split())
ls = []
for i in range(m):
    ls.append(list(map(int, input().split())))

ans = [-1 for i in range(n)]

for i in range(m):
    if ans[ls[i][0]-1] < 0:
        ans[ls[i][0]-1] = ls[i][1]
    elif ans[ls[i][0]-1] != ls[i][1]:
        ans = []
        break

if len(ans) == 0 or ans[0] == 0:
    print(-1)
else:
    if ans[0] == -1:
        ans[0] = 1

    for j in range(1, n):
        if ans[j] == -1:
            ans[j] = 0

    print("".join(list(map(str, ans))))
