N, M = map(int, input().split())
sc = []
ans = [-1] * N

for _ in range(M):
    sc.append(list(map(int, input().split())))

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] == -1:
    print(-1)

else:
    for a in range(N):
        if ans[a] == -1:
            ans[a] = 0

    if sum(ans) == 0 and len(ans) != 1:
        print(-1)
    else:
        print("".join(map(str, ans)))