N, M = map(int, input().split())
sc = [list(map(int, input().split())) for _ in range(M)]
ans = [0] * N
sc.sort(key=lambda x: x[1], reverse=True)

for i in range(M):
    ans[sc[i][0] - 1] = sc[i][1]

if ans[0] == 0 and N != 1:
    print("-1")
elif ans[0] == 0 and N == 1:
    print(0)
else:
    print("".join(map(str, ans)))