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

# print(sc)
ans = '?'*n
for i in range(m):
    d = sc[i][0]
    r = sc[i][1]
    if (ans[d-1] == '?') or (ans[d-1] == str(r)):
        ans = ans[:d-1] + str(r) + ans[d:]
    else:
        print(-1)
        exit()

ans = int(ans.replace('?', '0'))
if len(str(ans)) == n:
    print(ans)
else:
    print(-1)