N, M = map(int, input().split())
sc_dict = {}
for i in range(M):
    s, c = map(int, input().split())
    if sc_dict.get(s) is not None:
        if sc_dict.get(s) != c:
            print(-1)
            exit(0)
    else:
        sc_dict[s] = c

ans = ""
for i in range(N):
    ans += "0"
ans = list(ans)

for k, v in sc_dict.items():
    ans[k-1] = str(v)

ans = int("".join(ans))

if ans == 0:
    print(-1)
else:
    print(ans)
