n, m = map(int, input().split())
l = [list(map(int, input().split())) for _ in range(m)]
l = [list(x) for x in zip(*l)]

flag = True
ans = [-1] * n
for i in range(m):
    if ans[l[0][i]-1] == -1:
        ans[l[0][i]-1] = l[1][i]
    elif ans[l[0][i]-1] != l[1][i]:
        flag = False

if n != 1:
    if ans[0] == 0:
        flag = False

if flag:
    ans[0] = max(0, ans[0])
    ans[1] = max(0, ans[1])
    ans[2] = max(0, ans[2])
    ans = str(ans[0]) + str(ans[1]) + str(ans[2])

print(ans) if flag else print(-1)
